{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mini-segment-bar",
  "title": "Mini Segment Bar",
  "description": "Compact rows of small blocks, one per item, filled by status: progress for several teams at once, with a filter to light up one status.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/mini-segment-bar/mini-segment-bar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SegmentStatus {\n  id: string;\n  label: string;\n  /** Leave out for the empty cell colour, e.g. for \"To do\". */\n  color?: string;\n}\n\nexport interface SegmentRow {\n  label: string;\n  /** One entry per period: a count for each status id. */\n  counts: Record<string, number>[];\n}\n\nexport interface MiniSegmentBarProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  /** In the order the cells fill. The last one usually has no colour. */\n  statuses?: SegmentStatus[];\n  rows?: SegmentRow[];\n  periods?: string[];\n  /** Index of the period shown first. Defaults to the latest. */\n  defaultPeriod?: number;\n  /** The status counted as finished in the stats. */\n  doneId?: string;\n  /** The status counted as stuck in the stats. */\n  stuckId?: string;\n  onPeriodChange?: (period: string) => void;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    chipOn: \"rgba(255,255,255,0.1)\",\n    empty: \"rgba(255,255,255,0.08)\",\n    rowOn: \"rgba(255,255,255,0.04)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    chipOn: \"#FFFFFF\",\n    empty: \"rgba(8,9,10,0.08)\",\n    rowOn: \"rgba(8,9,10,0.03)\",\n  },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst CARD_FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst MAX_CELLS = 48;\n\nconst STATUSES: SegmentStatus[] = [\n  { id: \"done\", label: \"Done\", color: \"#5E6AD2\" },\n  { id: \"review\", label: \"In review\", color: \"#4EA7FC\" },\n  { id: \"blocked\", label: \"Blocked\", color: \"#FC7840\" },\n  { id: \"todo\", label: \"To do\" },\n];\n\nconst PERIODS = [\"Sprint 22\", \"Sprint 23\", \"Sprint 24\"];\n\nconst ROWS: SegmentRow[] = [\n  {\n    label: \"Platform\",\n    counts: [\n      { done: 22, review: 4, blocked: 1, todo: 3 },\n      { done: 18, review: 6, blocked: 0, todo: 8 },\n      { done: 9, review: 5, blocked: 2, todo: 16 },\n    ],\n  },\n  {\n    label: \"Web app\",\n    counts: [\n      { done: 26, review: 2, blocked: 0, todo: 2 },\n      { done: 20, review: 5, blocked: 1, todo: 4 },\n      { done: 14, review: 7, blocked: 0, todo: 13 },\n    ],\n  },\n  {\n    label: \"Mobile\",\n    counts: [\n      { done: 15, review: 3, blocked: 2, todo: 4 },\n      { done: 12, review: 4, blocked: 3, todo: 7 },\n      { done: 6, review: 3, blocked: 1, todo: 14 },\n    ],\n  },\n  {\n    label: \"Design\",\n    counts: [\n      { done: 17, review: 1, blocked: 0, todo: 2 },\n      { done: 14, review: 3, blocked: 0, todo: 3 },\n      { done: 11, review: 4, blocked: 0, todo: 7 },\n    ],\n  },\n  {\n    label: \"Data\",\n    counts: [\n      { done: 10, review: 2, blocked: 1, todo: 5 },\n      { done: 9, review: 2, blocked: 2, todo: 6 },\n      { done: 4, review: 2, blocked: 1, todo: 11 },\n    ],\n  },\n  {\n    label: \"Support tools\",\n    counts: [\n      { done: 12, review: 0, blocked: 0, todo: 2 },\n      { done: 8, review: 3, blocked: 0, todo: 4 },\n      { done: 5, review: 1, blocked: 0, todo: 10 },\n    ],\n  },\n];\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle cx={r} cy={r} r={r} style={{ fill: color }} />\n    </svg>\n  );\n}\n\nfunction Stat({\n  value,\n  label,\n  pal,\n}: {\n  value: string;\n  label: string;\n  pal: Palette;\n}) {\n  return (\n    <div className=\"min-w-0 text-left sm:text-right\">\n      <p className=\"m-0 truncate text-[18px] leading-[1.2] font-[510] tracking-[-0.018em] tabular-nums\">\n        {value}\n      </p>\n      <p\n        className=\"m-0 mt-0.5 text-[12px] tracking-[-0.011em] whitespace-nowrap\"\n        style={{ color: pal.sub }}\n      >\n        {label}\n      </p>\n    </div>\n  );\n}\n\nexport function MiniSegmentBar({\n  theme = \"dark\",\n  title = \"Sprint progress\",\n  subtitle = \"One block per issue, filled in as work moves.\",\n  statuses = STATUSES,\n  rows = ROWS,\n  periods = PERIODS,\n  defaultPeriod,\n  doneId = \"done\",\n  stuckId = \"blocked\",\n  onPeriodChange,\n  className,\n  style,\n  ...props\n}: MiniSegmentBarProps) {\n  const pal = PALETTES[theme];\n  const boxRef = React.useRef<HTMLUListElement>(null);\n  const [period, setPeriod] = React.useState(\n    defaultPeriod ?? Math.max(0, periods.length - 1),\n  );\n  const [row, setRow] = React.useState<number | null>(null);\n  const [only, setOnly] = React.useState<string | null>(null);\n  const [seen, setSeen] = React.useState(false);\n\n  React.useEffect(() => {\n    const el = boxRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry.isIntersecting) return;\n        io.disconnect();\n        setSeen(true);\n      },\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  const colorOf = (id: string) =>\n    statuses.find((s) => s.id === id)?.color ?? pal.empty;\n  const totalOf = (counts: Record<string, number> | undefined) =>\n    statuses.reduce((n, s) => n + Math.max(0, counts?.[s.id] ?? 0), 0);\n\n  // One width for every period, so rows only fill and never stretch.\n  const widest = Math.max(\n    1,\n    ...rows.flatMap((r) => r.counts.map((c) => totalOf(c))),\n  );\n  const cells = Math.min(MAX_CELLS, widest);\n  const scale = cells / widest;\n\n  const counts = rows.map((r) => r.counts[period] ?? {});\n  const all = counts.reduce((n, c) => n + totalOf(c), 0);\n  const done = counts.reduce((n, c) => n + (c[doneId] ?? 0), 0);\n  const stuck = counts.reduce((n, c) => n + (c[stuckId] ?? 0), 0);\n\n  /** Each row as a list of status ids, one per cell, in status order. */\n  const cellsOf = (c: Record<string, number>) => {\n    const out: string[] = [];\n    const total = totalOf(c);\n    const used = Math.round(total * scale);\n    let carried = 0;\n    statuses.forEach((s, i) => {\n      const exact = (c[s.id] ?? 0) * scale;\n      const n =\n        i === statuses.length - 1\n          ? used - out.length\n          : Math.round(exact + carried);\n      carried += exact - n;\n      for (let k = 0; k < n && out.length < used; k += 1) out.push(s.id);\n    });\n    return out;\n  };\n\n  const readout =\n    row === null\n      ? `${done} of ${all} done across ${rows.length} teams in ${periods[period]}.`\n      : `${rows[row].label}: ${statuses\n          .map((s) => `${counts[row][s.id] ?? 0} ${s.label.toLowerCase()}`)\n          .join(\", \")}`;\n\n  return (\n    <section\n      className={`w-full rounded-2xl p-5 sm:p-6 ${className ?? \"\"}`}\n      style={{\n        background: pal.card,\n        boxShadow: `inset 0 0 0 1px ${pal.border}`,\n        color: pal.text,\n        fontFamily: CARD_FONT,\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-wrap items-start justify-between gap-x-8 gap-y-3\">\n        <div>\n          <h3 className=\"m-0 text-[17px] leading-[1.33] font-[590] tracking-[-0.012em]\">\n            {title}\n          </h3>\n          <p\n            className=\"m-0 mt-0.5 text-[13px] tracking-[-0.011em]\"\n            style={{ color: pal.sub }}\n          >\n            {subtitle}\n          </p>\n        </div>\n        <div className=\"grid grid-cols-3 gap-7\">\n          <Stat\n            value={all ? `${Math.round((done / all) * 100)}%` : \"–\"}\n            label=\"Done\"\n            pal={pal}\n          />\n          <Stat\n            value={String(stuck)}\n            label={statuses.find((s) => s.id === stuckId)?.label ?? \"Stuck\"}\n            pal={pal}\n          />\n          <Stat value={String(all)} label=\"Issues\" pal={pal} />\n        </div>\n      </div>\n\n      <ul\n        ref={boxRef}\n        className=\"m-0 mt-5 list-none p-0\"\n        aria-label={`${title}, ${periods[period]}`}\n      >\n        {rows.map((r, i) => {\n          const c = counts[i];\n          const list = cellsOf(c);\n          const total = totalOf(c);\n          const on = row === i;\n          return (\n            <li\n              key={r.label}\n              data-team={r.label}\n              tabIndex={0}\n              aria-label={`${r.label}: ${statuses.map((s) => `${c[s.id] ?? 0} ${s.label}`).join(\", \")}`}\n              onPointerEnter={() => setRow(i)}\n              onPointerLeave={() => setRow(null)}\n              onFocus={() => setRow(i)}\n              onBlur={() => setRow(null)}\n              className={`grid h-10 grid-cols-[84px_minmax(0,1fr)_44px] items-center gap-3 rounded-md px-2 sm:grid-cols-[120px_minmax(0,1fr)_56px] ${RING}`}\n              style={{\n                background: on ? pal.rowOn : \"transparent\",\n                borderTop: i ? `1px solid ${pal.border}` : \"none\",\n              }}\n            >\n              <span\n                className=\"truncate text-[13px] leading-[20px] font-[510] tracking-[-0.011em]\"\n                style={{ color: row === null || on ? pal.text : pal.sub }}\n              >\n                {r.label}\n              </span>\n              <span\n                aria-hidden=\"true\"\n                className=\"grid h-3.5\"\n                style={{\n                  gridTemplateColumns: `repeat(${cells}, minmax(0, 1fr))`,\n                  gap: cells > 36 ? 1.5 : 2,\n                }}\n              >\n                {Array.from({ length: cells }, (_, k) => {\n                  const id = list[k];\n                  const filled = seen && id !== undefined;\n                  const dim = only !== null && id !== only;\n                  return (\n                    <span\n                      key={k}\n                      className=\"block h-full rounded-[2px] motion-safe:transition-[background-color,opacity] motion-safe:duration-300\"\n                      style={{\n                        background: filled ? colorOf(id) : \"transparent\",\n                        boxShadow:\n                          id === undefined\n                            ? \"none\"\n                            : `inset 0 0 0 1px ${pal.empty}`,\n                        opacity: filled && dim ? 0.2 : 1,\n                        transitionDelay: `${k * 12}ms`,\n                      }}\n                    />\n                  );\n                })}\n              </span>\n              <span\n                className=\"text-right text-[12px] leading-[16px] tabular-nums\"\n                style={{ color: pal.sub }}\n              >\n                <span style={{ color: pal.text }}>{c[doneId] ?? 0}</span>/\n                {total}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n\n      <p\n        aria-live=\"polite\"\n        className=\"m-0 mt-2 h-5 truncate px-2 text-[12.5px] leading-[20px] tracking-[-0.008em]\"\n        style={{ color: row === null ? pal.sub : pal.soft }}\n      >\n        {readout}\n      </p>\n\n      <div className=\"mt-3 flex flex-wrap items-center justify-between gap-x-4 gap-y-2\">\n        <div\n          className=\"flex rounded-full p-0.5\"\n          style={{ background: pal.chip }}\n          role=\"radiogroup\"\n          aria-label=\"Sprint\"\n        >\n          {periods.map((p, i) => (\n            <button\n              key={p}\n              type=\"button\"\n              role=\"radio\"\n              aria-checked={i === period}\n              data-period={p}\n              onClick={() => {\n                setPeriod(i);\n                onPeriodChange?.(p);\n              }}\n              className={`h-7 cursor-pointer rounded-full border-0 px-3 text-[13px] font-[510] tracking-[-0.011em] whitespace-nowrap transition-colors ${RING}`}\n              style={{\n                background: i === period ? pal.chipOn : \"transparent\",\n                color: i === period ? pal.text : pal.sub,\n              }}\n            >\n              {p}\n            </button>\n          ))}\n        </div>\n        <div\n          role=\"group\"\n          aria-label=\"Highlight a status\"\n          className=\"flex flex-wrap gap-1\"\n        >\n          {statuses.map((s) => {\n            const on = only === s.id;\n            return (\n              <button\n                key={s.id}\n                type=\"button\"\n                data-status={s.id}\n                aria-pressed={on}\n                onClick={() => setOnly(on ? null : s.id)}\n                className={`flex h-7 cursor-pointer items-center gap-1.5 rounded-full border-0 px-2.5 text-[12px] leading-[16px] font-[510] whitespace-nowrap transition-colors ${RING}`}\n                style={{\n                  background: on ? pal.chipOn : \"transparent\",\n                  color: only === null || on ? pal.soft : pal.faint,\n                  boxShadow: on ? `inset 0 0 0 1px ${pal.border}` : \"none\",\n                }}\n              >\n                <Dot size={7} color={s.color ?? pal.faint} />\n                {s.label}\n              </button>\n            );\n          })}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}