Impeccable

Chip Trace button

A black button on a hidden circuit board, like a chip: press it and traces draw out from your finger, fading at their ends, until you let go.

ButtonClickCanvasNo extra packagesLight + darkMobile
npx shadcn@latest add https://impeccable-ui.com/r/chip-trace-button.json
Press and hold different spots on it. A few traces draw out from wherever you press, stay while you hold, and leave fast when you let go.

Run it in a project set up with shadcn. No other packages needed. Or open and copy the file into components/ui/chip-trace-button.tsx.

Prompts

Paste one into Claude Code, Cursor or any AI coding tool. Install adds this exact button and asks only where it goes. Blend asks three short questions (where, the button and trace colors, and the plus), then fits it to your product without changing how it moves.

# Chip Trace button

A 1-file React component from Impeccable. Add it to this project so it works and looks exactly like the source below, in the one place I choose, and change nothing else.

A black button that sits on a hidden circuit board like a chip. The moment it is pressed (as it shrinks), a few thin traces, one or two at a time, grow out of its edges like pins, starting nearest the spot that was pressed: each line draws itself outward with a small bright tip, bends at 45 degrees with its neighbour and fades away along its length, bright at the button and gone at its end, so it melts into the page. No dots at the ends. The board stays for as long as the button is held down and leaves fast from the middle out on release; a quick tap still draws the whole board, rests a moment, then leaves. In slow and calm, out fast. Nothing moves inside the button. Black and white only.

## Before you build: one question

Look through this project first: its "Create", "New", "Add" and "Start" buttons, its toolbars, empty states and dashboards, and how much free space sits around them. Then ask me this in one message and wait for my answer:

- **Where should it go?** Suggest the 1–3 buttons it could replace or the spots it fits best (for example the main button of an empty state, a "New project" button with space around it, or a hero's main action). Keep that button's label and click handler.
  *Why: the board glows in the space around the button, so it belongs on one main action with some room around it, not in a tight toolbar row.*

Ask nothing else. If I say *skip*, use the best suggestion.

## Keep it as it is

The near black button with its thin light edge, the hidden circuit board around it (single traces and pairs leaving its edges like pins, bending at 45 degrees and fading out toward their ends), the traces drawing out slowly from the pressed spot, and the fast exit about two seconds after the click are the design. Keep them exactly as in the source, with their sizes, colors and timing. If something doesn't fit my project, tell me instead of changing it.

- Add only the component file and the one place I picked. If it replaces an existing button, keep that button's label and click handler. Don't add packages, change other files, or restyle anything.
- Don't add the demo parts from the Impeccable website: the dotted card behind the button and its "Create New" label (use my own label).

## Fastest path

If this project has a `components.json` (shadcn), run `npx shadcn@latest add https://impeccable-ui.com/r/chip-trace-button.json`.
If the command succeeds, only fix import paths to match this project and skip ahead. If it fails or there is no `components.json`, build it by hand as below.

## Build it

- Stack: React 18 or 19 with TypeScript. No other packages: the board is drawn on one small canvas behind the button with the browser's own 2D drawing.
- JavaScript project? Name the file `chip-trace-button.jsx` and remove the type annotations; nothing else changes.
- Create this file, in this project's usual place for components:
  - `components/ui/chip-trace-button.tsx`
- Keep these exports and their names: `ChipTraceButton`, `ChipTraceButtonProps`.
- Keep `"use client"` at the top in Next.js App Router projects. In other setups it is harmless.
- Keep the tuning values at the top exactly as written: `ROOM_X`, `ROOM_Y`, `PITCH`, `LINE`, `STAGGER_MS`, `DRAW_MS`, `DRAW_PER_PX`, `HOLD_MS`, `EXIT_MS`, `EXIT_SPREAD_MS`, `TRACE_GLOW`, `TAIL`, `STOPS`, `TIP_GLOW`, `FAR_DIM`, `CALM_IN_MS`, the easing curves `grow`, `glide` and `go`, the board drawing in `makeBoard` and the `CSS` block with its easing curves. They are the design and its timing.
- Keep the fallbacks: with `prefers-reduced-motion: reduce` nothing draws or travels: the finished board fades in softly in place, rests and leaves. Holding Enter or Space works like a press, from the middle; letting go of the key (or leaving the button) releases it. A click made from code with no press before it plays the whole board and lets it go by itself. Keyboard focus shows a ring. A disabled button is dimmed and never glows. Hover lifts the fill a touch only on devices with a real pointer, so it never sticks after a tap. The canvas draws only while the board shows and stops on its own, and it is trimmed near the side of the window so the page never scrolls sideways.

## Use it

```tsx
"use client";
import { ChipTraceButton } from "@/components/ui/chip-trace-button";

export function NewProjectAction() {
  return <ChipTraceButton onClick={() => createProject()}>Create New</ChipTraceButton>;
}
```

- It is a real `<button>` and takes every button prop (`type`, `disabled`, `aria-*`). In a form, set `type="submit"`.
- The board plays by itself on every press and stays while it is held; `onClick` runs as usual on release, after the board has started, so it is seen even when the click opens a dialog or a new page at once.
- `className` and `style` go on the button itself. It is 44px tall with 18px each side.
- The board reaches 40px above and below the button and 56px to each side. If its parent hides overflow, leave that much room inside it, or the traces are cut off.

## How the board moves

Read this before you touch anything, so you know what the code does and why it must stay as it is.

1. **At rest.** A 44px button with 8px corners (smoothed corners where the browser supports `corner-shape`): a near black fill with a faint top to bottom shade, a thin light edge, a lit line along the top inside and a small shadow. The circuit board around it is invisible.
2. **The board.** Laid out once for the button's size on a canvas behind it that reaches 40px above and below and 56px to each side, and never under the button itself. On every side, a few single traces and pairs 5px apart leave the edge like the pins of a chip, with wide gaps between them so the board stays airy. Groups left of the middle bend left, right of it bend right, the middle runs straight out. Each group bends at 45 degrees and keeps its spacing through the bend (each trace starts its bend a little later than its neighbour, the way real boards are routed), never further than the gap to the next group, so traces never cross. Every trace fades out along its length: full strength where it leaves the button, easing down to nothing at its end (a gradient along the trace, strength `(1 - f)^1.4`), so it melts into the page and gives depth. No dots, rings or halos at the ends; ends often step in little staircases. A seeded random makes it the same board every time for the same size, like a real chip.
3. **In, slow and calm.** It starts on press (pointer down, the moment the button shrinks), not on click. The pins nearest the pressed spot start at once and the farthest up to 240ms later. Each trace draws itself outward from the button edge over about 0.8 seconds (620ms plus 8ms per px of length, so all travel at about the same speed) on a curve that eases off, travels and lands softly (`cubic-bezier(.4, .3, .1, 1)`), with a small bright tip and a soft glow that dim as it travels out and lands. Traces start at 60% strength at the button edge so it stays subtle, and the far pins rest dimmer than the near ones. Nothing moves inside the button, and pressing it shrinks only the button to 97%, never the board.
4. **Hold.** The finished board rests for 420ms.
5. **Out, fast.** Every part fades in 260ms on an accelerating curve (`cubic-bezier(.4, 0, .9, .55)`), starting at the pressed spot and reaching the far pins 110ms later, so it leaves from the middle out. It starts the moment the button is released (listened for on the whole window, so letting go anywhere, or the browser taking over for a scroll, still counts). After a quick tap it waits until the board has fully drawn in, plus 160ms, so a tap still shows the whole story; it is gone about 1.6 seconds after a quick tap. A new press sends the board drawn so far out at once and draws a new one from the new spot.
6. **Timing and color.** Every step runs on the clock, not on frame counts, so it takes the same time on slow phones and fast screens. The traces take the text color around the button unless `glowColor` is set, read again on every click, so they show as dark lines on a light page, as a light glow on a dark page, and follow a theme switch.

## Check

- It type-checks and the page renders with no console errors.
- At rest it is a plain near black button with a plus and my label, and nothing around it. The moment I press it (as it shrinks), a few circuit traces draw themselves out of the button's edges, nearest the spot I pressed first, each with a small bright tip, and fade out toward their ends with no dots there. If I keep holding, the board stays; when I let go it leaves fast from the middle out. A quick tap still draws the whole board, then it leaves. Nothing moves inside the button. Pressing again sends the old board out at once and draws a new one from the new spot.
- It looks right in light and dark mode (check both): dark traces on the light page, a light glow on the dark page, and the button near black with a visible edge on both.
- On a phone, a tap lights it from under my finger and there is no sideways scroll.
- With `prefers-reduced-motion: reduce`, nothing draws or travels: the finished board fades in softly in place, rests and leaves.
- Nothing else on the site looks or behaves differently.
- Finish with a short report: the files you added or changed, where it's placed, and every place where you had to do something differently from the source, and why.

## Source

The reference implementation. Copy it as-is, then apply only the changes listed above.

### `components/ui/chip-trace-button.tsx`

```tsx
"use client";

/**
 * Chip Trace button, from Impeccable.
 *
 * A black button that sits on a hidden circuit board, like a chip. Press it
 * and, as it shrinks, a few copper traces grow out of its edges like the pins
 * of a chip: each line draws itself outward with a small bright tip, bends at
 * 45 degrees with its neighbour and fades away along its length, bright at the
 * button and gone at its end, so it melts into the page. The pins nearest your
 * finger go first. The board stays for as long as you hold the button down and
 * lets go quickly from the middle out when you release. A quick tap still draws
 * the whole board, rests a moment, then lets go. Nothing moves inside the button.
 *
 * In slow and calm, out fast: the drawing takes about a second, the exit about
 * a third of a second, and a new press sends the last board out at once.
 *
 * Black and white only: the traces take your page's text color by default, so
 * they glow light on a dark page and show as dark lines on a light page.
 * Holding Enter or Space works the same, from the middle.
 *
 * No packages. The board is drawn on one small canvas behind the button that
 * only runs while it shows, and it is the same board every time for the same
 * button size.
 */

import {
  forwardRef,
  useCallback,
  useEffect,
  useImperativeHandle,
  useRef,
  type ButtonHTMLAttributes,
  type CSSProperties,
  type FocusEvent,
  type KeyboardEvent,
  type MouseEvent,
  type PointerEvent,
} from "react";

export type ChipTraceButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
  /** The fill. Any CSS color, including var(--…). Default: near black. */
  color?: string;
  /** The label and plus color. Default: white. */
  textColor?: string;
  /** The color the traces behind the button glow in. Default: the page's text color around the button. */
  glowColor?: string;
  /** Shows the small plus before the label. */
  icon?: boolean;
};

/* ---------- tuning (the design: keep as written) ---------- */

const ROOM_X = 56; // px of board to the left and right of the button
const ROOM_Y = 40; // px of board above and below it
const PITCH = 5; // px between two parallel traces
const LINE = 1; // px, trace width
const STAGGER_MS = 240; // the pin nearest the click starts at once, the farthest this much later
const DRAW_MS = 620; // a trace draws itself out over this long, plus DRAW_PER_PX for every px of its length,
const DRAW_PER_PX = 8; // so long and short traces travel at about the same calm speed
const HOLD_MS = 420; // a click that came without a press (from code) rests the finished board this long
const TAP_HOLD_MS = 160; // a quick tap still draws the whole board, then rests this long before it leaves
const EXIT_MS = 260; // then every part lets go this fast (about a third of the way in),
const EXIT_SPREAD_MS = 110; // starting at the click and reaching the far pins this much later, for depth
const TRACE_GLOW = 0.6; // how strong a trace is where it leaves the button, next to the click (0 to 1): subtle, not a flash
const TAIL = 1.4; // how a trace fades out along its length: from full at the button to nothing at its end
const STOPS = 6; // gradient stops along each trace for that fade
const TIP_GLOW = 0.9; // how bright the travelling tip of a trace is
const FAR_DIM = 0.5; // the farthest pins rest this much dimmer than the nearest, so the click spot reads as the source
const CALM_IN_MS = 260; // reduced motion: the whole board fades in this long, holds, and leaves in EXIT_MS

/** Styles that can't be inline: the surface, the edge, the board behind, focus, hover, disabled and reduced motion. */
const CSS = `
.ctb { --ctb-f: var(--ctb-fill, rgb(14 14 16)); --ctb-t: var(--ctb-text, rgb(255 255 255)); --ctb-r: 8px; position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 0; max-width: 100%; height: 44px; padding: 0 18px; border: 0; border-radius: var(--ctb-r); background: none; color: var(--ctb-t); font: inherit; font-size: 16px; line-height: 24px; font-weight: 500; cursor: pointer; isolation: isolate; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.ctb-face { position: absolute; inset: 0; z-index: 0; border-radius: var(--ctb-r); background: linear-gradient(180deg, color-mix(in srgb, var(--ctb-f), white 7%), var(--ctb-f)); box-shadow: 0 1px 2px rgb(0 0 0 / .16), 0 4px 10px -4px rgb(0 0 0 / .32); pointer-events: none; }
.ctb-face::before, .ctb-face::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.ctb-face::before { background: white; opacity: 0; transition: opacity .15s ease; }
.ctb-face::after { box-shadow: inset 0 0 0 1px color-mix(in srgb, white 11%, transparent), inset 0 1px 0 color-mix(in srgb, white 16%, transparent); }
.ctb-face, .ctb-label { transition: scale .15s cubic-bezier(.23,1,.32,1); }
.ctb-board { position: absolute; top: -${ROOM_Y}px; bottom: -${ROOM_Y}px; left: -${ROOM_X}px; right: -${ROOM_X}px; z-index: -1; overflow: hidden; pointer-events: none; }
.ctb-board canvas { position: absolute; top: 0; display: block; }
.ctb-label { position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.ctb-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctb-plus { flex: none; width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .ctb:hover:not(:disabled) .ctb-face::before { opacity: .05; }
}
/* A press shrinks only the button itself; the board around it never moves. */
.ctb:active:not(:disabled) :is(.ctb-face, .ctb-label) { scale: .97; }
.ctb:focus-visible { outline: 2px solid color-mix(in srgb, var(--foreground, var(--fg, #111)) 55%, transparent); outline-offset: 2px; }
.ctb:disabled { opacity: .5; cursor: not-allowed; }
@supports (corner-shape: squircle) {
  .ctb, .ctb-face { border-radius: calc(var(--ctb-r) * 1.6); corner-shape: squircle; }
}
@media (prefers-reduced-motion: reduce) {
  .ctb-face, .ctb-label { transition: none; }
  .ctb:active:not(:disabled) :is(.ctb-face, .ctb-label) { scale: 1; }
}`;

/* ---------- the board ---------- */

/** One trace: its corner points (x, y, x, y, …) from the button edge out to its end, and its length so far at each. */
type Trace = { pts: number[]; at: number[]; length: number; wait: number };
type Board = { w: number; h: number; traces: Trace[] };
/** One click: where it landed, when, and when it starts to leave (sooner if another click comes). */
type Pulse = { x: number; y: number; start: number; leave: number; calm: boolean; rgb: string };

/** A small seeded random, so the same button size always gets the same board. */
function random(seed: number) {
  let s = seed >>> 0;
  return () => {
    s = (s + 0x6d2b79f5) >>> 0;
    let t = s;
    t = Math.imul(t ^ (t >>> 15), t | 1);
    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

/**
 * Lays out the board once for this button size: on every side, a few small groups of parallel traces leave the edge
 * like the pins of a chip, bend outward together at 45 degrees (keeping their spacing, the way real boards are
 * routed) and fade out at their ends. The button sits at (ROOM_X, ROOM_Y) on the board.
 */
function makeBoard(w: number, h: number): Board {
  const rand = random(w * 131 + h * 7 + 2026);
  const k = PITCH * (Math.SQRT2 - 1); // how much later the next trace starts its bend, so the gaps stay equal through it
  const traces: Trace[] = [];

  // One side of the button. `at(u, t)` turns "u px along the side, t px out from it" into board coordinates.
  const side = (length: number, room: number, corner: number, maxBend: number, at: (u: number, t: number) => [number, number]) => {
    // A few single pins and pairs with wide gaps between them, so the board stays airy.
    const groups: { us: number[]; dir: number; d: number }[] = [];
    let u = corner + rand() * 3;
    while (u < length - corner) {
      const size = 1 + Math.floor(rand() * 2);
      const us: number[] = [];
      for (let i = 0; i < size && u < length - corner; i++, u += PITCH) us.push(u);
      groups.push({ us, dir: 0, d: 0 });
      u += PITCH + 20 + rand() * 18; // the gap to the next group
    }
    // Groups left of the middle bend away to the left, right of it to the right, the middle runs straight out.
    // A group never bends further than the gap to its outer neighbour, so traces never cross.
    for (let g = 0; g < groups.length; g++) {
      const grp = groups[g];
      const mid = (grp.us[0] + grp.us[grp.us.length - 1]) / 2;
      const off = mid / length - 0.5;
      grp.dir = Math.abs(off) < 0.12 ? 0 : Math.sign(off);
      if (!grp.dir) continue;
      const outer = groups[g + grp.dir];
      const gap = outer
        ? grp.dir < 0
          ? grp.us[0] - outer.us[outer.us.length - 1]
          : outer.us[0] - grp.us[grp.us.length - 1]
        : grp.dir < 0
          ? grp.us[0] - 2
          : length - 2 - grp.us[grp.us.length - 1];
      grp.d = Math.max(0, Math.min(maxBend, gap - 2, 4 + rand() * (maxBend - 4)));
    }
    for (const grp of groups) {
      const n = grp.us.length;
      const s0 = 3 + rand() * 4;
      const stairs = (rand() < 0.5 ? -1 : 1) * (2 + rand() * 4);
      const first = room * (0.55 + rand() * 0.3);
      grp.us.forEach((u0, j) => {
        const rank = grp.dir > 0 ? n - 1 - j : j;
        const bend = grp.dir ? s0 + rank * k : 0;
        const d = grp.dir ? grp.d : 0;
        const end = Math.max(bend + d + 4, Math.min(room - 6, first + rank * stairs + rand() * 2));
        const u1 = u0 + grp.dir * d;
        const pts = [...at(u0, 0.5)];
        if (grp.dir) pts.push(...at(u0, bend), ...at(u1, bend + d));
        pts.push(...at(u1, end));
        const lengths = [0];
        for (let i = 2; i < pts.length; i += 2) lengths.push(lengths[lengths.length - 1] + Math.hypot(pts[i] - pts[i - 2], pts[i + 1] - pts[i - 1]));
        // A tiny random wait of its own, so pins at the same distance don't move in lockstep.
        traces.push({ pts, at: lengths, length: lengths[lengths.length - 1], wait: rand() * 40 });
      });
    }
  };

  const X = ROOM_X;
  const Y = ROOM_Y;
  // Top and bottom: pins 14px clear of the corners, bending at most 12px sideways.
  side(w, Y, 14, 12, (u, t) => [X + u, Y - t]);
  side(w, Y, 14, 12, (u, t) => [X + u, Y + h + t]);
  // Left and right: pins 9px clear of the corners, bending at most 8px, so they never meet the top and bottom ones.
  side(h, X, 9, 8, (u, t) => [X - t, Y + u]);
  side(h, X, 9, 8, (u, t) => [X + w + t, Y + u]);
  return { w, h, traces };
}

/** The point `len` px along a trace. */
function pointAt(tr: Trace, len: number): [number, number] {
  for (let i = 1; i < tr.at.length; i++) {
    if (len <= tr.at[i] || i === tr.at.length - 1) {
      const seg = tr.at[i] - tr.at[i - 1] || 1;
      const f = Math.min(1, Math.max(0, (len - tr.at[i - 1]) / seg));
      return [tr.pts[i * 2 - 2] + (tr.pts[i * 2] - tr.pts[i * 2 - 2]) * f, tr.pts[i * 2 - 1] + (tr.pts[i * 2 + 1] - tr.pts[i * 2 - 1]) * f];
    }
  }
  return [tr.pts[0], tr.pts[1]];
}

/** Adds the part of a trace from `from` px to `to` px along it to `path`. */
function partOf(path: Path2D, tr: Trace, from: number, to: number) {
  if (to <= from) return;
  const a = pointAt(tr, from);
  path.moveTo(a[0], a[1]);
  for (let i = 1; i < tr.at.length; i++) if (tr.at[i] > from && tr.at[i] < to) path.lineTo(tr.pts[i * 2], tr.pts[i * 2 + 1]);
  const b = pointAt(tr, to);
  path.lineTo(b[0], b[1]);
}

/** How long one trace takes to draw itself out. */
const drawTime = (tr: Trace) => DRAW_MS + tr.length * DRAW_PER_PX;

/** Reads any CSS color (including var(--…)) as "r, g, b", so it can be mixed with any strength. */
function readRgb(host: HTMLElement, color: string | undefined) {
  let value: string;
  if (color) {
    const probe = document.createElement("span");
    probe.style.color = color;
    probe.style.display = "none";
    host.appendChild(probe);
    value = getComputedStyle(probe).color;
    probe.remove();
  } else {
    value = getComputedStyle(host).color; // the page's text color around the button
  }
  const m = value.match(/[\d.]+/g);
  return m && m.length >= 3 ? `${m[0]}, ${m[1]}, ${m[2]}` : "128, 128, 128";
}

/** A CSS cubic-bezier() easing curve, solved for x, so the canvas moves on the same curves as the CSS. */
function bezier(x1: number, y1: number, x2: number, y2: number) {
  const ax = 3 * x1 - 3 * x2 + 1, bx = 3 * x2 - 6 * x1, cx = 3 * x1;
  const ay = 3 * y1 - 3 * y2 + 1, by = 3 * y2 - 6 * y1, cy = 3 * y1;
  return (x: number) => {
    if (x <= 0) return 0;
    if (x >= 1) return 1;
    let t = x;
    for (let i = 0; i < 8; i++) {
      const dx = ((ax * t + bx) * t + cx) * t - x;
      const d = (3 * ax * t + 2 * bx) * t + cx;
      if (Math.abs(dx) < 1e-5 || !d) break;
      t -= dx / d;
    }
    t = Math.min(1, Math.max(0, t));
    return ((ay * t + by) * t + cy) * t;
  };
}

const grow = bezier(0.4, 0.3, 0.1, 1); // the line drawing out: eases off, travels, then a long soft landing
const glide = bezier(0.22, 1, 0.36, 1); // calm fades in (reduced motion)
const go = bezier(0.4, 0, 0.9, 0.55); // leaving: starts gently, then speeds away, so it gets out of the way fast

export const ChipTraceButton = forwardRef<HTMLButtonElement, ChipTraceButtonProps>(function ChipTraceButton(
  { color, textColor, glowColor, icon = true, onClick, onPointerDown, onKeyDown, onKeyUp, onBlur, className, style, children, type = "button", ...rest },
  forwarded,
) {
  const button = useRef<HTMLButtonElement>(null);
  const holder = useRef<HTMLSpanElement>(null);
  const canvas = useRef<HTMLCanvasElement>(null);
  const board = useRef<Board | null>(null);
  const pulses = useRef<Pulse[]>([]);
  const frame = useRef(0);
  useImperativeHandle(forwarded, () => button.current as HTMLButtonElement);

  /**
   * Sizes the canvas to the button plus its room (offsetWidth, so it stays sharp inside scaled previews) and
   * redraws the board. The board is trimmed where the button is near the side of the window, so it never makes
   * the page scroll sideways.
   */
  const fit = useCallback(() => {
    const el = button.current;
    const hold = holder.current;
    const cv = canvas.current;
    if (!el || !hold || !cv) return;
    const w = el.offsetWidth;
    const h = el.offsetHeight;
    if (!w || !h) return;
    const rect = el.getBoundingClientRect();
    const scale = rect.width / w || 1;
    const page = document.documentElement.clientWidth;
    const left = Math.max(0, Math.min(ROOM_X, Math.floor(rect.left / scale)));
    const right = Math.max(0, Math.min(ROOM_X, Math.floor((page - rect.right) / scale)));
    hold.style.left = `${-left}px`;
    hold.style.right = `${-right}px`;
    const dpr = Math.min(window.devicePixelRatio || 1, 2);
    const cw = w + ROOM_X * 2;
    const ch = h + ROOM_Y * 2;
    cv.width = Math.round(cw * dpr);
    cv.height = Math.round(ch * dpr);
    cv.style.width = `${cw}px`;
    cv.style.height = `${ch}px`;
    cv.style.left = `${left - ROOM_X}px`;
    if (!board.current || board.current.w !== w || board.current.h !== h) board.current = makeBoard(w, h);
  }, []);

  const draw = useCallback((now: number) => {
    const cv = canvas.current;
    const b = board.current;
    const ctx = cv?.getContext("2d");
    if (!cv || !b || !ctx) return;
    const cw = b.w + ROOM_X * 2;
    const ch = b.h + ROOM_Y * 2;
    const dpr = cv.width / cw;
    ctx.setTransform(1, 0, 0, 1, 0, 0);
    ctx.clearRect(0, 0, cv.width, cv.height);
    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
    ctx.save();
    // Never draw under the button itself: the board lives only around it.
    const cut = new Path2D();
    cut.rect(0, 0, cw, ch);
    cut.roundRect(ROOM_X + 1, ROOM_Y + 1, b.w - 2, b.h - 2, 10);
    ctx.clip(cut, "evenodd");
    ctx.lineWidth = LINE;
    ctx.lineJoin = "round";
    ctx.lineCap = "round";
    const far = Math.hypot(b.w, b.h) || 1;

    pulses.current = pulses.current.filter((p) => now < p.leave + EXIT_SPREAD_MS + EXIT_MS);
    for (const p of pulses.current) {
      const t = Math.max(0, now - p.start);
      const x = p.x + ROOM_X;
      const y = p.y + ROOM_Y;
      const c = (a: number) => `rgba(${p.rgb}, ${Math.min(1, Math.max(0, a)).toFixed(3)})`;
      // The soft glow around a travelling tip is light on a dark page; dark lines on a light page keep it faint, so it never reads as a smudge.
      const [cr, cg, cb] = p.rgb.split(",").map(Number);
      const soft = (0.2126 * cr + 0.7152 * cg + 0.0722 * cb) / 255 > 0.5 ? 0.55 : 0.18;
      const fade = (f: number) => Math.pow(1 - Math.min(1, f), TAIL); // 1 at the button, 0 at the far end of a trace

      for (const tr of b.traces) {
        const dist = Math.hypot(tr.pts[0] - x, tr.pts[1] - y) / far; // 0 at the click, about 1 at the far end
        const rest = 1 - FAR_DIM * Math.min(1, dist);
        // Leaving: from the click outward, each part fades on an accelerating curve.
        const out = 1 - go(Math.min(1, Math.max(0, (now - p.leave - EXIT_SPREAD_MS * Math.min(1, dist)) / EXIT_MS)));
        if (out <= 0) continue;
        const end = tr.pts.length - 2;
        // Every trace fades along its length, brightest where it leaves the button and gone at its end, for depth.
        const along = (a: number) => {
          const g = ctx.createLinearGradient(tr.pts[0], tr.pts[1], tr.pts[end], tr.pts[end + 1]);
          for (let i = 0; i <= STOPS; i++) g.addColorStop(i / STOPS, c(a * fade(i / STOPS)));
          return g;
        };
        const line = new Path2D();

        if (p.calm) {
          // Reduced motion: the finished board fades in softly in place. Nothing draws or travels.
          partOf(line, tr, 0, tr.length);
          ctx.strokeStyle = along(TRACE_GLOW * glide(Math.min(1, t / CALM_IN_MS)) * out * rest);
          ctx.stroke(line);
          continue;
        }

        // Entering: the pins nearest the click start first, then each line draws out on a decelerating curve,
        // dissolving into the board as it reaches out.
        const begin = STAGGER_MS * Math.min(1, dist) + tr.wait;
        const q = Math.min(1, Math.max(0, (t - begin) / drawTime(tr)));
        if (q <= 0) continue;
        const e = grow(q);
        const len = tr.length * e;
        partOf(line, tr, 0, len);
        ctx.strokeStyle = along(TRACE_GLOW * rest * out);
        ctx.stroke(line);
        // The bright tip: the last few px of the line plus a soft glow, dimming as it travels out and lands.
        const tip = TIP_GLOW * Math.pow(1 - e, 0.6) * fade(e * 0.8) * out;
        if (tip > 0.01) {
          const head = new Path2D();
          partOf(head, tr, Math.max(0, len - 6), len);
          ctx.strokeStyle = c(tip);
          ctx.stroke(head);
          const [hx, hy] = pointAt(tr, len);
          const g = ctx.createRadialGradient(hx, hy, 0, hx, hy, 5);
          g.addColorStop(0, c(tip * soft));
          g.addColorStop(1, c(0));
          ctx.fillStyle = g;
          ctx.fillRect(hx - 5, hy - 5, 10, 10);
        }
      }
    }

    ctx.restore();
    if (pulses.current.length) frame.current = requestAnimationFrame(draw);
    else frame.current = 0;
  }, []);

  useEffect(() => {
    const el = button.current;
    if (!el) return;
    fit();
    const ro = new ResizeObserver(fit);
    ro.observe(el);
    window.addEventListener("resize", fit);
    return () => {
      ro.disconnect();
      window.removeEventListener("resize", fit);
      cancelAnimationFrame(frame.current);
      frame.current = 0;
      pulses.current = [];
      stopListening.current?.();
    };
  }, [fit]);

  /** The board being held down right now, if any, and how to stop listening for its release. */
  const held = useRef<Pulse | null>(null);
  const heldKey = useRef("");
  const releasedAt = useRef(-Infinity);
  const stopListening = useRef<(() => void) | null>(null);

  /** When a board started at `now` has fully drawn in. */
  const drawnIn = (now: number, calm: boolean) => {
    const b = board.current;
    const longest = b ? Math.max(0, ...b.traces.map((tr) => STAGGER_MS + 40 + drawTime(tr))) : 0;
    return now + (calm ? CALM_IN_MS : longest);
  };

  /** Starts a new board from (x, y) in button px. Held boards stay until release; others leave on their own. */
  const start = (x: number, y: number, hold: boolean) => {
    const el = button.current;
    if (!el) return null;
    const calm = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    fit();
    const rgb = readRgb(el.parentElement ?? el, glowColor);
    const now = performance.now();
    // The board drawn so far leaves at once, fast, while the new one draws in from the new spot.
    for (const p of pulses.current) p.leave = Math.min(p.leave, now);
    const leave = hold ? Infinity : drawnIn(now, calm) + HOLD_MS;
    const pulse: Pulse = { x, y, start: now, leave, calm, rgb };
    pulses.current = [...pulses.current.slice(-2), pulse];
    if (!frame.current) frame.current = requestAnimationFrame(draw);
    return pulse;
  };

  /** Lets go of the held board: it leaves fast right away, or, after a quick tap, once it has fully drawn in. */
  const release = () => {
    stopListening.current?.();
    stopListening.current = null;
    heldKey.current = "";
    const p = held.current;
    held.current = null;
    releasedAt.current = performance.now();
    if (!p) return;
    p.leave = Math.max(releasedAt.current, drawnIn(p.start, p.calm) + TAP_HOLD_MS);
    if (!frame.current) frame.current = requestAnimationFrame(draw);
  };

  /** Where a pointer event lands on the button, in button px (works inside scaled previews too). */
  const spot = (clientX: number, clientY: number): [number, number] => {
    const el = button.current as HTMLButtonElement;
    const rect = el.getBoundingClientRect();
    const sx = rect.width ? el.offsetWidth / rect.width : 1;
    const sy = rect.height ? el.offsetHeight / rect.height : 1;
    return [(clientX - rect.left) * sx, (clientY - rect.top) * sy];
  };

  // The board appears the moment the button is pressed (when it shrinks), stays while it is held, and leaves on release.
  const handlePointerDown = (event: PointerEvent<HTMLButtonElement>) => {
    onPointerDown?.(event);
    const el = button.current;
    if (event.defaultPrevented || !el || el.disabled || event.button !== 0) return;
    release();
    const [x, y] = spot(event.clientX, event.clientY);
    held.current = start(x, y, true);
    // Listen on the window, so letting go anywhere (or the browser taking over for a scroll) still releases it.
    const up = () => release();
    window.addEventListener("pointerup", up);
    window.addEventListener("pointercancel", up);
    stopListening.current = () => {
      window.removeEventListener("pointerup", up);
      window.removeEventListener("pointercancel", up);
    };
  };

  // Keyboard: Enter or Space held down works the same, from the middle of the button.
  const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
    onKeyDown?.(event);
    const el = button.current;
    if (event.defaultPrevented || !el || el.disabled || event.repeat || held.current) return;
    if (event.key !== "Enter" && event.key !== " ") return;
    heldKey.current = event.key;
    held.current = start(el.offsetWidth / 2, el.offsetHeight / 2, true);
  };
  const handleKeyUp = (event: KeyboardEvent<HTMLButtonElement>) => {
    onKeyUp?.(event);
    if (heldKey.current && event.key === heldKey.current) release();
  };
  const handleBlur = (event: FocusEvent<HTMLButtonElement>) => {
    onBlur?.(event);
    if (heldKey.current) release();
  };

  const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
    const el = button.current;
    // A click with no press before it (one made from code) still plays the whole board, then lets it go by itself.
    const pressed = held.current || performance.now() - releasedAt.current < 300;
    if (el && !pressed) {
      const fromKeys = event.detail === 0 || (event.clientX === 0 && event.clientY === 0);
      const [x, y] = fromKeys ? [el.offsetWidth / 2, el.offsetHeight / 2] : spot(event.clientX, event.clientY);
      start(x, y, false);
    }
    onClick?.(event);
  };

  const vars = {
    ...(color ? { "--ctb-fill": color } : null),
    ...(textColor ? { "--ctb-text": textColor } : null),
    ...style,
  } as CSSProperties;

  return (
    <>
      <style>{CSS}</style>
      <button
        ref={button}
        type={type}
        className={className ? `ctb ${className}` : "ctb"}
        style={vars}
        onClick={handleClick}
        onPointerDown={handlePointerDown}
        onKeyDown={handleKeyDown}
        onKeyUp={handleKeyUp}
        onBlur={handleBlur}
        {...rest}
      >
        <span ref={holder} className="ctb-board" aria-hidden="true">
          <canvas ref={canvas} />
        </span>
        <span className="ctb-face" aria-hidden="true" />
        <span className="ctb-label">
          {icon ? (
            <svg className="ctb-plus" viewBox="0 0 16 16" fill="none" aria-hidden="true">
              <path d="M8 3v10M3 8h10" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
            </svg>
          ) : null}
          <span className="ctb-text">{children}</span>
        </span>
      </button>
    </>
  );
});
```

Usage

Use it like any button. The board plays on every press by itself.

"use client";
import { ChipTraceButton } from "@/components/ui/chip-trace-button";

export function NewProjectAction() {
  return (
    <ChipTraceButton
      color="var(--gray-950)"          // optional: the fill (default near black)
      textColor="var(--gray-50)"       // optional: the label and plus (default white)
      glowColor="var(--foreground)"    // optional: the traces behind it (default your text color around it)
      icon={true}                      // optional: the plus before the label
      onClick={() => createProject()}
    >
      Create New
    </ChipTraceButton>
  );
}

The board is drawn behind the button, 40px above and below it and 56px to each side, so give it that room inside a box that hides overflow. Near the side of the window it is trimmed, so the page never scrolls sideways.

How it moves

At rest it is a plain black button with a thin light edge, a lit top line and a small shadow. The circuit board around it is invisible.

The button sits on the board like a chip. On every side, a few single traces and pairs 5px apart leave its edge like pins and bend outward together at 45 degrees. Each one fades along its length, brightest at the button and gone at its end, so it melts into the page and gives depth. It moves in slow and calm, out fast. It starts the moment you press, as the button shrinks. The pins nearest your finger start first and the farthest up to 240ms later. Each trace draws itself outward over about 0.8 seconds with a small bright tip, easing off, travelling and landing softly, and dissolving into the page as it reaches out. The board stays for as long as you hold the button down, and when you let go it leaves in about a quarter of a second, from the spot you pressed outward. A quick tap still draws the whole board, rests a moment, then leaves. A new press sends the old board out at once. Pressing shrinks only the button, never the board. Nothing moves inside the button. The traces take your text color, so they read as dark lines on a light page and as a light glow on a dark one. Holding Enter or Space works the same, from the middle. With reduced motion nothing draws or travels: the finished board fades in softly in place, rests and leaves. The board is the same every time for the same button size, like a real chip, and it is drawn only while it shows. Set glowColor to change its color.

Props

PropDefaultWhat it does
children—The label. It stays on one line and trims with … if it runs out of room.
onClick—Runs on click, like any button. The board starts earlier, on press, so it is seen even when the click opens something at once.
colornear blackThe fill. Any CSS color, including var(--…). The board is drawn only around the button, never on it.
textColorwhiteThe label and plus color.
glowColoryour text colorThe color the traces take. By default the text color around the button, so they show dark on a light page and light on a dark page. Read again on every click, so it follows light and dark mode.
icontrueShows the small plus before the label.
type, disabled, aria-*, …type="button"Everything a normal button takes. Disabled dims it and the board never shows.
className / style—On the button itself. It is 44px tall with 18px each side and 8px corners. The board reaches 40px above and below it and 56px to each side.