{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "subtask-05",
  "title": "Nested sub-tasks",
  "description": "Phases that fold over their steps, with a parent box that checks every step and shows when only some are done",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/checkbox.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/subtask/subtask-05.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { ChevronRightIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Checkbox } from '@/registry/ndeko/ui/checkbox';\n\nimport { heightPresenceOf, RollingCount } from './_parts/motion-parts';\nimport { StrikeTitle } from './_parts/subtask-parts';\n\ntype Step = {\n  id: string;\n  title: string;\n  isDone: boolean;\n};\n\ntype Phase = {\n  id: string;\n  title: string;\n  steps: Step[];\n};\n\nconst PHASES: Phase[] = [\n  {\n    id: 'design',\n    title: 'Design the export',\n    steps: [\n      { id: 'd1', title: 'Pick the columns finance needs', isDone: true },\n      { id: 'd2', title: 'Agree on the file name pattern', isDone: true },\n    ],\n  },\n  {\n    id: 'build',\n    title: 'Build the export',\n    steps: [\n      { id: 'b1', title: 'CSV writer with escaped fields', isDone: true },\n      { id: 'b2', title: 'Totals row at the end', isDone: false },\n      { id: 'b3', title: 'Dates in the account time zone', isDone: false },\n    ],\n  },\n  {\n    id: 'ship',\n    title: 'Ship it',\n    steps: [\n      {\n        id: 's1',\n        title: 'Download button on the invoices page',\n        isDone: false,\n      },\n      { id: 's2', title: 'Note in the changelog', isDone: false },\n    ],\n  },\n];\n\nfunction doneCountOf(steps: Step[]) {\n  return steps.filter((step) => step.isDone).length;\n}\n\nfunction withStep(phase: Phase, stepId: string, isDone: boolean): Phase {\n  const steps = phase.steps.map((step) => {\n    if (step.id !== stepId) {\n      return step;\n    }\n    return { ...step, isDone };\n  });\n  return { ...phase, steps };\n}\n\nfunction withAllSteps(phase: Phase, isDone: boolean): Phase {\n  const steps = phase.steps.map((step) => ({ ...step, isDone }));\n  return { ...phase, steps };\n}\n\nfunction StepRow({\n  step,\n  onChange,\n}: {\n  step: Step;\n  onChange: (isDone: boolean) => void;\n}) {\n  return (\n    <li>\n      <label className='hover:bg-foreground/[0.03] flex h-8 cursor-pointer items-center gap-3 rounded-lg ps-9 pe-2'>\n        <Checkbox checked={step.isDone} onCheckedChange={onChange} />\n        <StrikeTitle title={step.title} isDone={step.isDone} />\n      </label>\n    </li>\n  );\n}\n\nfunction PhaseBlock({\n  phase,\n  onChange,\n}: {\n  phase: Phase;\n  onChange: (phase: Phase) => void;\n}) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [isOpen, setIsOpen] = useState(true);\n  const stepsId = useId();\n  const doneCount = doneCountOf(phase.steps);\n  const total = phase.steps.length;\n  const isAllDone = doneCount === total;\n  const isPartlyDone = doneCount > 0 && !isAllDone;\n\n  return (\n    <li>\n      <div className='flex h-9 items-center gap-1 rounded-lg pe-2'>\n        <button\n          type='button'\n          aria-expanded={isOpen}\n          aria-controls={stepsId}\n          aria-label={`Show the steps of ${phase.title}`}\n          onClick={() => setIsOpen((current) => !current)}\n          className='text-muted-foreground hover:text-foreground focus-visible:ring-ring/25 inline-flex size-7 shrink-0 cursor-pointer items-center justify-center rounded-md outline-none focus-visible:ring-[3px]'\n        >\n          <ChevronRightIcon\n            className={cn(\n              'size-3.5 transition-transform duration-200 ease-(--ease-out-strong)',\n              isOpen && 'rotate-90'\n            )}\n          />\n        </button>\n        <label className='flex min-w-0 flex-1 cursor-pointer items-center gap-3 self-stretch'>\n          <Checkbox\n            checked={isAllDone}\n            indeterminate={isPartlyDone}\n            onCheckedChange={(isDone) => onChange(withAllSteps(phase, isDone))}\n          />\n          <StrikeTitle\n            title={phase.title}\n            isDone={isAllDone}\n            className='font-medium'\n          />\n        </label>\n        <span className='keycap-3d text-muted-foreground inline-flex h-5 shrink-0 items-center rounded-[5px] px-1.5 text-[11px] font-medium tabular-nums'>\n          <RollingCount value={doneCount} />/{total}\n        </span>\n      </div>\n      <div id={stepsId}>\n        <AnimatePresence initial={false}>\n          {isOpen && (\n            <motion.ul\n              {...heightPresenceOf(shouldReduceMotion)}\n              className='overflow-hidden'\n            >\n              {phase.steps.map((step) => (\n                <StepRow\n                  key={step.id}\n                  step={step}\n                  onChange={(isDone) =>\n                    onChange(withStep(phase, step.id, isDone))\n                  }\n                />\n              ))}\n            </motion.ul>\n          )}\n        </AnimatePresence>\n      </div>\n    </li>\n  );\n}\n\nfunction replaced(phases: Phase[], next: Phase) {\n  return phases.map((phase) => {\n    if (phase.id !== next.id) {\n      return phase;\n    }\n    return next;\n  });\n}\n\nexport default function Subtask05() {\n  const [phases, setPhases] = useState(PHASES);\n  const allSteps = phases.flatMap((phase) => phase.steps);\n  const doneCount = doneCountOf(allSteps);\n\n  return (\n    <section aria-label='Nested sub-tasks' className='w-full max-w-md'>\n      <header className='flex items-baseline justify-between gap-3 px-2'>\n        <h3 className='text-sm font-medium'>Sub-tasks</h3>\n        <p className='text-muted-foreground text-xs'>\n          <RollingCount value={doneCount} /> of {allSteps.length} steps done\n        </p>\n      </header>\n      <ul className='mt-2 flex flex-col gap-1'>\n        {phases.map((phase) => (\n          <PhaseBlock\n            key={phase.id}\n            phase={phase}\n            onChange={(next) => setPhases((current) => replaced(current, next))}\n          />\n        ))}\n      </ul>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/subtask/subtask-05.tsx"
    },
    {
      "path": "registry/ndeko/components/subtask/_parts/motion-parts.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type MotionProps,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { cn } from '@/registry/ndeko/lib/utils';\n\nexport const EASE_OUT_STRONG: [number, number, number, number] = [\n  0.23, 1, 0.32, 1,\n];\n\nexport const ENTER: Transition = { duration: 0.2, ease: EASE_OUT_STRONG };\n\nexport const EXIT: Transition = { duration: 0.15, ease: EASE_OUT_STRONG };\n\nexport type PresenceProps = Pick<\n  MotionProps,\n  'initial' | 'animate' | 'exit' | 'transition'\n>;\n\nconst HEIGHT_PRESENCE: PresenceProps = {\n  initial: { height: 0, opacity: 0 },\n  animate: { height: 'auto', opacity: 1 },\n  exit: { height: 0, opacity: 0, transition: EXIT },\n  transition: ENTER,\n};\n\nconst FADE_PRESENCE: PresenceProps = {\n  initial: { opacity: 0 },\n  animate: { opacity: 1 },\n  exit: { opacity: 0, transition: EXIT },\n  transition: ENTER,\n};\n\n/** Rows that arrive or leave a list: their height opens and closes so the rows after them slide. */\nexport function heightPresenceOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_PRESENCE;\n  }\n  return HEIGHT_PRESENCE;\n}\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: EASE_OUT_STRONG };\n\nconst SWAP_VARIANTS: Variants = {\n  hidden: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  shown: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n};\n\nconst FADE_VARIANTS: Variants = {\n  hidden: { opacity: 0 },\n  shown: { opacity: 1 },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\ntype SwapProps = {\n  swapKey: string;\n  children: React.ReactNode;\n  className?: string;\n};\n\n/** An icon or a short label that becomes another one in place. */\nexport function Swap({ swapKey, children, className }: SwapProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n\n  return (\n    <span className={cn('relative inline-flex', className)}>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={swapKey}\n          variants={swapVariantsOf(shouldReduceMotion)}\n          initial='hidden'\n          animate='shown'\n          exit='hidden'\n          transition={SWAP_TRANSITION}\n          className='inline-flex'\n        >\n          {children}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nconst COUNT_SLIDE = 8;\n\nconst COUNT_TRANSITION: Transition = { duration: 0.18, ease: EASE_OUT_STRONG };\n\nconst COUNT_VARIANTS: Variants = {\n  enter: (offset: number) => ({ y: offset, opacity: 0 }),\n  center: { y: 0, opacity: 1 },\n  leave: (offset: number) => ({ y: -offset, opacity: 0 }),\n};\n\nfunction directionOf(previous: number, next: number) {\n  if (next < previous) {\n    return -1;\n  }\n  return 1;\n}\n\nfunction offsetOf(direction: number, shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return 0;\n  }\n  return direction * COUNT_SLIDE;\n}\n\ntype RollingCountProps = {\n  value: number;\n  /** Writes the value, such as a duration; the digits still roll on the number. */\n  format?: (value: number) => string;\n  className?: string;\n};\n\nfunction plainNumber(value: number) {\n  return String(value);\n}\n\n/** A figure the person just changed: the new digits slide in from the side of the change. */\nexport function RollingCount({\n  value,\n  format = plainNumber,\n  className,\n}: RollingCountProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const [previous, setPrevious] = useState(value);\n  const [direction, setDirection] = useState(1);\n\n  if (previous !== value) {\n    setDirection(directionOf(previous, value));\n    setPrevious(value);\n  }\n\n  const offset = offsetOf(direction, shouldReduceMotion);\n\n  return (\n    <span\n      className={cn(\n        'relative inline-flex overflow-hidden tabular-nums',\n        className\n      )}\n    >\n      <AnimatePresence mode='popLayout' initial={false} custom={offset}>\n        <motion.span\n          key={value}\n          custom={offset}\n          variants={COUNT_VARIANTS}\n          initial='enter'\n          animate='center'\n          exit='leave'\n          transition={COUNT_TRANSITION}\n          className='inline-block'\n        >\n          {format(value)}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/subtask/_parts/motion-parts.tsx"
    },
    {
      "path": "registry/ndeko/components/subtask/_parts/people.ts",
      "content": "export type Person = {\n  id: string;\n  name: string;\n  firstName: string;\n};\n\nexport const CURRENT_USER_ID = 'amara';\n\nexport const PEOPLE: Person[] = [\n  {\n    id: 'amara',\n    name: 'Amara Okafor',\n    firstName: 'Amara',\n  },\n  {\n    id: 'leo',\n    name: 'Léo Martin',\n    firstName: 'Léo',\n  },\n  {\n    id: 'sana',\n    name: 'Sana Iqbal',\n    firstName: 'Sana',\n  },\n  {\n    id: 'tomas',\n    name: 'Tomás Rivera',\n    firstName: 'Tomás',\n  },\n  {\n    id: 'mei',\n    name: 'Mei Lin',\n    firstName: 'Mei',\n  },\n  {\n    id: 'jonah',\n    name: 'Jonah Brandt',\n    firstName: 'Jonah',\n  },\n];\n\nexport function personOf(id: string) {\n  const found = PEOPLE.find((person) => person.id === id);\n  if (found) {\n    return found;\n  }\n  return PEOPLE[0];\n}\n\nexport function isCurrentUser(id: string) {\n  return id === CURRENT_USER_ID;\n}\n\nexport function actorNameOf(id: string) {\n  if (isCurrentUser(id)) {\n    return 'You';\n  }\n  return personOf(id).name;\n}\n",
      "type": "registry:component",
      "target": "components/subtask/_parts/people.ts"
    },
    {
      "path": "registry/ndeko/components/subtask/_parts/subtask-parts.tsx",
      "content": "'use client';\n\nimport { CheckIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\n\nimport { Swap } from './motion-parts';\nimport type { Person } from './people';\n\nexport type StatusId =\n  'backlog' | 'todo' | 'in_progress' | 'in_review' | 'done';\n\nexport const STATUSES: { id: StatusId; name: string; color: string }[] = [\n  { id: 'backlog', name: 'Backlog', color: 'var(--muted-foreground)' },\n  { id: 'todo', name: 'Todo', color: 'var(--muted-foreground)' },\n  { id: 'in_progress', name: 'In progress', color: 'var(--warning)' },\n  { id: 'in_review', name: 'In review', color: 'var(--primary)' },\n  { id: 'done', name: 'Done', color: 'var(--success)' },\n];\n\nexport function statusOf(id: StatusId) {\n  const found = STATUSES.find((status) => status.id === id);\n  if (found) {\n    return found;\n  }\n  return STATUSES[0];\n}\n\nexport function isStatusId(value: unknown): value is StatusId {\n  return STATUSES.some((status) => status.id === value);\n}\n\nconst PIE_RADIUS = 2;\n\nconst PIE_CIRCUMFERENCE = 2 * Math.PI * PIE_RADIUS;\n\nfunction StartedShape({ share }: { share: number }) {\n  const filled = share * PIE_CIRCUMFERENCE;\n  return (\n    <>\n      <circle cx='7' cy='7' r='6' stroke='currentColor' strokeWidth='1.5' />\n      <circle\n        cx='7'\n        cy='7'\n        r={PIE_RADIUS}\n        stroke='currentColor'\n        strokeWidth={PIE_RADIUS * 2}\n        strokeDasharray={`${filled} ${PIE_CIRCUMFERENCE}`}\n        transform='rotate(-90 7 7)'\n      />\n    </>\n  );\n}\n\nfunction statusShapeOf(status: StatusId) {\n  if (status === 'backlog') {\n    return (\n      <circle\n        cx='7'\n        cy='7'\n        r='6'\n        stroke='currentColor'\n        strokeWidth='1.5'\n        strokeDasharray='1.6 1.9'\n      />\n    );\n  }\n  if (status === 'todo') {\n    return (\n      <circle cx='7' cy='7' r='6' stroke='currentColor' strokeWidth='1.5' />\n    );\n  }\n  if (status === 'in_progress') {\n    return <StartedShape share={0.5} />;\n  }\n  if (status === 'in_review') {\n    return <StartedShape share={0.75} />;\n  }\n  return (\n    <>\n      <circle cx='7' cy='7' r='7' fill='currentColor' />\n      <path\n        d='M4.4 7.2 6.2 9l3.4-3.8'\n        stroke='var(--card)'\n        strokeWidth='1.6'\n        strokeLinecap='round'\n        strokeLinejoin='round'\n      />\n    </>\n  );\n}\n\nexport function StatusGlyph({\n  status,\n  className,\n}: {\n  status: StatusId;\n  className?: string;\n}) {\n  const glyphStyle = { color: statusOf(status).color } as React.CSSProperties;\n  return (\n    <svg\n      viewBox='0 0 14 14'\n      fill='none'\n      aria-hidden='true'\n      style={glyphStyle}\n      className={cn('size-3.5 shrink-0', className)}\n    >\n      {statusShapeOf(status)}\n    </svg>\n  );\n}\n\nexport function PersonAvatar({\n  person,\n  className,\n}: {\n  person: Person;\n  className?: string;\n}) {\n  return (\n    <Avatar className={cn('size-5 text-[9px]', className)} seed={person.name} />\n  );\n}\n\nconst RING_RADIUS = 6.5;\n\nconst RING_LENGTH = 2 * Math.PI * RING_RADIUS;\n\nfunction shareOf(done: number, total: number) {\n  if (total === 0) {\n    return 0;\n  }\n  return done / total;\n}\n\nfunction ringKeyOf(isComplete: boolean) {\n  if (isComplete) {\n    return 'complete';\n  }\n  return 'ring';\n}\n\n/** The share of sub-tasks done; the arc travels on each check and becomes a check mark once all are done. */\nexport function ProgressRing({\n  done,\n  total,\n  className,\n}: {\n  done: number;\n  total: number;\n  className?: string;\n}) {\n  const share = shareOf(done, total);\n  const isComplete = total > 0 && done === total;\n  const dashOffset = RING_LENGTH * (1 - share);\n\n  return (\n    <Swap swapKey={ringKeyOf(isComplete)} className={className}>\n      {isComplete && (\n        <span className='bg-success/15 text-success-foreground flex size-4 items-center justify-center rounded-full'>\n          <CheckIcon strokeWidth={3} className='size-2.5' />\n        </span>\n      )}\n      {!isComplete && (\n        <svg\n          viewBox='0 0 16 16'\n          aria-hidden='true'\n          className='size-4 -rotate-90'\n        >\n          <circle\n            cx='8'\n            cy='8'\n            r={RING_RADIUS}\n            fill='none'\n            strokeWidth='2'\n            className='stroke-foreground/10'\n          />\n          <circle\n            cx='8'\n            cy='8'\n            r={RING_RADIUS}\n            fill='none'\n            strokeWidth='2'\n            strokeLinecap='round'\n            strokeDasharray={RING_LENGTH}\n            strokeDashoffset={dashOffset}\n            className='stroke-primary transition-[stroke-dashoffset] duration-300 ease-(--ease-out-strong)'\n          />\n        </svg>\n      )}\n    </Swap>\n  );\n}\n\n/** A title that gets struck through from left to right when its sub-task is done. */\nexport function StrikeTitle({\n  title,\n  isDone,\n  className,\n}: {\n  title: string;\n  isDone: boolean;\n  className?: string;\n}) {\n  return (\n    <span\n      className={cn(\n        'relative min-w-0 truncate text-[13px] transition-colors duration-200',\n        isDone && 'text-muted-foreground',\n        className\n      )}\n    >\n      {title}\n      <span\n        aria-hidden='true'\n        className={cn(\n          'bg-foreground/35 pointer-events-none absolute inset-x-0 top-1/2 h-px origin-left scale-x-0 transition-transform duration-200 ease-(--ease-out-strong)',\n          isDone && 'scale-x-100'\n        )}\n      />\n    </span>\n  );\n}\n\n/** One segment per sub-task, filled from the left when it is done. */\nexport function SegmentMeter({\n  states,\n  className,\n}: {\n  states: boolean[];\n  className?: string;\n}) {\n  return (\n    <span aria-hidden='true' className={cn('flex gap-0.5', className)}>\n      {states.map((isDone, index) => (\n        <span\n          key={index}\n          className='bg-foreground/10 relative h-1.5 min-w-1 flex-1 overflow-hidden rounded-full'\n        >\n          <span\n            className={cn(\n              'bg-success absolute inset-0 origin-left scale-x-0 rounded-full transition-transform duration-200 ease-(--ease-out-strong)',\n              isDone && 'scale-x-100'\n            )}\n          />\n        </span>\n      ))}\n    </span>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/subtask/_parts/subtask-parts.tsx"
    }
  ],
  "categories": [
    "components",
    "subtask"
  ],
  "type": "registry:component"
}