{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "todo-list",
  "type": "registry:ui",
  "title": "Todo list",
  "description": "Content-sized task rows with completion checks in your primary color, an animated strike-through, and spring reordering that moves finished tasks to the bottom.",
  "author": "Aditya Ojha <https://akoder.xyz>",
  "categories": [
    "tasks",
    "animation",
    "interactive",
    "accessibility"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [],
  "meta": {
    "docs": "https://akoder.xyz/components/todo-list",
    "source": "https://github.com/AdityaKodez/adityaojha/blob/main/components/ui/todo-list.tsx"
  },
  "files": [
    {
      "path": "components/ui/todo-list.tsx",
      "content": "\"use client\";\n\nimport { Check } from \"lucide-react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { useState, type CSSProperties } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface TodoItem {\n  /** A unique, stable key that stays the same when the task moves. */\n  id: string;\n  title: string;\n  completed?: boolean;\n}\n\nexport interface TodoListProps {\n  /** Controlled tasks. Pair with onItemsChange to update them. */\n  items?: TodoItem[];\n  /** Initial tasks when the list manages its own state. */\n  defaultItems?: TodoItem[];\n  onItemsChange?: (items: TodoItem[]) => void;\n  /** Color of the completed checkbox. Accepts any CSS color. */\n  accentColor?: string;\n  disabled?: boolean;\n  /** Accessible name for the list. */\n  label?: string;\n  emptyMessage?: string;\n  className?: string;\n}\n\n/** Content-sized tasks that settle beneath unfinished work when completed. */\nexport function TodoList({\n  items,\n  defaultItems = [],\n  onItemsChange,\n  accentColor = \"var(--primary, oklch(0.488 0.243 264.376))\",\n  disabled = false,\n  label = \"Todo list\",\n  emptyMessage = \"No tasks yet.\",\n  className,\n}: TodoListProps) {\n  const [internalItems, setInternalItems] = useState(defaultItems);\n  const reduceMotion = useReducedMotion();\n  const tasks = items ?? internalItems;\n  const ids = new Set<string>();\n\n  for (const task of tasks) {\n    if (!task.id.trim() || ids.has(task.id) || !task.title.trim()) {\n      throw new Error(\"TodoList requires unique, non-empty ids and non-empty titles.\");\n    }\n    ids.add(task.id);\n  }\n\n  const orderedTasks = [\n    ...tasks.filter((task) => !task.completed),\n    ...tasks.filter((task) => task.completed),\n  ];\n  const unavailable = disabled || (items !== undefined && !onItemsChange);\n  const spring = reduceMotion\n    ? { duration: 0 }\n    : { type: \"spring\" as const, stiffness: 420, damping: 32 };\n\n  function toggleTask(id: string) {\n    if (unavailable) return;\n\n    const nextItems = tasks.map((task) =>\n      task.id === id ? { ...task, completed: !task.completed } : task,\n    );\n    if (items === undefined) setInternalItems(nextItems);\n    onItemsChange?.(nextItems);\n  }\n\n  if (tasks.length === 0) {\n    return (\n      <p className={cn(\"text-sm text-muted-foreground\", className)} role=\"status\">\n        {emptyMessage}\n      </p>\n    );\n  }\n\n  return (\n    <ul\n      aria-label={label}\n      className={cn(\"m-0 flex w-fit max-w-full list-none flex-col items-start gap-2.5 p-0\", className)}\n      style={{ \"--todo-accent\": accentColor } as CSSProperties}\n    >\n      {orderedTasks.map((task) => {\n        const completed = Boolean(task.completed);\n\n        return (\n          <motion.li\n            key={task.id}\n            layout={reduceMotion ? false : \"position\"}\n            initial={false}\n            transition={spring}\n            className=\"relative max-w-full\"\n            style={{ zIndex: completed ? 1 : 0 }}\n          >\n            <motion.button\n              type=\"button\"\n              role=\"checkbox\"\n              aria-checked={completed}\n              disabled={unavailable}\n              onClick={() => toggleTask(task.id)}\n              whileTap={unavailable || reduceMotion ? undefined : { scale: 0.98 }}\n              transition={spring}\n              className=\"flex min-h-[54px] max-w-full cursor-pointer items-center gap-3 rounded-2xl bg-card px-3 py-3 text-left text-base font-normal leading-6 text-card-foreground shadow-[0_1px_2px_rgb(0_0_0/10%)] outline-none focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-ring disabled:cursor-not-allowed disabled:opacity-50\"\n            >\n              <span\n                aria-hidden=\"true\"\n                className={cn(\n                  \"flex size-7 shrink-0 items-center justify-center rounded-full\",\n                  completed\n                    ? \"bg-[var(--todo-accent)] text-[color:var(--primary-foreground,white)]\"\n                    : \"ring-1 ring-inset ring-border/70\",\n                )}\n              >\n                <motion.span\n                  initial={false}\n                  animate={{ opacity: completed ? 1 : 0, scale: completed ? 1 : 0.5 }}\n                  transition={spring}\n                  className=\"flex\"\n                >\n                  <Check className=\"size-4\" strokeWidth={2.5} />\n                </motion.span>\n              </span>\n              <span\n                className={cn(\n                  \"relative min-w-0 break-words transition-colors duration-200 motion-reduce:transition-none\",\n                  completed && \"text-muted-foreground\",\n                )}\n              >\n                {task.title}\n                <motion.span\n                  aria-hidden=\"true\"\n                  initial={false}\n                  animate={{ scaleX: completed ? 1 : 0 }}\n                  transition={reduceMotion ? { duration: 0 } : { duration: 0.2, ease: \"easeOut\" }}\n                  className=\"pointer-events-none absolute inset-0 origin-left text-transparent line-through decoration-muted-foreground\"\n                >\n                  {task.title}\n                </motion.span>\n              </span>\n            </motion.button>\n          </motion.li>\n        );\n      })}\n    </ul>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "docs": "## Installation\n\n```bash\nnpx shadcn add @akoder/todo-list\n```\n\n## Usage\n\n```tsx\nimport { TodoList } from \"@/components/ui/todo-list\";\n\nconst tasks = [\n  { id: \"user-testing\", title: \"Organize a user testing session\" },\n  { id: \"client-review\", title: \"Prepare designs for client review\" },\n  { id: \"meditation\", title: \"15-minute meditation\" },\n];\n\nexport function Tasks() {\n  return <TodoList defaultItems={tasks} />;\n}\n```\n\nClick a task to complete or reopen it. Completed tasks spring to the bottom while the checkmark and strike-through animate. Use `items` and `onItemsChange` for controlled state, or `defaultItems` for local state. Tasks need unique, stable ids and non-empty titles. Completed checkboxes use your primary color. `accentColor` customizes the fill, and `disabled` prevents changes. Reduced motion removes movement. See https://akoder.xyz/components/todo-list for the complete props reference."
}