{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"morphing-island-notch","type":"registry:component","title":"Morphing Island Notch","description":"A Dynamic-Island-style status pill with no dependencies: it measures its own content, springs to size, and fuses a stiff and a soft body through a goo filter so the silhouette stretches like liquid. Content crossfades between states, with room for live controls like call buttons and a waveform.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/morphing-island-notch.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type { PointerEvent as ReactPointerEvent, ReactNode } from \"react\";\n\n/*\n * A Dynamic-Island-style status pill with no dependencies.\n *\n * No width or height is ever specified. The content row is measured with a\n * ResizeObserver and the shell is driven to that size by a small spring loop\n * (semi-implicit Euler, written straight to the DOM). Behind the shell two more\n * bodies chase the same target, one stiffer and one softer, and an SVG \"goo\"\n * filter fuses them, so the silhouette stretches and snaps like liquid.\n * The corner radius is derived from the live height every frame, so it never skews.\n */\n\ntype Snap = {\n  key: string;\n  icon: ReactNode;\n  label: string | null | undefined;\n  detail: string | null | undefined;\n  trailing: ReactNode;\n};\n\nconst PAD = 24; // how far the goo layer extends past the shell on every side\nconst MAX_RADIUS = 28;\n\nconst CSS = [\n  \".mi-in{animation:mi-in 340ms cubic-bezier(.22,1,.36,1) 70ms both}\",\n  \".mi-out{animation:mi-out 200ms cubic-bezier(.4,0,1,1) both}\",\n  \"@keyframes mi-in{from{opacity:0;filter:blur(6px);transform:scale(.94)}to{opacity:1;filter:blur(0);transform:scale(1)}}\",\n  \"@keyframes mi-out{from{opacity:1;filter:blur(0);transform:scale(1)}to{opacity:0;filter:blur(6px);transform:scale(.94)}}\",\n  \".mi-glow{opacity:0;transition:opacity 260ms ease}\",\n  \".mi-root:hover .mi-glow{opacity:1}\",\n  \"@media (prefers-reduced-motion:reduce){.mi-in{animation:mi-fade 200ms linear both}.mi-out{animation:mi-fade-out 120ms linear both}.mi-glow{display:none}}\",\n  \"@keyframes mi-fade{from{opacity:0}to{opacity:1}}\",\n  \"@keyframes mi-fade-out{from{opacity:1}to{opacity:0}}\",\n].join(\"\\n\");\n\nconst markInert = (el: HTMLDivElement | null) => {\n  if (el) el.toggleAttribute(\"inert\", true);\n};\n\nconst nowMs = () => performance.now();\n\ntype Spring = { x: number; v: number };\nconst spring = (): Spring => ({ x: 0, v: 0 });\n\nfunction Row({ snap }: { snap: Snap }) {\n  const expanded = snap.label != null;\n  return (\n    <div className=\"flex items-center gap-2.5 p-2\">\n      <span className=\"flex size-7 min-h-7 min-w-7 shrink-0 items-center justify-center\">{snap.icon}</span>\n      {expanded ? (\n        <div className=\"flex min-w-0 flex-col pr-1 leading-tight\" aria-hidden=\"true\">\n          <span\n            className=\"max-w-[15rem] truncate whitespace-nowrap uppercase opacity-55\"\n            style={{\n              fontFamily: \"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace\",\n              fontSize: 9.5,\n              letterSpacing: \"0.15em\",\n            }}\n          >\n            {snap.label}\n          </span>\n          {snap.detail != null ? (\n            <span className=\"max-w-[15rem] truncate whitespace-nowrap text-[13.5px] font-semibold tabular-nums\">\n              {snap.detail}\n            </span>\n          ) : null}\n        </div>\n      ) : null}\n      {expanded && snap.trailing ? <span className=\"flex shrink-0 items-center pl-1\">{snap.trailing}</span> : null}\n    </div>\n  );\n}\n\nexport function MorphingIslandNotch({\n  icon,\n  label,\n  detail,\n  stiffness = 420,\n  dark = true,\n  trailing,\n  stateKey,\n  idleWidth = 0,\n  className,\n}: {\n  icon: ReactNode;\n  /** When label is null/undefined the island collapses to its compact pill. */\n  label?: string | null;\n  detail?: string | null;\n  /** Spring stiffness of the shell (the goo bodies derive theirs from it). */\n  stiffness?: number;\n  /** Dark island on a light page, or the inverse. */\n  dark?: boolean;\n  /** Optional content on the right of the expanded island (controls, a waveform). */\n  trailing?: ReactNode;\n  /**\n   * Content crossfades when this changes. Defaults to label + detail, so pass one when\n   * the text updates live (a timer) and should change in place instead of crossfading.\n   */\n  stateKey?: string | number;\n  /** Minimum width of the collapsed pill in px, for a wider resting notch. */\n  idleWidth?: number;\n  className?: string;\n}) {\n  const expanded = label != null;\n  const key = stateKey != null ? \"k\" + String(stateKey) : (expanded ? \"1\" : \"0\") + (label ?? \"\") + \"\\u0001\" + (detail ?? \"\");\n  const cur: Snap = { key, icon, label, detail, trailing };\n\n  // Keep the outgoing content on screen while it fades, derived during render.\n  const [shown, setShown] = useState<Snap>(cur);\n  const [prev, setPrev] = useState<Snap | null>(null);\n  if (shown.key !== key) {\n    setPrev(shown);\n    setShown(cur);\n  }\n  useEffect(() => {\n    if (!prev) return;\n    const t = window.setTimeout(() => setPrev(null), 460);\n    return () => window.clearTimeout(t);\n  }, [prev]);\n\n  const fid = \"mi\" + useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const shellRef = useRef<HTMLDivElement>(null);\n  const measRef = useRef<HTMLDivElement>(null);\n  const mainRef = useRef<HTMLDivElement>(null);\n  const fastRef = useRef<HTMLDivElement>(null);\n  const slowRef = useRef<HTMLDivElement>(null);\n  const rimRef = useRef<HTMLDivElement>(null);\n  const cfg = useRef({ stiffness, idleWidth, expanded });\n  const wakeRef = useRef<(() => void) | null>(null);\n\n  useEffect(() => {\n    const shell = shellRef.current;\n    const meas = measRef.current;\n    const main = mainRef.current;\n    const fast = fastRef.current;\n    const slow = slowRef.current;\n    const rim = rimRef.current;\n    if (!shell || !meas || !main || !fast || !slow || !rim) return;\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const w = spring();\n    const h = spring();\n    const fw = spring();\n    const fh = spring();\n    const sw = spring();\n    const sh = spring();\n    const all = [w, h, fw, fh, sw, sh];\n    const tgt = { w: 0, h: 0 };\n    let ready = false;\n    let raf = 0;\n    let last = 0;\n\n    const place = (el: HTMLDivElement, bw: number, bh: number) => {\n      const ww = Math.max(bw, 2);\n      const hh = Math.max(bh, 2);\n      el.style.width = ww + \"px\";\n      el.style.height = hh + \"px\";\n      el.style.left = PAD + (w.x - ww) / 2 + \"px\";\n      el.style.top = PAD + (h.x - hh) / 2 + \"px\";\n      el.style.borderRadius = Math.min(hh / 2, MAX_RADIUS) + \"px\";\n    };\n    const apply = () => {\n      const ww = Math.max(w.x, 2);\n      const hh = Math.max(h.x, 2);\n      const r = Math.min(hh / 2, MAX_RADIUS) + \"px\";\n      shell.style.width = ww + \"px\";\n      shell.style.height = hh + \"px\";\n      shell.style.borderRadius = r;\n      rim.style.borderRadius = r;\n      main.style.borderRadius = r;\n      place(fast, fw.x, fh.x);\n      place(slow, sw.x, sh.x);\n    };\n    const snap = () => {\n      w.x = fw.x = sw.x = tgt.w;\n      h.x = fh.x = sh.x = tgt.h;\n      for (const s of all) s.v = 0;\n      apply();\n    };\n    const integrate = (s: Spring, to: number, k: number, zeta: number, dt: number) => {\n      const m = 0.9;\n      const c = 2 * zeta * Math.sqrt(k * m);\n      s.v += ((-k * (s.x - to) - c * s.v) / m) * dt;\n      s.x += s.v * dt;\n    };\n    const loop = (t: number) => {\n      raf = 0;\n      let rest = Math.min(0.05, Math.max(0, (t - last) / 1000));\n      last = t;\n      const k = cfg.current.stiffness;\n      while (rest > 1e-6) {\n        const dt = Math.min(rest, 1 / 120);\n        rest -= dt;\n        integrate(w, tgt.w, k, 0.874, dt);\n        integrate(h, tgt.h, k, 0.874, dt);\n        integrate(fw, tgt.w, k * 2.1, 0.6, dt);\n        integrate(fh, tgt.h, k * 2.1, 0.6, dt);\n        integrate(sw, tgt.w, k * 0.3, 0.82, dt);\n        integrate(sh, tgt.h, k * 0.3, 0.82, dt);\n      }\n      const targets = [tgt.w, tgt.h, tgt.w, tgt.h, tgt.w, tgt.h];\n      const settled = all.every((s, i) => Math.abs(s.x - (targets[i] ?? 0)) < 0.08 && Math.abs(s.v) < 0.08);\n      if (settled) {\n        snap();\n        return;\n      }\n      apply();\n      raf = requestAnimationFrame(loop);\n    };\n    const wake = () => {\n      const c = cfg.current;\n      tgt.w = Math.max(meas.offsetWidth, c.expanded ? 0 : c.idleWidth);\n      tgt.h = meas.offsetHeight;\n      if (tgt.w === 0 || tgt.h === 0) return;\n      if (!ready || mq.matches) {\n        ready = true;\n        snap();\n        return;\n      }\n      if (!raf) {\n        last = nowMs();\n        raf = requestAnimationFrame(loop);\n      }\n    };\n    wakeRef.current = wake;\n    const ro = new ResizeObserver(wake);\n    ro.observe(meas);\n    mq.addEventListener(\"change\", wake);\n    wake();\n    return () => {\n      wakeRef.current = null;\n      ro.disconnect();\n      mq.removeEventListener(\"change\", wake);\n      cancelAnimationFrame(raf);\n    };\n  }, []);\n\n  useEffect(() => {\n    cfg.current = { stiffness, idleWidth, expanded };\n    wakeRef.current?.();\n  }, [stiffness, idleWidth, expanded]);\n\n  const onMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n    const shell = shellRef.current;\n    if (!shell) return;\n    const r = shell.getBoundingClientRect();\n    const k = r.width > 0 ? shell.offsetWidth / r.width : 1;\n    shell.style.setProperty(\"--mi-x\", (e.clientX - r.left) * k + \"px\");\n    shell.style.setProperty(\"--mi-y\", (e.clientY - r.top) * k + \"px\");\n  };\n\n  const bg = dark ? \"#000\" : \"#fff\";\n  const fg = dark ? \"#fff\" : \"#0a0c10\";\n  const rimShadow = dark\n    ? \"inset 0 0 0 1px rgba(255,255,255,0.1), inset 0 1px 0 rgba(255,255,255,0.14), 0 16px 34px -14px rgba(0,0,0,0.65), 0 2px 6px rgba(0,0,0,0.3)\"\n    : \"inset 0 0 0 1px rgba(10,12,16,0.09), 0 16px 34px -14px rgba(10,12,16,0.3), 0 2px 6px rgba(10,12,16,0.08)\";\n  const glow = dark ? \"rgba(255,255,255,0.11)\" : \"rgba(10,12,16,0.06)\";\n  const animateIn = prev !== null;\n\n  return (\n    <div\n      className={\"mi-root relative inline-flex max-w-full align-middle\" + (className ? \" \" + className : \"\")}\n      onPointerMove={onMove}\n    >\n      <style>{CSS}</style>\n      <svg width=\"0\" height=\"0\" aria-hidden=\"true\" focusable=\"false\" style={{ position: \"absolute\" }}>\n        <filter id={fid} x=\"-25%\" y=\"-90%\" width=\"150%\" height=\"280%\" colorInterpolationFilters=\"sRGB\">\n          <feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"7\" result=\"b\" />\n          <feColorMatrix in=\"b\" type=\"matrix\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 20 -9\" />\n        </filter>\n      </svg>\n\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute\" style={{ inset: -PAD, filter: \"url(#\" + fid + \")\" }}>\n        <div ref={mainRef} className=\"absolute\" style={{ inset: PAD, background: bg }} />\n        <div ref={fastRef} className=\"absolute\" style={{ background: bg }} />\n        <div ref={slowRef} className=\"absolute\" style={{ background: bg }} />\n      </div>\n\n      <div\n        ref={shellRef}\n        className=\"relative flex items-center justify-center overflow-hidden\"\n        style={{ background: bg, color: fg }}\n      >\n        <div\n          aria-hidden=\"true\"\n          className=\"mi-glow pointer-events-none absolute inset-0\"\n          style={{\n            background:\n              \"radial-gradient(130px circle at var(--mi-x, 50%) var(--mi-y, 50%), \" + glow + \", transparent 70%)\",\n          }}\n        />\n        {prev ? (\n          <div\n            key={\"p\" + prev.key}\n            aria-hidden=\"true\"\n            ref={markInert}\n            className=\"mi-out pointer-events-none absolute inset-0 flex items-center justify-center\"\n          >\n            <div className=\"w-max\">\n              <Row snap={prev} />\n            </div>\n          </div>\n        ) : null}\n        <div ref={measRef} className=\"relative w-max\">\n          <div key={key} className={animateIn ? \"mi-in\" : undefined}>\n            <Row snap={cur} />\n          </div>\n        </div>\n      </div>\n\n      <div\n        ref={rimRef}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0\"\n        style={{ boxShadow: rimShadow }}\n      />\n\n      <span className=\"sr-only\" role=\"status\" aria-live=\"polite\" aria-atomic=\"true\">\n        {expanded ? label + (detail ? \": \" + detail : \"\") : \"\"}\n      </span>\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/morphing-island-notch.tsx"}],"meta":{"tier":"free","tags":["island","notch","layout","status","goo","spring"],"href":"https://viberdy.dev/library/morphing-island-notch","aiPrompt":"Build a dependency-free React + Tailwind component named MorphingIslandNotch: a Dynamic-Island-style status pill. One \"use client\" file, plain CSS in a style element (not React 19 style hoisting), no animation library.\n\nProps: icon (ReactNode, required), label (string | null, null or undefined collapses to the compact pill), detail (string | null), stiffness (number, default 420), dark (boolean, default true: black island #000 with white text; false: white island with #0a0c10 text), plus optional trailing (ReactNode shown on the right only when expanded), stateKey (string | number, content crossfades when it changes; default is label + detail), idleWidth (number px, minimum collapsed width, default 0) and className on the root. Root is a relative inline-flex with max-w-full.\n\nSizing: never write a width or height. A w-max measure div holds a row with 8px padding: a 28px icon slot, a 10px gap, then a column with the label (ui-monospace 9.5px uppercase, letter-spacing .15em, 55% opacity, truncate at 15rem) over the detail (13.5px/600, tabular numerals, truncate), then trailing. A ResizeObserver on the measure div sets targets (width = max(offsetWidth, collapsed ? idleWidth : 0), height = offsetHeight).\n\nMotion: one rAF loop started on demand, semi-implicit Euler in 1/120s substeps (dt capped at 50ms), mass 0.9, damping ratio 0.874 for the shell. The shell is an overflow-hidden flex box (items-center, justify-center so content stays centered while it resizes) whose width, height and border-radius are written straight to the DOM every frame; radius = min(height / 2, 28px). Stop the loop when every spring is within 0.08 px and 0.08 px/s, snapping to target. Gooey layer: an absolutely positioned layer extending 24px past the shell, with CSS filter url(#id), holding three black (or white) rounded bodies centered on the shell: one matching the shell, a fast one (stiffness x2.1, damping ratio 0.6, overshoots) and a slow one (stiffness x0.3, ratio 0.82, trails). SVG filter: feGaussianBlur stdDeviation 7, then feColorMatrix with alpha row \"0 0 0 20 -9\", region x -25% y -90% width 150% height 280%, sRGB. The solid shell sits on top so its edge stays crisp and only the bodies' overshoot shows as goo. The filter id comes from useId with non-alphanumerics stripped.\n\nContent swap: when the key changes keep the previous row mounted for 460ms, absolutely centered, aria-hidden and inert, animating out over 200ms (opacity to 0, blur 6px, scale .94); the new row animates in over 340ms with a 70ms delay (opacity, blur 6px to 0, scale .94 to 1, cubic-bezier(.22,1,.36,1)). Derive the previous snapshot during render (compare keys, setState in render) and clear it in a timeout. No animation on first mount.\n\nSurface: a rim layer on top, pointer-events none, box-shadow inset 0 0 0 1px rgba(255,255,255,.1), inset 0 1px 0 rgba(255,255,255,.14), 0 16px 34px -14px rgba(0,0,0,.65), 0 2px 6px rgba(0,0,0,.3) (the light version uses 10,12,16 at lower alpha). Inside the shell a 130px radial pointer highlight (white 11%, 6% dark ink on light) follows the pointer using CSS variables mapped to layout pixels (offsetWidth / rect.width), fading in on hover.\n\nA11y: a visually hidden role=\"status\" aria-live=\"polite\" region with \"label: detail\"; the visible label and detail are aria-hidden; trailing content stays focusable and brings its own labels. prefers-reduced-motion: snap to size (also when the media query changes), opacity-only crossfade, no pointer highlight. Props read by the loop go through a ref synced in an effect. Runs on React 18 and 19.","license":"https://viberdy.dev/license"}}