{
  "schemaVersion": 1,
  "target": "react",
  "name": "bar-list",
  "version": "0.1.0",
  "category": "data",
  "title": "Bar List",
  "description": "Ranked rows whose background bar shows each value against the largest, with tabs that switch lists, bars that resize and re-rank in place, a Show more that grows the card, and a loading state.",
  "tags": [
    "chart",
    "bar list",
    "ranking",
    "analytics",
    "top list",
    "tabs",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0",
    "motion": "^14.14.0"
  },
  "registryDependencies": [],
  "docsPath": "/components/bar-list",
  "props": [
    {
      "name": "data",
      "type": "{ name, value, icon?, href? }[]",
      "description": "BarList: the rows. Rows with the same name keep their identity across updates, so their bars resize and they glide to their new rank."
    },
    {
      "name": "tabs",
      "type": "{ value, label, data }[]",
      "description": "BarListCard: the lists to switch between."
    },
    {
      "name": "tab / defaultTab / onTabChange",
      "type": "string",
      "description": "BarListCard: the active tab."
    },
    {
      "name": "title / meta / columns",
      "type": "ReactNode / ReactNode / [ReactNode, ReactNode]",
      "description": "BarListCard: the heading, text at the right of the header, and column headings above the rows."
    },
    {
      "name": "valueFormatter",
      "type": "(value: number) => string",
      "default": "Intl.NumberFormat",
      "description": "Formats values on the right."
    },
    {
      "name": "show",
      "type": "\"value\" | \"share\" | \"both\"",
      "default": "\"value\"",
      "description": "Right column: the value, the share of the total, or both."
    },
    {
      "name": "sortOrder",
      "type": "\"descending\" | \"ascending\" | \"none\"",
      "default": "\"descending\"",
      "description": "Ranks rows by value, or keeps the given order."
    },
    {
      "name": "limit",
      "type": "number",
      "default": "5",
      "description": "Rows shown before Show more."
    },
    {
      "name": "expanded / defaultExpanded / onExpandedChange",
      "type": "boolean",
      "description": "Whether the rows past limit are shown."
    },
    {
      "name": "loading",
      "type": "boolean",
      "default": "false",
      "description": "Shows static placeholder rows; bars grow in when data arrives."
    },
    {
      "name": "onSelect",
      "type": "(item) => void",
      "description": "Makes rows buttons. Rows with href are links."
    },
    {
      "name": "empty",
      "type": "ReactNode",
      "default": "\"No data for this period.\"",
      "description": "Shown when data is empty."
    }
  ],
  "accessibility": [
    "Rows are a list; each reads as its label and value, with the share of the total added as screen reader text. Bars are decorative.",
    "BarListCard tabs are a Base UI tablist with arrow-key navigation.",
    "Show more is a button with aria-expanded and aria-controls; folded rows are inert and hidden from assistive technology until expanded.",
    "Loading sets aria-busy on the placeholder.",
    "Under reduced motion bars render at their final width, rows re-rank and expand without animating."
  ],
  "states": [
    "loading",
    "default",
    "folded",
    "expanded",
    "empty",
    "interactive"
  ],
  "files": [
    {
      "path": "ui/bar-list.tsx",
      "content": "\"use client\";\n\nimport { Tabs as BaseTabs } from \"@base-ui/react/tabs\";\nimport { AnimatePresence, MotionConfig, motion, useReducedMotion, type Transition } from \"motion/react\";\nimport { useId, useMemo, useRef, useState, type ReactNode } from \"react\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const;\nconst ROW = 32;\nconst GAP = 4;\n\nexport interface BarListItem {\n  /** Row label. Rows with the same name keep their identity when the data changes, so their bars resize and re-rank instead of re-entering. */\n  name: string;\n  value: number;\n  /** A 16px icon, flag or favicon before the label. */\n  icon?: ReactNode;\n  /** Makes the row a link. */\n  href?: string;\n}\n\nexport interface BarListProps {\n  data: BarListItem[];\n  /** Formats values on the right. Defaults to `Intl.NumberFormat`. */\n  valueFormatter?: (value: number) => string;\n  /** Ranks rows by value. `none` keeps the given order. */\n  sortOrder?: \"descending\" | \"ascending\" | \"none\";\n  /** What the right column shows: the value, the row's share of the total, or both. */\n  show?: \"value\" | \"share\" | \"both\";\n  /** Rows shown before \"Show more\". Pass `Infinity` to show every row. */\n  limit?: number;\n  /** Controlled expanded state of a list longer than `limit`. */\n  expanded?: boolean;\n  defaultExpanded?: boolean;\n  onExpandedChange?: (expanded: boolean) => void;\n  /** Shows placeholder rows while the data loads. */\n  loading?: boolean;\n  /** Called when a row is pressed. Makes rows buttons. */\n  onSelect?: (item: BarListItem) => void;\n  /** Names the list for screen readers. */\n  label?: string;\n  /** Shown when `data` is empty. */\n  empty?: ReactNode;\n  className?: string;\n}\n\n/**\n * Ranked rows whose background bar shows each value against the largest one. Bars grow in on\n * mount, resize and re-rank in place when the data changes, and rows past `limit` fold behind a\n * \"Show more\" that grows the list. Under reduced motion everything renders in its final state.\n */\nexport function BarList({\n  data,\n  valueFormatter,\n  sortOrder = \"descending\",\n  show = \"value\",\n  limit = 5,\n  expanded: expandedProp,\n  defaultExpanded = false,\n  onExpandedChange,\n  loading = false,\n  onSelect,\n  label,\n  empty = \"No data for this period.\",\n  className,\n}: BarListProps) {\n  const reduce = useReducedMotion();\n  const listId = useId();\n  const [expandedState, setExpandedState] = useState(defaultExpanded);\n  const expanded = expandedProp ?? expandedState;\n  const setExpanded = (next: boolean) => {\n    if (expandedProp === undefined) setExpandedState(next);\n    onExpandedChange?.(next);\n  };\n\n  const rows = useMemo(() => {\n    const copy = data.slice();\n    if (sortOrder !== \"none\") copy.sort((a, b) => (sortOrder === \"descending\" ? b.value - a.value : a.value - b.value));\n    return copy;\n  }, [data, sortOrder]);\n\n  const max = rows.reduce((m, r) => Math.max(m, r.value), 0);\n  const total = rows.reduce((s, r) => s + r.value, 0);\n  const format = valueFormatter ?? ((n: number) => new Intl.NumberFormat().format(n));\n  const percent = new Intl.NumberFormat(undefined, { style: \"percent\", maximumFractionDigits: 1 });\n  const hidden = Math.max(0, rows.length - limit);\n  const folded = hidden > 0 && !expanded;\n  const collapsedHeight = Math.min(rows.length, limit) * ROW + Math.max(0, Math.min(rows.length, limit) - 1) * GAP;\n\n  // Bars stagger in only the first time rows appear; later changes resize them together.\n  const seen = useRef(new Set<string>());\n  const firstPaint = useRef(true);\n\n  if (loading) {\n    // Bars stagger in again once the data arrives.\n    seen.current.clear();\n    firstPaint.current = true;\n    const widths = [92, 71, 54, 38, 27, 19];\n    return (\n      <div aria-busy=\"true\" aria-label={label ? `${label}, loading` : \"Loading\"} className={cx(\"grid gap-1\", className)}>\n        {widths.slice(0, Number.isFinite(limit) ? Math.max(1, limit) : 5).map((w, i) => (\n          <div key={i} className=\"flex h-8 items-center justify-between gap-4\">\n            <div style={{ width: `${w}%` }} className=\"h-8 rounded-md bg-zinc-950/[0.04] dark:bg-white/[0.06]\" />\n            <div className=\"h-2.5 w-10 shrink-0 rounded-full bg-zinc-950/[0.06] dark:bg-white/[0.08]\" />\n          </div>\n        ))}\n      </div>\n    );\n  }\n\n  if (rows.length === 0) {\n    return <p className={cx(\"py-6 text-center text-sm text-zinc-500\", className)}>{empty}</p>;\n  }\n\n  const barTransition = (index: number, isNew: boolean, revealIndex: number): Transition =>\n    reduce\n      ? { duration: 0 }\n      : {\n          duration: 0.5,\n          ease,\n          delay: revealIndex >= 0 ? revealIndex * 0.03 : isNew && firstPaint.current ? index * 0.04 : 0,\n        };\n\n  const list = (\n    <motion.div\n      initial={false}\n      animate={{ height: folded ? collapsedHeight : \"auto\" }}\n      transition={reduce ? { duration: 0 } : { duration: 0.32, ease }}\n      className={cx(\n        \"relative overflow-hidden\",\n        folded && \"[mask-image:linear-gradient(to_bottom,black_55%,transparent)]\",\n      )}\n    >\n      <ul id={listId} aria-label={label} className=\"relative grid gap-1\">\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          {rows.map((row, index) => {\n            const isNew = !seen.current.has(row.name);\n            const visible = !folded || index < limit;\n            const pct = max > 0 ? (row.value / max) * 100 : 0;\n            const share = total > 0 ? row.value / total : 0;\n            const right =\n              show === \"share\" ? percent.format(share) : format(row.value);\n            const revealIndex = expanded && index >= limit ? index - limit : -1;\n            const content = (\n              <>\n                <span className=\"relative flex h-full min-w-0 flex-1 items-center\">\n                  <motion.span\n                    aria-hidden=\"true\"\n                    initial={{ clipPath: \"inset(0 100% 0 0 round 6px)\" }}\n                    animate={{ clipPath: `inset(0 ${visible ? 100 - pct : 100}% 0 0 round 6px)` }}\n                    transition={barTransition(index, isNew, revealIndex)}\n                    className={cx(\n                      \"absolute inset-0 rounded-md bg-zinc-950/[0.07] dark:bg-white/[0.1]\",\n                      \"transition-[background-color] duration-150 ease-out motion-reduce:transition-none\",\n                      (onSelect || row.href) && \"group-hover/row:bg-zinc-950/[0.11] dark:group-hover/row:bg-white/[0.15]\",\n                    )}\n                  />\n                  <span className=\"relative flex min-w-0 items-center gap-2 px-2.5\">\n                    {row.icon ? (\n                      <span aria-hidden=\"true\" className=\"flex size-4 shrink-0 items-center justify-center text-zinc-500 [&_svg]:size-4 [&>img]:size-4 [&>img]:rounded-sm\">\n                        {row.icon}\n                      </span>\n                    ) : null}\n                    <span className=\"truncate text-zinc-950 dark:text-white\">{row.name}</span>\n                  </span>\n                </span>\n                <span className=\"flex min-w-12 shrink-0 items-baseline justify-end gap-2 font-mono text-xs tabular-nums\">\n                  {show === \"both\" ? <span className=\"text-zinc-500\">{percent.format(share)}</span> : null}\n                  <span className=\"text-zinc-700 dark:text-zinc-300\">{right}</span>\n                  {show === \"value\" ? <span className=\"sr-only\">, {percent.format(share)} of total</span> : null}\n                </span>\n              </>\n            );\n            const rowClass = cx(\n              \"group/row relative flex h-8 w-full items-center justify-between gap-3 rounded-md text-left text-sm\",\n            );\n            const interactiveClass =\n              \"cursor-pointer outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\";\n            return (\n              <motion.li\n                key={row.name}\n                layout={reduce ? false : \"position\"}\n                initial={{ opacity: 0 }}\n                animate={{ opacity: 1 }}\n                exit={{ opacity: 0, transition: { duration: reduce ? 0 : 0.12, ease: \"easeOut\" } }}\n                transition={reduce ? { duration: 0 } : { layout: { type: \"spring\", bounce: 0, duration: 0.45 }, opacity: { duration: 0.2 } }}\n                onAnimationComplete={() => {\n                  seen.current.add(row.name);\n                  firstPaint.current = false;\n                }}\n                inert={!visible || undefined}\n                aria-hidden={!visible || undefined}\n              >\n                {row.href ? (\n                  <a href={row.href} className={cx(rowClass, interactiveClass)} onClick={onSelect ? () => onSelect(row) : undefined}>\n                    {content}\n                  </a>\n                ) : onSelect ? (\n                  <button type=\"button\" className={cx(rowClass, interactiveClass)} onClick={() => onSelect(row)}>\n                    {content}\n                  </button>\n                ) : (\n                  <div className={rowClass}>{content}</div>\n                )}\n              </motion.li>\n            );\n          })}\n        </AnimatePresence>\n      </ul>\n    </motion.div>\n  );\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div className={cx(\"grid\", className)}>\n        {list}\n        {hidden > 0 ? (\n          <div className={cx(\"relative flex justify-center\", folded ? \"-mt-3\" : \"mt-2\")}>\n            <button\n              type=\"button\"\n              aria-expanded={expanded}\n              aria-controls={listId}\n              onClick={() => setExpanded(!expanded)}\n              className={cx(\n                \"inline-flex h-7 items-center gap-1.5 rounded-lg border px-2.5 text-xs font-medium select-none\",\n                \"border-zinc-950/10 bg-white text-zinc-600 hover:border-zinc-950/20 hover:text-zinc-950\",\n                \"dark:border-white/15 dark:bg-black dark:text-zinc-400 dark:hover:border-white/25 dark:hover:text-white\",\n                \"transition-[color,border-color,scale] duration-150 ease-out motion-safe:active:scale-[0.97] motion-reduce:transition-none\",\n                \"outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n              )}\n            >\n              {expanded ? \"Show less\" : `Show ${hidden} more`}\n              <svg\n                aria-hidden=\"true\"\n                viewBox=\"0 0 16 16\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth=\"1.5\"\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n                className={cx(\"size-3.5 transition-transform duration-200 motion-reduce:transition-none\", expanded && \"rotate-180\")}\n              >\n                <path d=\"m4.5 6.5 3.5 3.5 3.5-3.5\" />\n              </svg>\n            </button>\n          </div>\n        ) : null}\n      </div>\n    </MotionConfig>\n  );\n}\n\nexport interface BarListTab {\n  value: string;\n  label: ReactNode;\n  data: BarListItem[];\n}\n\nexport interface BarListCardProps extends Omit<BarListProps, \"data\" | \"label\"> {\n  /** Card heading. */\n  title: ReactNode;\n  /** Lists to switch between. Rows that share a name across lists resize and re-rank in place. */\n  tabs: BarListTab[];\n  /** Controlled active tab. */\n  tab?: string;\n  defaultTab?: string;\n  onTabChange?: (value: string) => void;\n  /** Column headings above the rows, such as `[\"Page\", \"Visitors\"]`. */\n  columns?: [ReactNode, ReactNode];\n  /** Meta text at the right of the header, such as a total or a date range. */\n  meta?: ReactNode;\n}\n\n/**\n * A card with a heading, tabs that switch between ranked lists, and a Bar List.\n * The list instance persists across tabs, so shared rows animate between values.\n */\nexport function BarListCard({\n  title,\n  tabs,\n  tab: tabProp,\n  defaultTab,\n  onTabChange,\n  columns,\n  meta,\n  className,\n  ...listProps\n}: BarListCardProps) {\n  const [tabState, setTabState] = useState(defaultTab ?? tabs[0]?.value ?? \"\");\n  const active = tabProp ?? tabState;\n  const current = tabs.find((t) => t.value === active) ?? tabs[0];\n  const indicatorId = `bar-list-tab-${useId()}`;\n  const titleId = useId();\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <section\n        aria-labelledby={titleId}\n        className={cx(\n          \"grid w-full rounded-xl border border-zinc-950/10 bg-white text-sm shadow-[0_1px_2px_rgb(0_0_0/0.04)]\",\n          \"dark:border-white/10 dark:bg-black dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]\",\n          className,\n        )}\n      >\n        <header className=\"flex items-baseline justify-between gap-4 px-4 pt-4\">\n          <h3 id={titleId} className=\"text-sm font-semibold text-zinc-950 dark:text-white\">\n            {title}\n          </h3>\n          {meta ? <span className=\"font-mono text-xs text-zinc-500 tabular-nums\">{meta}</span> : null}\n        </header>\n        <BaseTabs.Root\n          value={active}\n          onValueChange={(value) => {\n            if (tabProp === undefined) setTabState(value as string);\n            onTabChange?.(value as string);\n          }}\n        >\n          <BaseTabs.List className=\"relative mt-2 flex gap-1 border-b border-zinc-950/[0.07] px-2 dark:border-white/[0.08]\">\n            {tabs.map((t) => (\n              <BaseTabs.Tab\n                key={t.value}\n                value={t.value}\n                className={cx(\n                  \"relative h-9 shrink-0 cursor-pointer px-2 text-sm whitespace-nowrap select-none\",\n                  \"text-zinc-500 hover:text-zinc-950 data-[active]:text-zinc-950 dark:hover:text-white dark:data-[active]:text-white\",\n                  \"transition-colors duration-150 ease-out motion-reduce:transition-none\",\n                  \"rounded-md outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\",\n                )}\n              >\n                {t.label}\n                {t.value === active ? (\n                  <motion.span\n                    aria-hidden=\"true\"\n                    layoutId={indicatorId}\n                    transition={{ type: \"spring\", bounce: 0, duration: 0.35 }}\n                    className=\"absolute inset-x-2 -bottom-px h-px bg-zinc-950 dark:bg-white\"\n                  />\n                ) : null}\n              </BaseTabs.Tab>\n            ))}\n          </BaseTabs.List>\n          {/* One panel whose value follows the active tab, so the list inside persists and can morph. */}\n          <BaseTabs.Panel value={active} className=\"grid gap-2 px-4 pt-3 pb-4 outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-sky-500\">\n            {columns ? (\n              <div aria-hidden=\"true\" className=\"flex justify-between px-2.5 text-xs font-medium text-zinc-500\">\n                <span>{columns[0]}</span>\n                <span>{columns[1]}</span>\n              </div>\n            ) : null}\n            <BarList {...listProps} data={current?.data ?? []} label={typeof current?.label === \"string\" ? current.label : undefined} />\n          </BaseTabs.Panel>\n        </BaseTabs.Root>\n      </section>\n    </MotionConfig>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { BarListCard } from \"@/components/shaken/ui/bar-list\";\n\nconst range = (values: number[]) =>\n  [\"search_docs\", \"read_file\", \"edit_file\", \"run_tests\", \"fetch_url\", \"query_db\", \"open_pull_request\", \"send_slack_message\"].map(\n    (name, i) => ({ name, value: values[i]! }),\n  );\n\nconst tabs = [\n  { value: \"24h\", label: \"24 hours\", data: range([412, 388, 241, 197, 133, 96, 31, 12]) },\n  { value: \"7d\", label: \"7 days\", data: range([2_604, 2_871, 1_932, 1_655, 702, 811, 214, 97]) },\n  { value: \"30d\", label: \"30 days\", data: range([10_284, 11_903, 8_115, 7_342, 2_516, 3_870, 902, 455]) },\n];\n\nexport default function BarListExample() {\n  return (\n    <BarListCard\n      className=\"max-w-md\"\n      title=\"Tool calls\"\n      meta=\"Production agents\"\n      columns={[\"Tool\", \"Calls\"]}\n      tabs={tabs}\n      limit={5}\n    />\n  );\n}\n"
  }
}
