{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sub-task-hierarchy",
  "title": "Sub-task Hierarchy",
  "description": "A big task broken into nested sub-tasks: progress rolls up through every level, blocked work stands out, and groups open and close without moving the card.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/sub-task-hierarchy/sub-task-hierarchy.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SubTask {\n  id: string;\n  title: string;\n  /** Who it's with. */\n  owner?: string;\n  /** Leaves only. */\n  done?: boolean;\n  /** Leaves only: something is stopping it. */\n  blocked?: boolean;\n  children?: SubTask[];\n}\n\nexport interface SubTaskHierarchyProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  tasks?: SubTask[];\n  /** Ids of the groups that start open. Leave out to open everything. */\n  defaultOpen?: string[];\n  onToggleTask?: (task: SubTask, done: boolean) => void;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst GREEN = \"#27A644\";\nconst ORANGE = \"#FC7840\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst ROW = 40;\nconst VISIBLE_ROWS = 12;\nconst INDENT = 22;\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    border: \"rgba(255,255,255,0.08)\",\n    guide: \"rgba(255,255,255,0.08)\",\n    track: \"rgba(255,255,255,0.1)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    box: \"rgba(255,255,255,0.2)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    guide: \"rgba(8,9,10,0.08)\",\n    track: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    box: \"rgba(8,9,10,0.22)\",\n  },\n};\n\nconst DEFAULT_TASKS: SubTask[] = [\n  {\n    id: \"research\",\n    title: \"Research\",\n    children: [\n      {\n        id: \"r1\",\n        title: \"Read 40 support tickets\",\n        owner: \"Scout\",\n        done: true,\n      },\n      { id: \"r2\", title: \"Compare rival pricing\", owner: \"Scout\", done: true },\n    ],\n  },\n  {\n    id: \"copy\",\n    title: \"Write the page\",\n    children: [\n      { id: \"c1\", title: \"Draft the headline\", owner: \"Aria\", done: true },\n      { id: \"c2\", title: \"Write the plan table\", owner: \"Aria\" },\n      { id: \"c3\", title: \"Legal check\", owner: \"Mira\", blocked: true },\n    ],\n  },\n  {\n    id: \"build\",\n    title: \"Build it\",\n    children: [\n      {\n        id: \"b1\",\n        title: \"Checkout\",\n        children: [\n          { id: \"b1a\", title: \"Add the new plans\", owner: \"Patch\", done: true },\n          { id: \"b1b\", title: \"Test annual billing\", owner: \"Patch\" },\n        ],\n      },\n      { id: \"b2\", title: \"Update the pricing page\", owner: \"Patch\" },\n    ],\n  },\n];\n\ninterface Row {\n  task: SubTask;\n  depth: number;\n}\n\nconst leavesOf = (task: SubTask): SubTask[] =>\n  task.children?.length ? task.children.flatMap(leavesOf) : [task];\n\nconst groupIds = (tasks: SubTask[]): string[] =>\n  tasks.flatMap((t) =>\n    t.children?.length ? [t.id, ...groupIds(t.children)] : [],\n  );\n\nfunction flatten(tasks: SubTask[], open: string[], depth = 0): Row[] {\n  return tasks.flatMap((task) => [\n    { task, depth },\n    ...(task.children?.length && open.includes(task.id)\n      ? flatten(task.children, open, depth + 1)\n      : []),\n  ]);\n}\n\nexport function SubTaskHierarchy({\n  theme = \"dark\",\n  title = \"Launch the new pricing page\",\n  subtitle = \"Split into smaller jobs by Lead.\",\n  tasks = DEFAULT_TASKS,\n  defaultOpen,\n  onToggleTask,\n  className,\n  style,\n  ...rest\n}: SubTaskHierarchyProps) {\n  const c = PALETTES[theme];\n  const allGroups = React.useMemo(() => groupIds(tasks), [tasks]);\n  const [open, setOpen] = React.useState(defaultOpen ?? allGroups);\n  const [flipped, setFlipped] = React.useState<Record<string, boolean>>({});\n\n  const isDone = (t: SubTask) => flipped[t.id] ?? Boolean(t.done);\n  const leaves = tasks.flatMap(leavesOf);\n  const finished = leaves.filter(isDone).length;\n  const blocked = leaves.filter((t) => t.blocked && !isDone(t)).length;\n  const percent = leaves.length\n    ? Math.round((finished / leaves.length) * 100)\n    : 0;\n  const rows = flatten(tasks, open);\n  const allOpen = open.length === allGroups.length;\n\n  const toggleOpen = (id: string) =>\n    setOpen((prev) =>\n      prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id],\n    );\n\n  const toggleDone = (t: SubTask) => {\n    const next = !isDone(t);\n    setFlipped((prev) => ({ ...prev, [t.id]: next }));\n    onToggleTask?.(t, next);\n  };\n\n  return (\n    <section\n      aria-label={title}\n      className={`@container w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      <div className=\"p-5 pb-4 @xl:p-6 @xl:pb-4\">\n        <div className=\"flex items-start justify-between gap-4\">\n          <header className=\"min-w-0\">\n            <h3 className=\"m-0 text-[20px] leading-[26px] font-[590] tracking-[-0.012em]\">\n              {title}\n            </h3>\n            <p\n              className=\"m-0 mt-1 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              {subtitle}\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\">\n              {percent}%\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              {finished} of {leaves.length} done\n            </p>\n          </div>\n        </div>\n        <div className=\"mt-3 flex flex-wrap items-center gap-1.5\">\n          <button\n            type=\"button\"\n            data-all=\"\"\n            onClick={() => setOpen(allOpen ? [] : allGroups)}\n            className={`flex h-7 cursor-pointer items-center justify-center rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n            style={{ width: 92, background: c.chip, color: c.text }}\n          >\n            {allOpen ? \"Collapse all\" : \"Expand all\"}\n          </button>\n          <span\n            aria-live=\"polite\"\n            className=\"flex h-7 items-center gap-2 px-2 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] tabular-nums\"\n            style={{ color: c.sub }}\n          >\n            <svg\n              aria-hidden=\"true\"\n              width=\"8\"\n              height=\"8\"\n              viewBox=\"0 0 8 8\"\n              className=\"block shrink-0\"\n            >\n              <circle cx=\"4\" cy=\"4\" r=\"4\" fill={blocked ? ORANGE : c.faint} />\n            </svg>\n            {blocked} blocked\n          </span>\n        </div>\n      </div>\n\n      {/* A fixed window, so opening and closing groups never changes the card's height. */}\n      <div\n        className=\"overflow-y-auto rounded-b-2xl border-t\"\n        style={{ height: VISIBLE_ROWS * ROW, borderColor: c.border }}\n      >\n        <ul\n          className=\"relative m-0 list-none p-0\"\n          style={{ height: rows.length * ROW }}\n        >\n          {rows.map(({ task, depth }, i) => {\n            const group = Boolean(task.children?.length);\n            const own = group ? leavesOf(task) : [];\n            const ownDone = own.filter(isDone).length;\n            const share = own.length ? ownDone / own.length : 0;\n            const opened = open.includes(task.id);\n            const done = !group && isDone(task);\n            return (\n              <li\n                key={task.id}\n                data-row={task.id}\n                className=\"motion-safe:transition-transform motion-safe:duration-200\"\n                style={{\n                  position: \"absolute\",\n                  top: 0,\n                  left: 0,\n                  right: 0,\n                  height: ROW,\n                  transform: `translateY(${i * ROW}px)`,\n                }}\n              >\n                {Array.from({ length: depth }, (_, d) => (\n                  <span\n                    key={d}\n                    aria-hidden=\"true\"\n                    style={{\n                      position: \"absolute\",\n                      top: 0,\n                      bottom: 0,\n                      width: 1,\n                      left: 29 + d * INDENT,\n                      background: c.guide,\n                    }}\n                  />\n                ))}\n                <div\n                  className=\"flex h-full items-center gap-2.5 pr-5 @xl:pr-6\"\n                  style={{ paddingLeft: 20 + depth * INDENT }}\n                >\n                  {group ? (\n                    <button\n                      type=\"button\"\n                      data-toggle={task.id}\n                      aria-expanded={opened}\n                      aria-label={`${opened ? \"Collapse\" : \"Expand\"} ${task.title}`}\n                      onClick={() => toggleOpen(task.id)}\n                      className={`flex shrink-0 cursor-pointer items-center justify-center rounded border-0 bg-transparent p-0 ${RING}`}\n                      style={{ width: 18, height: 18, color: c.sub }}\n                    >\n                      <svg\n                        aria-hidden=\"true\"\n                        viewBox=\"0 0 16 16\"\n                        width=\"14\"\n                        height=\"14\"\n                        fill=\"none\"\n                        className=\"block motion-safe:transition-transform motion-safe:duration-150\"\n                        style={{ transform: opened ? \"rotate(90deg)\" : \"none\" }}\n                      >\n                        <path\n                          d=\"m6 3.5 4.5 4.5L6 12.5\"\n                          stroke=\"currentColor\"\n                          strokeWidth=\"1.5\"\n                          strokeLinecap=\"round\"\n                          strokeLinejoin=\"round\"\n                        />\n                      </svg>\n                    </button>\n                  ) : (\n                    <button\n                      type=\"button\"\n                      role=\"checkbox\"\n                      data-check={task.id}\n                      aria-checked={done}\n                      aria-label={task.title}\n                      onClick={() => toggleDone(task)}\n                      className={`flex shrink-0 cursor-pointer items-center justify-center border-0 bg-transparent p-0 ${RING}`}\n                      style={{ width: 18, height: 18, borderRadius: 5 }}\n                    >\n                      <svg\n                        aria-hidden=\"true\"\n                        width=\"16\"\n                        height=\"16\"\n                        viewBox=\"0 0 16 16\"\n                        fill=\"none\"\n                        className=\"block\"\n                      >\n                        <rect\n                          x=\"0.75\"\n                          y=\"0.75\"\n                          width=\"14.5\"\n                          height=\"14.5\"\n                          rx=\"4\"\n                          fill={done ? ACCENT : \"transparent\"}\n                          stroke={done ? ACCENT : c.box}\n                          strokeWidth=\"1.5\"\n                        />\n                        {done && (\n                          <path\n                            d=\"m4.5 8.3 2.4 2.4 4.6-5.2\"\n                            stroke=\"#FFFFFF\"\n                            strokeWidth=\"1.6\"\n                            strokeLinecap=\"round\"\n                            strokeLinejoin=\"round\"\n                          />\n                        )}\n                      </svg>\n                    </button>\n                  )}\n                  <span\n                    className=\"min-w-0 flex-1 truncate text-[13.5px] leading-[20px] tracking-[-0.011em]\"\n                    style={{\n                      color: done ? c.faint : group ? c.text : c.soft,\n                      fontWeight: group ? 510 : 400,\n                    }}\n                  >\n                    {task.title}\n                  </span>\n                  {group ? (\n                    <span className=\"flex shrink-0 items-center gap-2.5\">\n                      <svg\n                        aria-hidden=\"true\"\n                        width=\"56\"\n                        height=\"4\"\n                        viewBox=\"0 0 56 4\"\n                        className=\"hidden shrink-0 @xl:block\"\n                      >\n                        <rect width=\"56\" height=\"4\" rx=\"2\" fill={c.track} />\n                        <rect\n                          width={Math.round(56 * share)}\n                          height=\"4\"\n                          rx=\"2\"\n                          fill={share === 1 ? GREEN : ACCENT}\n                        />\n                      </svg>\n                      <span\n                        className=\"text-[12.5px] leading-[18px] tracking-[-0.008em] tabular-nums\"\n                        style={{ color: c.sub }}\n                      >\n                        {ownDone}/{own.length}\n                      </span>\n                    </span>\n                  ) : (\n                    <span\n                      className=\"shrink-0 text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n                      style={{\n                        color: task.blocked && !done ? ORANGE : c.faint,\n                      }}\n                    >\n                      {task.blocked && !done ? \"Blocked\" : task.owner}\n                    </span>\n                  )}\n                </div>\n              </li>\n            );\n          })}\n        </ul>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}