{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"quiet-status-stack","type":"registry:component","title":"Quiet Status Stack","description":"Background work, without the applause.","dependencies":[],"categories":["systems","notifications","progress","async","status"],"files":[{"path":"components/lab/quiet-status-stack/quiet-status-stack.tsx","target":"components/lab/quiet-status-stack/quiet-status-stack.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport \"./quiet-status-stack.css\";\n\nexport type StatusTone = \"pending\" | \"processing\" | \"success\" | \"error\";\n\nexport type StatusAction = {\n  label: string;\n  onClick: () => void;\n  busy?: boolean;\n};\n\nexport type StatusItem = {\n  id: string;\n  title: string;\n  detail?: string;\n  status: StatusTone;\n  /** 0–1 for determinate work. Omit for an indeterminate bar. */\n  progress?: number;\n  action?: StatusAction;\n  /** Defaults to true. Errors stay until dismissed. */\n  dismissible?: boolean;\n  /** Only used for settled items. Pauses on hover and focus. */\n  autoDismissMs?: number;\n};\n\nexport type QuietStatusStackProps = {\n  items: StatusItem[];\n  onDismiss?: (id: string) => void;\n  /** How many rows remain visible at once. */\n  max?: number;\n  label?: string;\n  className?: string;\n};\n\nfunction Icon({ tone }: { tone: StatusTone }) {\n  if (tone === \"success\") {\n    return (\n      <svg viewBox=\"0 0 18 18\" aria-hidden=\"true\" focusable=\"false\">\n        <path\n          d=\"M3.5 9.5l3.4 3.2 7.6-8\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"1.7\"\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n        />\n      </svg>\n    );\n  }\n  if (tone === \"error\") {\n    return (\n      <svg viewBox=\"0 0 18 18\" aria-hidden=\"true\" focusable=\"false\">\n        <path\n          d=\"M9 3.2v7.1\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"1.8\"\n          strokeLinecap=\"round\"\n        />\n        <circle cx=\"9\" cy=\"14\" r=\"1\" fill=\"currentColor\" />\n      </svg>\n    );\n  }\n  if (tone === \"processing\") {\n    return (\n      <svg\n        className=\"qs-spinner\"\n        viewBox=\"0 0 18 18\"\n        aria-hidden=\"true\"\n        focusable=\"false\"\n      >\n        <circle\n          cx=\"9\"\n          cy=\"9\"\n          r=\"6.4\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"1.5\"\n          strokeOpacity=\"0.24\"\n        />\n        <path\n          d=\"M9 2.6a6.4 6.4 0 0 1 6.4 6.4\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"1.5\"\n          strokeLinecap=\"round\"\n        />\n      </svg>\n    );\n  }\n  return (\n    <svg viewBox=\"0 0 18 18\" aria-hidden=\"true\" focusable=\"false\">\n      <circle cx=\"9\" cy=\"9\" r=\"3.1\" fill=\"currentColor\" opacity=\"0.55\" />\n    </svg>\n  );\n}\n\nfunction StatusRow({\n  item,\n  onDismiss,\n  register,\n}: {\n  item: StatusItem;\n  onDismiss?: (id: string) => void;\n  register: (id: string, node: HTMLElement | null) => void;\n}) {\n  const rowRef = useRef<HTMLElement>(null);\n  const [leaving, setLeaving] = useState(false);\n  const [paused, setPaused] = useState(false);\n  const remaining = useRef<number | null>(null);\n  const started = useRef<number>(0);\n  const timer = useRef<number | null>(null);\n  const leaveTimer = useRef<number | null>(null);\n  const dismissing = useRef(false);\n  const auto = Boolean(item.autoDismissMs && item.status === \"success\");\n  const canDismiss = item.dismissible !== false;\n\n  const dismiss = (delay = true) => {\n    if (dismissing.current) return;\n    dismissing.current = true;\n    if (!delay) {\n      onDismiss?.(item.id);\n      return;\n    }\n    setLeaving(true);\n    leaveTimer.current = window.setTimeout(\n      () => onDismiss?.(item.id),\n      180,\n    );\n  };\n\n  /* Auto-dismiss is deadline-based so hover/focus pauses preserve the rest. */\n  useEffect(() => {\n    if (!auto || paused) {\n      if (timer.current !== null) {\n        window.clearTimeout(timer.current);\n        timer.current = null;\n      }\n      if (remaining.current !== null && started.current) {\n        remaining.current = Math.max(\n          0,\n          remaining.current - (Date.now() - started.current),\n        );\n      }\n      return;\n    }\n    if (remaining.current === null)\n      remaining.current = item.autoDismissMs ?? 0;\n    if (remaining.current <= 0) return;\n    started.current = Date.now();\n    timer.current = window.setTimeout(() => {\n      timer.current = null;\n      dismiss();\n    }, remaining.current);\n    return () => {\n      if (timer.current !== null) {\n        window.clearTimeout(timer.current);\n        timer.current = null;\n      }\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [auto, paused, item.autoDismissMs, item.id]);\n\n  useEffect(() => {\n    const onVisibility = () => setPaused(document.hidden);\n    document.addEventListener(\"visibilitychange\", onVisibility);\n    return () => document.removeEventListener(\"visibilitychange\", onVisibility);\n  }, []);\n\n  useEffect(\n    () => () => {\n      if (timer.current !== null) window.clearTimeout(timer.current);\n      if (leaveTimer.current !== null) window.clearTimeout(leaveTimer.current);\n    },\n    [],\n  );\n\n  const progress =\n    typeof item.progress === \"number\"\n      ? Math.max(0, Math.min(1, item.progress))\n      : null;\n\n  return (\n    <li\n      ref={(node) => {\n        rowRef.current = node;\n        register(item.id, node);\n      }}\n      className=\"qs-item\"\n      data-tone={item.status}\n      data-leaving={leaving ? \"true\" : \"false\"}\n      onPointerEnter={() => setPaused(true)}\n      onPointerLeave={() => setPaused(false)}\n      onFocusCapture={() => setPaused(true)}\n      onBlurCapture={(event) => {\n        if (!event.currentTarget.contains(event.relatedTarget as Node)) {\n          setPaused(false);\n        }\n      }}\n    >\n      <span className=\"qs-icon\" aria-hidden=\"true\">\n        <Icon tone={item.status} />\n      </span>\n      <div className=\"qs-copy\">\n        <p className=\"qs-title\">{item.title}</p>\n        {item.detail ? <p className=\"qs-detail\">{item.detail}</p> : null}\n        {item.status === \"processing\" ? (\n          <div\n            className=\"qs-progress\"\n            role=\"progressbar\"\n            aria-label={`${item.title} progress`}\n            aria-valuemin={0}\n            aria-valuemax={100}\n            aria-valuenow={\n              progress === null ? undefined : Math.round(progress * 100)\n            }\n            data-indeterminate={progress === null ? \"true\" : \"false\"}\n          >\n            <span\n              style={\n                progress === null\n                  ? undefined\n                  : { transform: `scaleX(${progress})` }\n              }\n            />\n          </div>\n        ) : null}\n      </div>\n      <div className=\"qs-actions\">\n        {item.action ? (\n          <button\n            type=\"button\"\n            className=\"qs-action\"\n            onClick={item.action.onClick}\n            disabled={item.action.busy}\n          >\n            {item.action.busy ? \"Working…\" : item.action.label}\n          </button>\n        ) : null}\n        {canDismiss ? (\n          <button\n            type=\"button\"\n            className=\"qs-dismiss\"\n            aria-label={`Dismiss ${item.title}`}\n            onClick={() => dismiss()}\n          >\n            <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" focusable=\"false\">\n              <path\n                d=\"M4 4l8 8M12 4l-8 8\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth=\"1.4\"\n                strokeLinecap=\"round\"\n              />\n            </svg>\n          </button>\n        ) : null}\n      </div>\n    </li>\n  );\n}\n\n/**\n * QUIET STATUS STACK\n *\n * A low-volume activity log for work that continues in the background.\n * Rows move with a small FLIP pass when one is added or removed, while\n * the new row enters on top of that movement. Success can auto-dismiss\n * and pauses on hover or focus; errors wait for a person. A single\n * polite live region announces state changes, never progress frames.\n */\nexport function QuietStatusStack({\n  items,\n  onDismiss,\n  max = 4,\n  label = \"Background activity\",\n  className,\n}: QuietStatusStackProps) {\n  const visible = items.slice(0, Math.max(1, max));\n  const nodes = useRef(new Map<string, HTMLElement>());\n  const boxes = useRef(new Map<string, DOMRect>());\n  const previous = useRef<string[]>([]);\n  const live = useRef<HTMLParagraphElement>(null);\n  const tones = useRef(new Map<string, StatusTone>());\n\n  const register = (id: string, node: HTMLElement | null) => {\n    if (node) nodes.current.set(id, node);\n    else nodes.current.delete(id);\n  };\n\n  useLayoutEffect(() => {\n    if (window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const next = new Map<string, DOMRect>();\n    for (const item of visible) {\n      const node = nodes.current.get(item.id);\n      if (!node) continue;\n      next.set(item.id, node.getBoundingClientRect());\n    }\n    if (previous.current.length) {\n      let index = 0;\n      for (const item of visible) {\n        const node = nodes.current.get(item.id);\n        const before = boxes.current.get(item.id);\n        if (!node || !before) {\n          index += 1;\n          continue;\n        }\n        const after = next.get(item.id);\n        if (after && Math.abs(before.top - after.top) > 0.5) {\n          node.animate(\n            [\n              { transform: `translateY(${before.top - after.top}px)` },\n              { transform: \"translateY(0)\" },\n            ],\n            {\n              duration: 260,\n              easing: \"cubic-bezier(0.22, 1, 0.36, 1)\",\n              delay: index < previous.current.length ? 0 : 30,\n            },\n          );\n        }\n        index += 1;\n      }\n      for (const item of visible) {\n        if (!previous.current.includes(item.id) && nodes.current.get(item.id)) {\n          nodes.current.get(item.id)!.animate(\n            [\n              { opacity: 0, transform: \"translateY(-5px) scale(0.99)\" },\n              { opacity: 1, transform: \"translateY(0) scale(1)\" },\n            ],\n            { duration: 240, easing: \"cubic-bezier(0.22, 1, 0.36, 1)\" },\n          );\n        }\n      }\n    }\n    boxes.current = next;\n    previous.current = visible.map((item) => item.id);\n\n    /* Announce transitions, not progress ticks. */\n    let message = \"\";\n    for (const item of visible) {\n      const tone = tones.current.get(item.id);\n      if (tone !== item.status) {\n        tones.current.set(item.id, item.status);\n        if (item.status === \"success\") message = `${item.title} finished.`;\n        else if (item.status === \"error\")\n          message = `${item.title} needs attention.`;\n        else if (!tone && item.status === \"processing\")\n          message = `${item.title} started.`;\n      }\n    }\n    if (message && live.current) {\n      live.current.textContent =\n        live.current.textContent === message ? `${message}\\u200B` : message;\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [visible.map((item) => `${item.id}:${item.status}`).join(\"|\")]);\n\n  return (\n    <div className={`qs-root${className ? ` ${className}` : \"\"}`}>\n      <p ref={live} className=\"qs-live\" aria-live=\"polite\" aria-atomic=\"true\" />\n      <ul className=\"qs-list\" aria-label={label}>\n        {visible.map((item) => (\n          <StatusRow\n            key={item.id}\n            item={item}\n            onDismiss={onDismiss}\n            register={register}\n          />\n        ))}\n      </ul>\n    </div>\n  );\n}\n"},{"path":"components/lab/quiet-status-stack/quiet-status-stack.css","target":"components/lab/quiet-status-stack/quiet-status-stack.css","type":"registry:file","content":".qs-root {\n  --qs-ink: #1d2422;\n  --qs-muted: #66706c;\n  --qs-line: rgba(29, 36, 34, 0.12);\n  --qs-surface: #ffffff;\n  --qs-soft: #f5f6f4;\n  --qs-ok: #1d6b4c;\n  --qs-warn: #9a4b1c;\n  --qs-danger: #a12f2a;\n  --qs-focus: #1d2422;\n  --qs-ease: cubic-bezier(0.22, 1, 0.36, 1);\n  width: min(380px, 100%);\n  color: var(--qs-ink);\n  font: inherit;\n}\n\n.qs-live {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  padding: 0;\n  margin: -1px;\n  overflow: hidden;\n  clip: rect(0 0 0 0);\n  white-space: nowrap;\n  border: 0;\n}\n\n.qs-list {\n  display: flex;\n  flex-direction: column;\n  gap: 8px;\n  margin: 0;\n  padding: 0;\n  list-style: none;\n}\n\n.qs-item {\n  position: relative;\n  display: flex;\n  align-items: flex-start;\n  gap: 11px;\n  padding: 12px 12px 12px 13px;\n  border: 1px solid var(--qs-line);\n  border-radius: 11px;\n  background: var(--qs-surface);\n  box-shadow:\n    0 1px 2px rgba(29, 36, 34, 0.04),\n    0 10px 26px -22px rgba(29, 36, 34, 0.32);\n  transition:\n    opacity 180ms ease,\n    transform 180ms ease,\n    border-color 180ms ease;\n}\n\n.qs-item[data-leaving=\"true\"] {\n  opacity: 0;\n  transform: translateX(8px);\n  pointer-events: none;\n}\n\n.qs-item[data-tone=\"error\"] {\n  border-color: color-mix(in srgb, var(--qs-danger) 34%, var(--qs-line));\n  background: color-mix(in srgb, var(--qs-danger) 3%, var(--qs-surface));\n}\n\n.qs-icon {\n  flex: none;\n  display: grid;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  margin-top: 1px;\n  border-radius: 50%;\n  background: var(--qs-soft);\n  color: var(--qs-muted);\n}\n\n.qs-item[data-tone=\"success\"] .qs-icon {\n  color: var(--qs-ok);\n  background: color-mix(in srgb, var(--qs-ok) 10%, transparent);\n}\n\n.qs-item[data-tone=\"error\"] .qs-icon {\n  color: var(--qs-danger);\n  background: color-mix(in srgb, var(--qs-danger) 10%, transparent);\n}\n\n.qs-item[data-tone=\"processing\"] .qs-icon {\n  color: var(--qs-warn);\n  background: color-mix(in srgb, var(--qs-warn) 9%, transparent);\n}\n\n.qs-icon svg {\n  width: 16px;\n  height: 16px;\n}\n\n.qs-spinner {\n  animation: qs-spin 1.2s linear infinite;\n}\n\n.qs-copy {\n  flex: 1;\n  min-width: 0;\n  padding-top: 1px;\n}\n\n.qs-title {\n  margin: 0;\n  font-size: 0.8125rem;\n  font-weight: 600;\n  letter-spacing: -0.005em;\n  line-height: 1.35;\n  overflow-wrap: anywhere;\n}\n\n.qs-detail {\n  margin: 2px 0 0;\n  color: var(--qs-muted);\n  font-size: 0.75rem;\n  line-height: 1.42;\n  overflow-wrap: anywhere;\n}\n\n.qs-progress {\n  position: relative;\n  height: 3px;\n  margin-top: 8px;\n  overflow: hidden;\n  border-radius: 999px;\n  background: rgba(29, 36, 34, 0.1);\n}\n\n.qs-progress > span {\n  display: block;\n  width: 100%;\n  height: 100%;\n  border-radius: inherit;\n  background: var(--qs-warn);\n  transform-origin: left center;\n  transition: transform 320ms linear;\n}\n\n.qs-progress[data-indeterminate=\"true\"] > span {\n  width: 38%;\n  animation: qs-indeterminate 1.4s var(--qs-ease) infinite;\n}\n\n.qs-actions {\n  flex: none;\n  display: flex;\n  align-items: center;\n  gap: 5px;\n  margin-top: -2px;\n}\n\n.qs-action {\n  min-height: 28px;\n  padding: 4px 8px;\n  border: 1px solid var(--qs-line);\n  border-radius: 6px;\n  background: var(--qs-surface);\n  color: var(--qs-ink);\n  font: inherit;\n  font-size: 0.6875rem;\n  font-weight: 600;\n  cursor: pointer;\n  transition:\n    background-color 140ms ease,\n    border-color 140ms ease;\n}\n\n.qs-action:hover {\n  background: var(--qs-soft);\n  border-color: rgba(29, 36, 34, 0.2);\n}\n\n.qs-action:disabled {\n  opacity: 0.5;\n  cursor: wait;\n}\n\n.qs-dismiss {\n  display: grid;\n  place-items: center;\n  width: 26px;\n  height: 26px;\n  border: 0;\n  border-radius: 6px;\n  background: transparent;\n  color: var(--qs-muted);\n  cursor: pointer;\n  transition:\n    color 140ms ease,\n    background-color 140ms ease;\n}\n\n.qs-dismiss:hover {\n  color: var(--qs-ink);\n  background: var(--qs-soft);\n}\n\n.qs-action:focus-visible,\n.qs-dismiss:focus-visible {\n  outline: 2px solid var(--qs-focus);\n  outline-offset: 1px;\n}\n\n.qs-dismiss svg {\n  width: 13px;\n  height: 13px;\n}\n\n@keyframes qs-spin {\n  to {\n    transform: rotate(360deg);\n  }\n}\n\n@keyframes qs-indeterminate {\n  0% {\n    transform: translateX(-105%);\n  }\n  100% {\n    transform: translateX(275%);\n  }\n}\n\n@media (max-width: 420px) {\n  .qs-item {\n    flex-wrap: wrap;\n  }\n\n  .qs-copy {\n    flex-basis: calc(100% - 38px);\n  }\n\n  .qs-actions {\n    margin-left: 35px;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .qs-item {\n    transition-duration: 0.01ms;\n  }\n\n  .qs-spinner {\n    animation: none;\n  }\n\n  .qs-progress[data-indeterminate=\"true\"] > span {\n    width: 42%;\n    animation: none;\n  }\n}\n"}]}