{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table-demo",
  "title": "Data Table Demo",
  "description": "A worked example of Data Table: Typed rows with cells you write, column widths you set or the reader drags, sorting that is one property to switch on, and selection kept in keys rather than positions.",
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/data-table.json"
  ],
  "files": [
    {
      "path": "components/demos/data-table-demo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  DataTable,\n  type Column,\n} from \"@/registry/default/data-table/data-table\"\n\ntype Person = {\n  id: string\n  name: string\n  email: string\n  plan: \"Sketch\" | \"Studio\" | \"Workshop\"\n  seats: number\n  renews: string\n}\n\nconst people: Person[] = [\n  {\n    id: \"1\",\n    name: \"Ada Lovelace\",\n    email: \"ada@analytical.co\",\n    plan: \"Workshop\",\n    seats: 24,\n    renews: \"2026-11-02\",\n  },\n  {\n    id: \"2\",\n    name: \"Grace Hopper\",\n    email: \"grace@compiler.dev\",\n    plan: \"Studio\",\n    seats: 8,\n    renews: \"2026-09-18\",\n  },\n  {\n    id: \"3\",\n    name: \"Radia Perlman\",\n    email: \"radia@spanning.net\",\n    plan: \"Studio\",\n    seats: 12,\n    renews: \"2027-01-24\",\n  },\n  {\n    id: \"4\",\n    name: \"Barbara Liskov\",\n    email: \"barbara@substitute.io\",\n    plan: \"Sketch\",\n    seats: 1,\n    renews: \"2026-08-30\",\n  },\n  {\n    id: \"5\",\n    name: \"Katherine Johnson\",\n    email: \"katherine@trajectory.org\",\n    plan: \"Workshop\",\n    seats: 40,\n    renews: \"2026-12-11\",\n  },\n]\n\n// Plans have an order that is not alphabetical, so the column brings its own.\nconst RANK = { Sketch: 0, Studio: 1, Workshop: 2 }\n\n// Fixed locale and zone, so the server and the browser agree on the text.\nconst renewsOn = new Intl.DateTimeFormat(\"en-GB\", {\n  day: \"numeric\",\n  month: \"short\",\n  year: \"numeric\",\n  timeZone: \"UTC\",\n})\n\nconst columns: Column<Person>[] = [\n  {\n    key: \"name\",\n    header: \"Name\",\n    sort: true,\n    pinned: \"start\",\n    width: \"11rem\",\n    footer: (rows) => `${rows.length} people`,\n    cell: (person) => <span className=\"font-medium\">{person.name}</span>,\n  },\n  {\n    key: \"email\",\n    header: \"Email\",\n    cell: (person) => (\n      <a\n        href={`mailto:${person.email}`}\n        className=\"text-muted-foreground hover:text-foreground underline-offset-4 hover:underline\"\n        onClick={(event) => event.stopPropagation()}\n      >\n        {person.email}\n      </a>\n    ),\n  },\n  {\n    key: \"plan\",\n    header: \"Plan\",\n    width: \"7rem\",\n    sort: (a, b) => RANK[a.plan] - RANK[b.plan],\n    cell: (person) => (\n      <span className=\"border-border inline-flex rounded-full border px-2 py-0.5 text-xs font-semibold\">\n        {person.plan}\n      </span>\n    ),\n  },\n  {\n    key: \"seats\",\n    header: \"Seats\",\n    width: \"5rem\",\n    align: \"end\",\n    sort: true,\n    sortFirst: \"desc\",\n    footer: (rows) => rows.reduce((total, person) => total + person.seats, 0),\n  },\n  {\n    key: \"renews\",\n    header: \"Renews\",\n    width: \"7.5rem\",\n    align: \"end\",\n    sort: true,\n    cell: (person) => renewsOn.format(new Date(person.renews)),\n  },\n]\n\nexport function DataTableDemo() {\n  const [selected, setSelected] = React.useState<string[]>([\"2\"])\n  const [density, setDensity] = React.useState<\"comfortable\" | \"compact\">(\n    \"comfortable\"\n  )\n  const [striped, setStriped] = React.useState(false)\n  const [loading, setLoading] = React.useState(false)\n\n  return (\n    <div className=\"grid w-full max-w-3xl gap-3\">\n      <DataTable\n        rows={people}\n        columns={columns}\n        getKey={(person) => person.id}\n        getLabel={(person) => person.name}\n        label=\"Subscriptions\"\n        defaultSort={{ column: \"name\", direction: \"asc\" }}\n        selected={selected}\n        onSelectionChange={setSelected}\n        density={density}\n        striped={striped}\n        loading={loading}\n        resizable\n      />\n\n      <div className=\"flex flex-wrap items-center gap-2\">\n        <p className=\"text-muted-foreground mr-auto text-xs\">\n          {selected.length} of {people.length} selected. Drag a column edge, or\n          focus one and use the arrow keys.\n        </p>\n\n        <button\n          type=\"button\"\n          aria-pressed={density === \"compact\"}\n          className=\"border-border inline-flex min-h-9 items-center rounded-full border px-3 text-xs font-semibold\"\n          onClick={() =>\n            setDensity((value) =>\n              value === \"compact\" ? \"comfortable\" : \"compact\"\n            )\n          }\n        >\n          {density === \"compact\" ? \"Comfortable\" : \"Compact\"}\n        </button>\n\n        <button\n          type=\"button\"\n          className=\"border-border inline-flex min-h-9 items-center rounded-full border px-3 text-xs font-semibold\"\n          onClick={() => {\n            setLoading(true)\n            window.setTimeout(() => setLoading(false), 1600)\n          }}\n        >\n          Reload\n        </button>\n\n        <button\n          type=\"button\"\n          aria-pressed={striped}\n          className=\"border-border inline-flex min-h-9 items-center rounded-full border px-3 text-xs font-semibold\"\n          onClick={() => setStriped((value) => !value)}\n        >\n          {striped ? \"Plain rows\" : \"Striped rows\"}\n        </button>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}