{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-view",
  "title": "Data View",
  "description": "A collection view that switches between a card grid and a list, with every item gliding to its new place; a sort menu reorders them with the same motion, and a pager steps through pages.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/data-view/data-view.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, LayoutGroup, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface DataViewItem {\n  id: string;\n  title: string;\n  subtitle?: string;\n  image?: string;\n  price?: number;\n  rating?: number;\n  /** A short tag on the image, e.g. \"New\" or \"Beginner\". */\n  badge?: string;\n}\n\nexport type DataViewSort = \"featured\" | \"price-asc\" | \"price-desc\" | \"rating\" | \"title\";\n\nexport interface DataViewProps {\n  items?: DataViewItem[];\n  title?: string;\n  layout?: \"grid\" | \"list\";\n  defaultLayout?: \"grid\" | \"list\";\n  onLayoutChange?: (layout: \"grid\" | \"list\") => void;\n  /** Sort choices offered in the header. Pass [] to hide the menu. */\n  sortOptions?: DataViewSort[];\n  defaultSort?: DataViewSort;\n  /** Items per page; 0 shows them all. */\n  pageSize?: number;\n  /** Grid columns on wide screens. */\n  columns?: 2 | 3 | 4;\n  currency?: string;\n  locale?: string;\n  onItemClick?: (item: DataViewItem) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", faint: \"rgba(245,244,241,0.3)\", panel: \"#0E0E0E\", card: \"#131313\", border: \"rgba(255,255,255,0.09)\", borderHover: \"rgba(255,255,255,0.2)\", seg: \"rgba(255,255,255,0.06)\", segOn: \"#1F1F1F\", badge: \"rgba(10,10,10,0.6)\", focus: \"rgba(245,244,241,0.85)\", img: \"#1A1A1A\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", faint: \"rgba(10,10,10,0.3)\", panel: \"#FFFFFF\", card: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", borderHover: \"rgba(10,10,10,0.22)\", seg: \"rgba(10,10,10,0.05)\", segOn: \"#FFFFFF\", badge: \"rgba(255,255,255,0.85)\", focus: \"rgba(10,10,10,0.85)\", img: \"#EDEDEB\" },\n};\n\nconst SORT_LABELS: Record<DataViewSort, string> = { featured: \"Featured\", \"price-asc\": \"Price: low to high\", \"price-desc\": \"Price: high to low\", rating: \"Top rated\", title: \"Name\" };\n\nconst DEFAULT_ITEMS: DataViewItem[] = [\n  { id: \"cycling\", title: \"Road Cycling Base\", subtitle: \"Cycling · 8 weeks\", image: \"/demo/34.webp\", price: 49, rating: 4.8, badge: \"Bestseller\" },\n  { id: \"sprint\", title: \"Sprint Speed\", subtitle: \"Running · 6 weeks\", image: \"/demo/31.webp\", price: 39, rating: 4.7 },\n  { id: \"ski\", title: \"Alpine Ski Prep\", subtitle: \"Skiing · 5 weeks\", image: \"/demo/12.webp\", price: 59, rating: 4.9, badge: \"New\" },\n  { id: \"rowing\", title: \"Rowing Endurance\", subtitle: \"Rowing · 10 weeks\", image: \"/demo/28.webp\", price: 45, rating: 4.6 },\n  { id: \"swim\", title: \"Open Water Swim\", subtitle: \"Swimming · 8 weeks\", image: \"/demo/33.webp\", price: 55, rating: 4.8 },\n  { id: \"barbell\", title: \"Barbell Foundations\", subtitle: \"Strength · 12 weeks\", image: \"/demo/24.webp\", price: 65, rating: 4.9 },\n  { id: \"trail\", title: \"Trail Hiking Strength\", subtitle: \"Hiking · 6 weeks\", image: \"/demo/23.webp\", price: 35, rating: 4.5 },\n  { id: \"sled\", title: \"Sled Push Power\", subtitle: \"Conditioning · 4 weeks\", image: \"/demo/30.webp\", price: 29, rating: 4.4, badge: \"Short\" },\n  { id: \"track\", title: \"5K to 10K\", subtitle: \"Running · 9 weeks\", image: \"/demo/29.webp\", price: 42, rating: 4.7 },\n];\n\nfunction Star({ color }: { color: string }) {\n  return (\n    <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n      <path d=\"M12 3.2 14.7 8.7l6 .9-4.35 4.25 1 6L12 17l-5.4 2.85 1-6L3.3 9.6l6-.9Z\" fill={color} />\n    </svg>\n  );\n}\n\nexport function DataView({\n  items = DEFAULT_ITEMS,\n  title = \"Training plans\",\n  layout,\n  defaultLayout = \"grid\",\n  onLayoutChange,\n  sortOptions = [\"featured\", \"price-asc\", \"price-desc\", \"rating\"],\n  defaultSort = \"featured\",\n  pageSize = 6,\n  columns = 3,\n  currency = \"USD\",\n  locale = \"en-US\",\n  onItemClick,\n  theme = \"dark\",\n  className,\n}: DataViewProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const [internalLayout, setInternalLayout] = React.useState(defaultLayout);\n  const view = layout ?? internalLayout;\n  const [sort, setSort] = React.useState<DataViewSort>(defaultSort);\n  const [page, setPage] = React.useState(0);\n\n  const money = React.useMemo(() => new Intl.NumberFormat(locale, { style: \"currency\", currency, maximumFractionDigits: 0 }), [locale, currency]);\n\n  const sorted = React.useMemo(() => {\n    const list = [...items];\n    if (sort === \"price-asc\") list.sort((a, b) => (a.price ?? 0) - (b.price ?? 0));\n    else if (sort === \"price-desc\") list.sort((a, b) => (b.price ?? 0) - (a.price ?? 0));\n    else if (sort === \"rating\") list.sort((a, b) => (b.rating ?? 0) - (a.rating ?? 0));\n    else if (sort === \"title\") list.sort((a, b) => a.title.localeCompare(b.title));\n    return list;\n  }, [items, sort]);\n\n  const pages = pageSize > 0 ? Math.max(1, Math.ceil(sorted.length / pageSize)) : 1;\n  const current = Math.min(page, pages - 1);\n  const shown = pageSize > 0 ? sorted.slice(current * pageSize, current * pageSize + pageSize) : sorted;\n\n  const setView = (v: \"grid\" | \"list\") => {\n    if (layout === undefined) setInternalLayout(v);\n    onLayoutChange?.(v);\n  };\n\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 380, damping: 36 };\n  const grid = view === \"grid\";\n  const cols = { 2: \"sm:grid-cols-2\", 3: \"sm:grid-cols-2 lg:grid-cols-3\", 4: \"sm:grid-cols-2 lg:grid-cols-4\" }[columns];\n\n  const segBtn = (v: \"grid\" | \"list\", label: string, d: string[]) => (\n    <button\n      type=\"button\"\n      aria-label={label}\n      aria-pressed={view === v}\n      onClick={() => setView(v)}\n      className=\"relative flex cursor-pointer items-center justify-center rounded-md border-none bg-transparent outline-none focus-visible:ring-2\"\n      style={{ width: 32, height: 28, color: view === v ? p.text : p.muted, [\"--tw-ring-color\" as string]: p.focus }}\n    >\n      {view === v && <motion.span layoutId={`${uid}-seg`} className=\"absolute inset-0 rounded-md\" style={{ background: p.segOn, boxShadow: `0 0 0 1px ${p.border}` }} transition={spring} />}\n      <svg className=\"relative\" width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n        {d.map((x) => (\n          <path key={x} d={x} />\n        ))}\n      </svg>\n    </button>\n  );\n\n  return (\n    <section className={cn(\"flex w-full flex-col\", className)} aria-labelledby={`${uid}-title`} style={{ gap: 16, fontFamily: \"Inter, sans-serif\", color: p.text }}>\n      <div className=\"flex flex-wrap items-center justify-between\" style={{ gap: 12 }}>\n        <div className=\"flex items-baseline\" style={{ gap: 10 }}>\n          <h3 id={`${uid}-title`} className=\"m-0 text-[17px] font-semibold tracking-[-0.01em]\">\n            {title}\n          </h3>\n          <span className=\"text-[13px] tabular-nums\" style={{ color: p.muted }}>\n            {items.length} {items.length === 1 ? \"item\" : \"items\"}\n          </span>\n        </div>\n        <div className=\"flex items-center\" style={{ gap: 8 }}>\n          {sortOptions.length > 0 && (\n            <label className=\"relative flex items-center\">\n              <span className=\"sr-only\">Sort by</span>\n              <select\n                value={sort}\n                onChange={(e) => {\n                  setSort(e.target.value as DataViewSort);\n                  setPage(0);\n                }}\n                className=\"h-8 cursor-pointer appearance-none rounded-lg text-[13px] font-medium outline-none focus-visible:ring-2\"\n                style={{ padding: \"0 30px 0 11px\", background: p.seg, color: p.text, border: `1px solid ${p.border}`, [\"--tw-ring-color\" as string]: p.focus, colorScheme: theme }}\n              >\n                {sortOptions.map((o) => (\n                  <option key={o} value={o}>\n                    {SORT_LABELS[o]}\n                  </option>\n                ))}\n              </select>\n              <svg className=\"pointer-events-none absolute right-2.5\" width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.muted} strokeWidth=\"2.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"m6 9 6 6 6-6\" />\n              </svg>\n            </label>\n          )}\n          <div className=\"flex rounded-lg\" style={{ padding: 2, gap: 2, background: p.seg }} role=\"group\" aria-label=\"Layout\">\n            {segBtn(\"grid\", \"Grid view\", [\"M4 4h6.5v6.5H4Z\", \"M13.5 4H20v6.5h-6.5Z\", \"M4 13.5h6.5V20H4Z\", \"M13.5 13.5H20V20h-6.5Z\"])}\n            {segBtn(\"list\", \"List view\", [\"M4 6h16\", \"M4 12h16\", \"M4 18h16\"])}\n          </div>\n        </div>\n      </div>\n\n      <LayoutGroup id={uid}>\n        <motion.ul layout className={cn(\"m-0 grid list-none p-0\", grid ? cols : \"grid-cols-1\")} style={{ gap: grid ? 14 : 8 }} transition={spring}>\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            {shown.map((item) => {\n              const inner = (\n                <>\n                  {item.image && (\n                    <motion.div layout className=\"relative shrink-0 overflow-hidden\" style={{ width: grid ? \"100%\" : 104, aspectRatio: grid ? \"4 / 3\" : \"4 / 3\", borderRadius: grid ? 12 : 10, background: p.img }} transition={spring}>\n                      {/* eslint-disable-next-line @next/next/no-img-element */}\n                      <img src={item.image} alt=\"\" draggable={false} className=\"h-full w-full object-cover transition-transform duration-500 group-hover:scale-[1.04]\" />\n                      {item.badge && grid && (\n                        <span className=\"absolute top-2.5 left-2.5 rounded-full text-[11px] font-semibold backdrop-blur-md\" style={{ padding: \"3px 8px\", background: p.badge, color: p.text }}>\n                          {item.badge}\n                        </span>\n                      )}\n                    </motion.div>\n                  )}\n                  <motion.div layout=\"position\" className=\"flex min-w-0 flex-1 flex-col\" style={{ gap: 3, padding: grid ? \"12px 4px 4px\" : \"0\" }} transition={spring}>\n                    <span className=\"flex items-center\" style={{ gap: 8 }}>\n                      <span className=\"truncate text-[14.5px] font-semibold\">{item.title}</span>\n                      {item.badge && !grid && (\n                        <span className=\"shrink-0 rounded-full text-[10.5px] font-semibold\" style={{ padding: \"2px 7px\", background: p.seg, color: p.muted }}>\n                          {item.badge}\n                        </span>\n                      )}\n                    </span>\n                    {item.subtitle && <span className=\"truncate text-[12.5px]\" style={{ color: p.muted }}>{item.subtitle}</span>}\n                    {(item.rating !== undefined || item.price !== undefined) && grid && (\n                      <span className=\"mt-1.5 flex items-center justify-between\">\n                        {item.rating !== undefined && (\n                          <span className=\"flex items-center text-[12.5px] font-medium tabular-nums\" style={{ gap: 4, color: p.muted }}>\n                            <Star color={p.text} /> {item.rating.toFixed(1)}\n                          </span>\n                        )}\n                        {item.price !== undefined && <span className=\"text-[14.5px] font-semibold tabular-nums\">{money.format(item.price)}</span>}\n                      </span>\n                    )}\n                    {item.rating !== undefined && !grid && (\n                      <span className=\"mt-0.5 flex items-center text-[12.5px] font-medium tabular-nums\" style={{ gap: 4, color: p.muted }}>\n                        <Star color={p.text} /> {item.rating.toFixed(1)}\n                      </span>\n                    )}\n                  </motion.div>\n                  {!grid && item.price !== undefined && (\n                    <motion.span layout=\"position\" className=\"shrink-0 text-[15px] font-semibold tabular-nums\" transition={spring}>\n                      {money.format(item.price)}\n                    </motion.span>\n                  )}\n                </>\n              );\n              const box = cn(\"group flex w-full text-left no-underline outline-none focus-visible:ring-2\", grid ? \"flex-col\" : \"flex-row items-center\");\n              const boxStyle: React.CSSProperties = { gap: grid ? 0 : 16, padding: grid ? 8 : 10, borderRadius: 16, background: p.card, border: `1px solid ${p.border}`, color: p.text, [\"--tw-ring-color\" as string]: p.focus };\n              return (\n                <motion.li\n                  key={item.id}\n                  layout\n                  initial={{ opacity: 0, scale: 0.96 }}\n                  animate={{ opacity: 1, scale: 1 }}\n                  exit={{ opacity: 0, scale: 0.96 }}\n                  transition={spring}\n                  style={{ borderRadius: 16 }}\n                  whileHover={reduce ? undefined : { y: -2 }}\n                >\n                  {onItemClick ? (\n                    <button type=\"button\" onClick={() => onItemClick(item)} className={cn(box, \"cursor-pointer\")} style={boxStyle}>\n                      {inner}\n                    </button>\n                  ) : (\n                    <div className={box} style={boxStyle}>\n                      {inner}\n                    </div>\n                  )}\n                </motion.li>\n              );\n            })}\n          </AnimatePresence>\n        </motion.ul>\n      </LayoutGroup>\n\n      {pages > 1 && (\n        <nav className=\"flex items-center justify-center\" style={{ gap: 4 }} aria-label=\"Pages\">\n          {Array.from({ length: pages }, (_, i) => (\n            <button\n              key={i}\n              type=\"button\"\n              aria-current={i === current ? \"page\" : undefined}\n              onClick={() => setPage(i)}\n              className=\"relative cursor-pointer rounded-lg border-none bg-transparent text-[13px] font-semibold tabular-nums outline-none focus-visible:ring-2\"\n              style={{ width: 32, height: 32, color: i === current ? p.text : p.muted, [\"--tw-ring-color\" as string]: p.focus }}\n            >\n              {i === current && <motion.span layoutId={`${uid}-page`} className=\"absolute inset-0 rounded-lg\" style={{ background: p.seg, boxShadow: `0 0 0 1px ${p.border}` }} transition={spring} />}\n              <span className=\"relative\">{i + 1}</span>\n            </button>\n          ))}\n        </nav>\n      )}\n    </section>\n  );\n}\n\nexport default DataView;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}