{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"checklist-cell","type":"registry:ui","title":"Checklist Cell","description":"A checklist card whose ticks draw in, labels strike through, finished items glide to the bottom and a progress ring fills toward a celebratory check.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/checklist-cell.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type FormEvent } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { Check, Plus, Sparkles } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ChecklistItem {\n  id: string;\n  label: string;\n  done?: boolean;\n  /** Small tag on the right, e.g. \"Today\". */\n  tag?: string;\n}\n\nexport interface ChecklistCellProps {\n  title?: string;\n  /** Initial items (uncontrolled). */\n  defaultItems?: ChecklistItem[];\n  /** Fired with the full list after every change. */\n  onChange?: (items: ChecklistItem[]) => void;\n  /** Show the \"Add a task\" field. */\n  allowAdd?: boolean;\n  /** Move completed items to the bottom (after the strike-through plays). */\n  sinkCompleted?: boolean;\n  className?: string;\n}\n\nconst DEFAULT_ITEMS: ChecklistItem[] = [\n  { id: \"notes\", label: \"Write release notes\", tag: \"Today\" },\n  { id: \"qa\", label: \"QA pass on staging\", done: true },\n  { id: \"pricing\", label: \"Update the pricing page\" },\n  { id: \"video\", label: \"Record the demo video\", tag: \"Fri\" },\n  { id: \"beta\", label: \"Email beta users\", done: true },\n  { id: \"tweet\", label: \"Schedule the launch thread\" },\n];\n\nconst R = 22;\nconst CIRC = 2 * Math.PI * R;\n\n/** Open items keep their original order; done items sink below them. */\nconst sortIds = (list: ChecklistItem[]) =>\n  [...list.filter((i) => !i.done), ...list.filter((i) => i.done)].map(\n    (i) => i.id,\n  );\n\nexport function ChecklistCell({\n  title = \"Launch checklist\",\n  defaultItems = DEFAULT_ITEMS,\n  onChange,\n  allowAdd = true,\n  sinkCompleted = true,\n  className,\n}: ChecklistCellProps) {\n  const id = useId();\n  const reduce = useReducedMotion();\n  const [items, setItems] = useState(defaultItems);\n  const [order, setOrder] = useState(() =>\n    sinkCompleted ? sortIds(defaultItems) : defaultItems.map((i) => i.id),\n  );\n  const [draft, setDraft] = useState(\"\");\n  const [pulse, setPulse] = useState<string | null>(null);\n  const timer = useRef<ReturnType<typeof setTimeout>>(undefined);\n  useEffect(() => () => clearTimeout(timer.current), []);\n\n  const commit = (next: ChecklistItem[], delay: number) => {\n    setItems(next);\n    onChange?.(next);\n    clearTimeout(timer.current);\n    const apply = () =>\n      setOrder(sinkCompleted ? sortIds(next) : next.map((i) => i.id));\n    if (delay && !reduce) timer.current = setTimeout(apply, delay);\n    else apply();\n  };\n\n  const toggle = (itemId: string) => {\n    setPulse(itemId);\n    commit(\n      items.map((i) => (i.id === itemId ? { ...i, done: !i.done } : i)),\n      550,\n    );\n  };\n\n  const add = (e: FormEvent) => {\n    e.preventDefault();\n    const label = draft.trim();\n    if (!label) return;\n    setDraft(\"\");\n    commit([{ id: `add-${items.length}`, label }, ...items], 0); // items only grow, so the length is a unique id\n  };\n\n  const byId = new Map(items.map((i) => [i.id, i]));\n  const rows = !sinkCompleted\n    ? items\n    : order.map((k) => byId.get(k)).filter((i): i is ChecklistItem => !!i);\n  const done = items.filter((i) => i.done).length;\n  const pct = items.length ? done / items.length : 0;\n  const complete = items.length > 0 && done === items.length;\n\n  return (\n    <div\n      className={cn(\n        \"w-full max-w-sm overflow-hidden rounded-3xl border border-border bg-card text-card-foreground shadow-2xl shadow-black/20\",\n        className,\n      )}\n    >\n      <div className=\"flex items-center gap-4 p-5 pb-4\">\n        <div className=\"min-w-0 flex-1\">\n          <h3\n            id={`${id}-t`}\n            className=\"truncate text-lg font-semibold tracking-tight\"\n          >\n            {title}\n          </h3>\n          <AnimatePresence mode=\"wait\" initial={false}>\n            <motion.p\n              key={complete ? \"all\" : done}\n              initial={{ opacity: 0, y: 6 }}\n              animate={{ opacity: 1, y: 0 }}\n              exit={{ opacity: 0, y: -6 }}\n              transition={{ duration: 0.18 }}\n              className=\"text-sm text-muted-foreground\"\n            >\n              {complete ? (\n                <span className=\"inline-flex items-center gap-1.5 font-medium text-foreground\">\n                  <Sparkles className=\"size-3.5 text-primary\" aria-hidden /> All\n                  done. Ship it!\n                </span>\n              ) : (\n                `${done} of ${items.length} completed`\n              )}\n            </motion.p>\n          </AnimatePresence>\n        </div>\n\n        {/* progress ring */}\n        <div\n          role=\"progressbar\"\n          aria-label={`${title} progress`}\n          aria-valuemin={0}\n          aria-valuemax={100}\n          aria-valuenow={Math.round(pct * 100)}\n          className=\"relative grid size-14 shrink-0 place-items-center\"\n        >\n          <svg\n            viewBox=\"0 0 52 52\"\n            className=\"absolute inset-0 -rotate-90\"\n            aria-hidden\n          >\n            <circle\n              cx=\"26\"\n              cy=\"26\"\n              r={R}\n              fill=\"none\"\n              strokeWidth=\"4.5\"\n              className=\"stroke-muted\"\n            />\n            <motion.circle\n              cx=\"26\"\n              cy=\"26\"\n              r={R}\n              fill=\"none\"\n              strokeWidth=\"4.5\"\n              strokeLinecap=\"round\"\n              strokeDasharray={CIRC}\n              className=\"stroke-primary\"\n              initial={false}\n              animate={{ strokeDashoffset: CIRC * (1 - pct) }}\n              transition={{ type: \"spring\", stiffness: 120, damping: 20 }}\n            />\n          </svg>\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            {complete ? (\n              <motion.span\n                key=\"check\"\n                initial={reduce ? false : { scale: 0, rotate: -60 }}\n                animate={{ scale: 1, rotate: 0 }}\n                exit={{ scale: 0 }}\n                transition={{ type: \"spring\", stiffness: 400, damping: 15 }}\n                className=\"grid size-9 place-items-center rounded-full bg-primary text-primary-foreground\"\n              >\n                <Check className=\"size-5\" strokeWidth={3} aria-hidden />\n              </motion.span>\n            ) : (\n              <motion.span\n                key=\"pct\"\n                initial={{ scale: 0.6, opacity: 0 }}\n                animate={{ scale: 1, opacity: 1 }}\n                exit={{ scale: 0.6, opacity: 0 }}\n                className=\"text-xs font-semibold tabular-nums\"\n              >\n                {Math.round(pct * 100)}%\n              </motion.span>\n            )}\n          </AnimatePresence>\n        </div>\n      </div>\n\n      {allowAdd && (\n        <form\n          onSubmit={add}\n          className=\"mx-5 mb-2 flex items-center gap-2 rounded-xl border border-dashed border-border px-3 transition-colors focus-within:border-ring focus-within:border-solid\"\n        >\n          <Plus className=\"size-4 shrink-0 text-muted-foreground\" aria-hidden />\n          <label htmlFor={`${id}-add`} className=\"sr-only\">\n            Add a task\n          </label>\n          <input\n            id={`${id}-add`}\n            value={draft}\n            onChange={(e) => setDraft(e.target.value)}\n            placeholder=\"Add a task and press Enter\"\n            maxLength={80}\n            className=\"h-10 min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground\"\n          />\n        </form>\n      )}\n\n      <ul aria-labelledby={`${id}-t`} className=\"grid gap-0.5 px-2.5 pb-3\">\n        <AnimatePresence initial={false}>\n          {rows.map((item) => {\n            const inputId = `${id}-${item.id}`;\n            return (\n              <motion.li\n                key={item.id}\n                layout={reduce ? false : \"position\"}\n                initial={{ opacity: 0, height: 0 }}\n                animate={{ opacity: 1, height: \"auto\" }}\n                exit={{ opacity: 0, height: 0 }}\n                transition={{\n                  layout: { type: \"spring\", stiffness: 380, damping: 34 },\n                  duration: 0.2,\n                }}\n              >\n                <label\n                  htmlFor={inputId}\n                  className=\"group flex cursor-pointer items-center gap-3 rounded-xl px-2.5 py-2.5 transition-colors select-none hover:bg-muted/70 has-focus-visible:bg-muted/70 has-focus-visible:ring-2 has-focus-visible:ring-ring/50\"\n                >\n                  <input\n                    id={inputId}\n                    type=\"checkbox\"\n                    checked={!!item.done}\n                    onChange={() => toggle(item.id)}\n                    className=\"peer sr-only\"\n                  />\n                  <span\n                    aria-hidden\n                    className={cn(\n                      \"relative grid size-5 shrink-0 place-items-center rounded-full border-[1.5px] transition-[background-color,border-color,scale] duration-200 group-active:scale-90\",\n                      item.done\n                        ? \"border-primary bg-primary\"\n                        : \"border-muted-foreground/50 group-hover:border-foreground/70\",\n                    )}\n                  >\n                    <svg\n                      viewBox=\"0 0 24 24\"\n                      className=\"size-3 text-primary-foreground\"\n                      fill=\"none\"\n                      stroke=\"currentColor\"\n                      strokeWidth={3.5}\n                      strokeLinecap=\"round\"\n                      strokeLinejoin=\"round\"\n                    >\n                      <motion.path\n                        d=\"M5 12.5l4.5 4.5L19 7.5\"\n                        initial={false}\n                        animate={{ pathLength: item.done ? 1 : 0 }}\n                        transition={{\n                          duration: reduce ? 0 : 0.25,\n                          delay: item.done ? 0.05 : 0,\n                        }}\n                      />\n                    </svg>\n                    {/* ring pulse on completion */}\n                    {item.done && pulse === item.id && !reduce && (\n                      <motion.span\n                        className=\"absolute inset-0 rounded-full border-2 border-primary\"\n                        initial={{ scale: 1, opacity: 0.7 }}\n                        animate={{ scale: 2, opacity: 0 }}\n                        transition={{ duration: 0.5 }}\n                      />\n                    )}\n                  </span>\n                  <span className=\"min-w-0 flex-1\">\n                    <span className=\"relative inline-block max-w-full align-middle\">\n                      <span\n                        className={cn(\n                          \"block truncate text-sm transition-colors duration-300\",\n                          item.done\n                            ? \"text-muted-foreground\"\n                            : \"text-foreground\",\n                        )}\n                      >\n                        {item.label}\n                      </span>\n                      <motion.span\n                        aria-hidden\n                        className=\"absolute top-1/2 left-0 h-[1.5px] w-full origin-left rounded-full bg-muted-foreground\"\n                        initial={false}\n                        animate={{ scaleX: item.done ? 1 : 0 }}\n                        transition={{\n                          duration: reduce ? 0 : 0.35,\n                          ease: [0.65, 0, 0.35, 1],\n                        }}\n                      />\n                    </span>\n                  </span>\n                  {item.tag && (\n                    <span\n                      className={cn(\n                        \"shrink-0 rounded-full px-2 py-0.5 text-[11px] font-medium transition-opacity\",\n                        item.done\n                          ? \"bg-muted text-muted-foreground opacity-60\"\n                          : \"bg-primary/15 text-foreground\",\n                      )}\n                    >\n                      {item.tag}\n                    </span>\n                  )}\n                </label>\n              </motion.li>\n            );\n          })}\n        </AnimatePresence>\n      </ul>\n    </div>\n  );\n}\n"}]}