{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "status-island",
  "title": "Status Island",
  "description": "A small pill at the edge of the screen that reports background work. It reshapes as tasks come and go, opens into the full list, and leaves once everything is done.",
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/default/status-island/status-island.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport type StatusIslandTaskStatus = \"running\" | \"done\" | \"error\"\n\nexport interface StatusIslandTask {\n  id: string\n  label: string\n  /** From 0 to 1. Leave it out while the size of the work is unknown. */\n  progress?: number\n  status: StatusIslandTaskStatus\n  /** A second line, such as the reason a task failed. */\n  detail?: string\n}\n\nexport type StatusIslandState = \"hidden\" | \"running\" | \"error\" | \"done\"\n\nexport interface StatusIslandProps extends Omit<\n  React.HTMLAttributes<HTMLDivElement>,\n  \"children\"\n> {\n  tasks: StatusIslandTask[]\n  /** Omit it and running tasks have no Cancel button. */\n  onCancel?: (id: string) => void\n  /** Omit it and failed tasks have no Retry button. */\n  onRetry?: (id: string) => void\n  /** The accessible name of the island and its list. */\n  label?: string\n  doneLabel?: string\n  failedLabel?: string\n  cancelLabel?: string\n  retryLabel?: string\n  /** How long \"Done\" stays up before the island leaves, in milliseconds. */\n  doneDuration?: number\n}\n\nconst SPRING =\n  \"transition-[width,height,border-radius,opacity,transform] duration-300 ease-[cubic-bezier(0.3,1.3,0.5,1)] motion-reduce:transition-none\"\n\nfunction percent(progress: number) {\n  return Math.round(Math.min(Math.max(progress, 0), 1) * 100)\n}\n\nfunction Ring({ task }: { task: StatusIslandTask }) {\n  const known = task.status === \"running\" && task.progress !== undefined\n  const value = known ? percent(task.progress ?? 0) : 0\n\n  return (\n    <span aria-hidden=\"true\" className=\"relative size-5 shrink-0\">\n      {task.status === \"error\" ? (\n        <span className=\"bg-destructive text-background absolute inset-0.5 grid place-items-center rounded-full text-[10px] leading-none font-bold\">\n          !\n        </span>\n      ) : task.status === \"done\" ? (\n        <svg className=\"absolute inset-0\" fill=\"none\" viewBox=\"0 0 20 20\">\n          <circle cx=\"10\" cy=\"10\" r=\"8\" className=\"fill-primary\" />\n          <path\n            d=\"M6.5 10.5 9 13l4.5-5.5\"\n            className=\"stroke-primary-foreground\"\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            strokeWidth=\"2\"\n          />\n        </svg>\n      ) : (\n        <svg\n          className={cn(\n            \"absolute inset-0 -rotate-90\",\n            !known && \"animate-spin motion-reduce:animate-none\"\n          )}\n          fill=\"none\"\n          viewBox=\"0 0 20 20\"\n        >\n          <circle\n            cx=\"10\"\n            cy=\"10\"\n            r=\"8\"\n            className=\"stroke-foreground/15\"\n            strokeWidth=\"2.5\"\n          />\n          <circle\n            cx=\"10\"\n            cy=\"10\"\n            r=\"8\"\n            pathLength={100}\n            className=\"stroke-primary transition-[stroke-dashoffset] duration-300 ease-out motion-reduce:transition-none\"\n            strokeDasharray={100}\n            strokeDashoffset={known ? 100 - value : 70}\n            strokeLinecap=\"round\"\n            strokeWidth=\"2.5\"\n          />\n        </svg>\n      )}\n    </span>\n  )\n}\n\nfunction lead(tasks: StatusIslandTask[]) {\n  return (\n    tasks.find((task) => task.status === \"error\") ??\n    tasks.find((task) => task.status === \"running\") ??\n    tasks[tasks.length - 1]\n  )\n}\n\nexport const StatusIsland = React.forwardRef<HTMLDivElement, StatusIslandProps>(\n  function StatusIsland(\n    {\n      className,\n      doneDuration = 1600,\n      doneLabel = \"Done\",\n      cancelLabel = \"Cancel\",\n      failedLabel = \"Failed\",\n      label = \"Background tasks\",\n      onBlur,\n      onCancel,\n      onFocus,\n      onKeyDown,\n      onRetry,\n      retryLabel = \"Retry\",\n      tasks,\n      ...rootProps\n    },\n    forwardedRef\n  ) {\n    const listId = React.useId()\n    const rootRef = React.useRef<HTMLDivElement | null>(null)\n    const contentRef = React.useRef<HTMLDivElement | null>(null)\n    const summaryRef = React.useRef<HTMLButtonElement | null>(null)\n    const [expanded, setExpanded] = React.useState(false)\n    const [focusWithin, setFocusWithin] = React.useState(false)\n    const [size, setSize] = React.useState<{ w: number; h: number } | null>(\n      null\n    )\n    const [dismissedKey, setDismissedKey] = React.useState<string | null>(null)\n\n    const signature = tasks.map((task) => `${task.id}:${task.status}`).join()\n    const [seen, setSeen] = React.useState(() =>\n      Object.fromEntries(tasks.map((task) => [task.id, task.status]))\n    )\n    const [seenSignature, setSeenSignature] = React.useState(signature)\n    const [announcement, setAnnouncement] = React.useState(\"\")\n\n    if (signature !== seenSignature) {\n      const news = tasks\n        .filter((task) => task.status !== \"running\")\n        .filter((task) => seen[task.id] !== task.status)\n        .map((task) =>\n          task.status === \"done\"\n            ? `${task.label} finished`\n            : `${task.label} failed${task.detail ? `: ${task.detail}` : \"\"}`\n        )\n      setSeenSignature(signature)\n      setSeen(Object.fromEntries(tasks.map((task) => [task.id, task.status])))\n      if (news.length) setAnnouncement(news.join(\". \"))\n    }\n\n    const running = tasks.filter((task) => task.status === \"running\")\n    const failed = tasks.filter((task) => task.status === \"error\")\n    const settled = tasks.length > 0 && !running.length && !failed.length\n    const visible = tasks.length > 0 && !(settled && dismissedKey === signature)\n    const open = expanded && visible\n\n    const state: StatusIslandState = !visible\n      ? \"hidden\"\n      : failed.length\n        ? \"error\"\n        : running.length\n          ? \"running\"\n          : \"done\"\n\n    React.useEffect(() => {\n      if (!settled || open || focusWithin) return\n      const timer = setTimeout(() => setDismissedKey(signature), doneDuration)\n      return () => clearTimeout(timer)\n    }, [doneDuration, focusWithin, open, settled, signature])\n\n    React.useEffect(() => {\n      const content = contentRef.current\n      if (!content || typeof ResizeObserver === \"undefined\") return\n\n      const observer = new ResizeObserver(() => {\n        setSize({ w: content.offsetWidth, h: content.offsetHeight })\n      })\n      observer.observe(content)\n      return () => observer.disconnect()\n    }, [])\n\n    React.useEffect(() => {\n      if (!open) return\n\n      function onPointerDown(event: PointerEvent) {\n        if (!rootRef.current?.contains(event.target as Node)) {\n          setExpanded(false)\n        }\n      }\n\n      document.addEventListener(\"pointerdown\", onPointerDown)\n      return () => document.removeEventListener(\"pointerdown\", onPointerDown)\n    }, [open])\n\n    const top = lead(tasks)\n    const others = running.length + failed.length - 1\n    const summaryText = !top\n      ? \"\"\n      : state === \"done\" && tasks.length > 1\n        ? `${tasks.length} tasks`\n        : top.label\n    const summaryValue = !top\n      ? \"\"\n      : state === \"done\"\n        ? doneLabel\n        : top.status === \"error\"\n          ? failedLabel\n          : top.progress !== undefined\n            ? `${percent(top.progress)}%`\n            : \"\"\n\n    return (\n      <>\n        <div\n          {...rootProps}\n          ref={(node) => {\n            rootRef.current = node\n            if (typeof forwardedRef === \"function\") forwardedRef(node)\n            else if (forwardedRef) forwardedRef.current = node\n          }}\n          role=\"region\"\n          aria-label={label}\n          aria-hidden={!visible || undefined}\n          inert={!visible}\n          data-slot=\"status-island\"\n          data-state={state}\n          data-expanded={open || undefined}\n          onFocus={(event) => {\n            onFocus?.(event)\n            setFocusWithin(true)\n          }}\n          onBlur={(event) => {\n            onBlur?.(event)\n            if (!event.currentTarget.contains(event.relatedTarget)) {\n              setFocusWithin(false)\n            }\n          }}\n          onKeyDown={(event) => {\n            onKeyDown?.(event)\n            if (event.defaultPrevented || event.key !== \"Escape\" || !open) {\n              return\n            }\n            event.preventDefault()\n            setExpanded(false)\n            summaryRef.current?.focus()\n          }}\n          className={cn(\n            \"fixed top-4 left-1/2 z-50 -translate-x-1/2\",\n            className\n          )}\n        >\n          <div\n            className={cn(\n              \"bg-foreground text-background overflow-hidden shadow-lg\",\n              SPRING,\n              \"rounded-[1.25rem]\",\n              visible ? \"scale-100 opacity-100\" : \"scale-90 opacity-0\"\n            )}\n            style={size ? { width: size.w, height: size.h } : undefined}\n          >\n            <div ref={contentRef} className=\"w-max\">\n              <button\n                ref={summaryRef}\n                type=\"button\"\n                aria-expanded={open}\n                aria-controls={listId}\n                onClick={() => setExpanded((value) => !value)}\n                className={cn(\n                  \"focus-visible:ring-ring flex min-h-10 items-center gap-2.5 rounded-[1.25rem] py-2 pr-4 pl-2.5 text-left text-sm outline-none focus-visible:ring-2 focus-visible:ring-inset\",\n                  open\n                    ? \"w-[min(22rem,calc(100vw-2rem))]\"\n                    : \"max-w-[min(18rem,calc(100vw-2rem))]\"\n                )}\n              >\n                {top ? <Ring task={top} /> : null}\n                <span className=\"min-w-0 flex-1 truncate font-medium\">\n                  {summaryText}\n                </span>\n                {summaryValue ? (\n                  <span className=\"text-background/70 shrink-0 text-xs tabular-nums\">\n                    {summaryValue}\n                  </span>\n                ) : null}\n                {others > 0 ? (\n                  <span className=\"bg-background/15 shrink-0 rounded-full px-1.5 text-xs tabular-nums\">\n                    +{others}\n                    <span className=\"sr-only\">\n                      {others === 1 ? \" more task\" : \" more tasks\"}\n                    </span>\n                  </span>\n                ) : null}\n              </button>\n\n              <ul\n                id={listId}\n                hidden={!open}\n                className=\"w-[min(22rem,calc(100vw-2rem))] space-y-1 px-2 pb-2\"\n              >\n                {tasks.map((task) => (\n                  <li\n                    key={task.id}\n                    data-status={task.status}\n                    className=\"bg-background/8 flex items-center gap-2.5 rounded-xl px-2.5 py-2\"\n                  >\n                    <Ring task={task} />\n                    <div className=\"min-w-0 flex-1\">\n                      <div className=\"flex items-baseline gap-2\">\n                        <p className=\"min-w-0 flex-1 truncate text-sm\">\n                          {task.label}\n                        </p>\n                        <span className=\"text-background/70 shrink-0 text-xs tabular-nums\">\n                          {task.status === \"error\"\n                            ? failedLabel\n                            : task.status === \"done\"\n                              ? doneLabel\n                              : task.progress !== undefined\n                                ? `${percent(task.progress)}%`\n                                : \"\"}\n                        </span>\n                      </div>\n                      {task.status === \"running\" ? (\n                        <div\n                          role=\"progressbar\"\n                          aria-label={task.label}\n                          aria-valuemin={0}\n                          aria-valuemax={100}\n                          aria-valuenow={\n                            task.progress === undefined\n                              ? undefined\n                              : percent(task.progress)\n                          }\n                          className=\"bg-background/15 mt-1.5 h-1 overflow-hidden rounded-full\"\n                        >\n                          <div\n                            className={cn(\n                              \"bg-primary h-full origin-left rounded-full transition-transform duration-300 ease-out motion-reduce:transition-none\",\n                              task.progress === undefined && \"w-1/3\"\n                            )}\n                            style={\n                              task.progress === undefined\n                                ? undefined\n                                : {\n                                    transform: `scaleX(${percent(task.progress) / 100})`,\n                                  }\n                            }\n                          />\n                        </div>\n                      ) : task.detail ? (\n                        <p className=\"text-background/70 mt-0.5 truncate text-xs\">\n                          {task.detail}\n                        </p>\n                      ) : null}\n                    </div>\n                    {task.status === \"running\" && onCancel ? (\n                      <button\n                        type=\"button\"\n                        aria-label={`${cancelLabel} ${task.label}`}\n                        onClick={() => onCancel(task.id)}\n                        className=\"hover:bg-background/15 focus-visible:ring-ring grid size-8 shrink-0 place-items-center rounded-full text-base leading-none outline-none focus-visible:ring-2\"\n                      >\n                        <svg\n                          aria-hidden=\"true\"\n                          className=\"size-3.5\"\n                          fill=\"none\"\n                          viewBox=\"0 0 14 14\"\n                        >\n                          <path\n                            d=\"m3.5 3.5 7 7m0-7-7 7\"\n                            stroke=\"currentColor\"\n                            strokeLinecap=\"round\"\n                            strokeWidth=\"1.75\"\n                          />\n                        </svg>\n                      </button>\n                    ) : null}\n                    {task.status === \"error\" && onRetry ? (\n                      <button\n                        type=\"button\"\n                        aria-label={`${retryLabel} ${task.label}`}\n                        onClick={() => onRetry(task.id)}\n                        className=\"bg-background text-foreground focus-visible:ring-ring min-h-8 shrink-0 rounded-full px-3 text-xs font-medium outline-none focus-visible:ring-2\"\n                      >\n                        {retryLabel}\n                      </button>\n                    ) : null}\n                  </li>\n                ))}\n              </ul>\n            </div>\n          </div>\n        </div>\n        <span aria-live=\"polite\" className=\"sr-only\">\n          {announcement}\n        </span>\n      </>\n    )\n  }\n)\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "status",
    "progress",
    "feedback",
    "overlay"
  ],
  "type": "registry:ui"
}