{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lollipop-ranking-chart",
  "title": "Lollipop Ranking Chart",
  "description": "A ranked list of thin lollipops that reorders itself: switch period and the rows glide to their new places, with each one showing how far it climbed or fell.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/lollipop-ranking-chart/lollipop-ranking-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LollipopItem {\n  label: string;\n  /** One value per period, in the same order as periods. */\n  values: number[];\n}\n\nexport interface LollipopRankingChartProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  items?: LollipopItem[];\n  /** Oldest first. Rank changes compare each period with the one before it. */\n  periods?: string[];\n  /** Index of the period shown first. Defaults to the latest. */\n  defaultPeriod?: number;\n  /** Colour of the leader's head. */\n  color?: string;\n  /** Height of each row, in px. */\n  rowHeight?: number;\n  formatValue?: (value: number) => string;\n  onPeriodChange?: (period: string) => void;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    surface: \"#0F1011\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    tip: \"#161718\",\n    tipShadow: \"0 4px 24px rgba(0,0,0,0.4)\",\n    chip: \"rgba(255,255,255,0.05)\",\n    chipOn: \"rgba(255,255,255,0.1)\",\n    accent: \"#5E6AD2\",\n    line: \"rgba(255,255,255,0.16)\",\n    up: \"#27A644\",\n    down: \"#EB5757\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    surface: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    tip: \"#FFFFFF\",\n    tipShadow: \"0 3px 12px rgba(8,9,10,0.09)\",\n    chip: \"rgba(8,9,10,0.04)\",\n    chipOn: \"#FFFFFF\",\n    accent: \"#5E6AD2\",\n    line: \"rgba(8,9,10,0.18)\",\n    up: \"#27A644\",\n    down: \"#EB5757\",\n  },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst CARD_FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\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=\"text-left sm:text-right\">\n      <p className=\"m-0 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]\"\n        style={{ color: pal.sub }}\n      >\n        {label}\n      </p>\n    </div>\n  );\n}\n\nfunction Pills({\n  label,\n  options,\n  value,\n  onChange,\n  pal,\n}: {\n  label: string;\n  options: string[];\n  value: number;\n  onChange: (index: number) => void;\n  pal: Palette;\n}) {\n  return (\n    <div\n      className=\"flex rounded-full p-0.5\"\n      style={{ background: pal.chip }}\n      role=\"radiogroup\"\n      aria-label={label}\n    >\n      {options.map((option, i) => (\n        <button\n          key={option}\n          type=\"button\"\n          role=\"radio\"\n          aria-checked={i === value}\n          onClick={() => onChange(i)}\n          className=\"h-7 cursor-pointer rounded-full px-3 text-[13px] font-[510] tracking-[-0.011em] transition-colors outline-none focus-visible:ring-2\"\n          style={{\n            background: i === value ? pal.chipOn : \"transparent\",\n            color: i === value ? pal.text : pal.sub,\n          }}\n        >\n          {option}\n        </button>\n      ))}\n    </div>\n  );\n}\n\nconst PERIODS = [\"Q1\", \"Q2\", \"Q3\", \"Q4\"];\n\nconst ITEMS: LollipopItem[] = [\n  { label: \"Integrations\", values: [212, 248, 301, 356] },\n  { label: \"Reporting\", values: [268, 281, 272, 318] },\n  { label: \"Automation\", values: [96, 174, 262, 342] },\n  { label: \"Mobile app\", values: [241, 236, 228, 204] },\n  { label: \"SSO\", values: [188, 212, 204, 196] },\n  { label: \"Search\", values: [154, 138, 176, 231] },\n  { label: \"Exports\", values: [176, 162, 141, 128] },\n  { label: \"Themes\", values: [62, 88, 112, 96] },\n];\n\nconst FORMAT = (n: number) => Math.round(n).toLocaleString(\"en-US\");\n\n/** The longest stick stops short of the edge, so its value still fits after the head. */\nconst REACH = 88;\nconst EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\n\nfunction rankOf(items: LollipopItem[], period: number) {\n  const order = items\n    .map((item, i) => ({ i, value: item.values[period] ?? 0 }))\n    .sort((a, b) => b.value - a.value);\n  const ranks = new Array<number>(items.length);\n  order.forEach((o, rank) => {\n    ranks[o.i] = rank;\n  });\n  return ranks;\n}\n\nexport function LollipopRankingChart({\n  theme = \"dark\",\n  title = \"Customer requests\",\n  subtitle = \"What people ask for most, by quarter.\",\n  items = ITEMS,\n  periods = PERIODS,\n  defaultPeriod,\n  color,\n  rowHeight = 34,\n  formatValue = FORMAT,\n  onPeriodChange,\n  className,\n  style,\n  ...props\n}: LollipopRankingChartProps) {\n  const pal = PALETTES[theme];\n  const accent = color ?? pal.accent;\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const [period, setPeriod] = React.useState(\n    defaultPeriod ?? Math.max(0, periods.length - 1),\n  );\n  const [active, setActive] = React.useState<number | 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 ranks = rankOf(items, period);\n  const before = period > 0 ? rankOf(items, period - 1) : null;\n  // One scale across every period, so a stick only moves when its value does.\n  const max = Math.max(1, ...items.flatMap((item) => item.values));\n  const sorted = [...items].sort(\n    (a, b) => (b.values[period] ?? 0) - (a.values[period] ?? 0),\n  );\n  const lead = sorted[0];\n  const second = sorted[1];\n  const total = items.reduce((n, item) => n + (item.values[period] ?? 0), 0);\n  const gap = (lead?.values[period] ?? 0) - (second?.values[period] ?? 0);\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=\"flex gap-7\">\n          <Stat value={lead?.label ?? \"—\"} label=\"Most requested\" pal={pal} />\n          <Stat value={`+${formatValue(gap)}`} label=\"Lead\" pal={pal} />\n          <Stat value={formatValue(total)} label=\"Requests\" pal={pal} />\n        </div>\n      </div>\n\n      {!items.length ? (\n        <p className=\"py-16 text-center text-sm\" style={{ color: pal.sub }}>\n          No data available.\n        </p>\n      ) : (\n        <div\n          ref={boxRef}\n          className=\"relative mt-5\"\n          style={{ height: items.length * rowHeight }}\n          role=\"list\"\n          aria-label={`${title}, ${periods[period]}`}\n        >\n          {items.map((item, i) => {\n            const rank = ranks[i];\n            const value = item.values[period] ?? 0;\n            const length = seen ? (value / max) * REACH : 0;\n            const moved = before ? before[i] - rank : 0;\n            const on = active === i;\n            const first = rank === 0;\n            return (\n              <div\n                key={item.label}\n                role=\"listitem\"\n                tabIndex={0}\n                aria-label={`${rank + 1}. ${item.label}, ${formatValue(value)}${moved ? `, ${moved > 0 ? \"up\" : \"down\"} ${Math.abs(moved)}` : \"\"}`}\n                onPointerEnter={() => setActive(i)}\n                onPointerLeave={() => setActive(null)}\n                onFocus={() => setActive(i)}\n                onBlur={() => setActive(null)}\n                className=\"absolute inset-x-0 top-0 flex items-center gap-2 rounded-lg outline-none motion-safe:transition-transform motion-safe:duration-700 sm:gap-3\"\n                style={{\n                  height: rowHeight,\n                  transform: `translateY(${rank * rowHeight}px)`,\n                  transitionTimingFunction: EASE,\n                  background: on ? pal.chip : \"transparent\",\n                }}\n              >\n                <span\n                  className=\"w-5 shrink-0 text-right text-[12px] tabular-nums\"\n                  style={{ color: pal.faint }}\n                >\n                  {rank + 1}\n                </span>\n                <span\n                  className=\"w-[84px] shrink-0 truncate text-[13px] font-[510] tracking-[-0.011em] sm:w-[104px]\"\n                  style={{ color: first ? pal.text : pal.soft }}\n                >\n                  {item.label}\n                </span>\n                <span className=\"relative h-full min-w-0 flex-1\">\n                  <span\n                    className=\"absolute top-1/2 left-0 h-px -translate-y-1/2 motion-safe:transition-[width] motion-safe:duration-700\"\n                    style={{\n                      width: `${length}%`,\n                      background: pal.line,\n                      transitionTimingFunction: EASE,\n                    }}\n                  />\n                  <span\n                    className=\"absolute top-1/2 flex -translate-y-1/2 items-center gap-2 motion-safe:transition-[left] motion-safe:duration-700\"\n                    style={{\n                      left: `${length}%`,\n                      transitionTimingFunction: EASE,\n                    }}\n                  >\n                    <span\n                      className=\"-ml-[5px] size-2.5 rounded-full transition-colors duration-300\"\n                      style={{ background: first || on ? accent : pal.sub }}\n                    />\n                    <span\n                      className=\"text-[12px] tracking-[-0.011em] tabular-nums\"\n                      style={{ color: first ? pal.text : pal.sub }}\n                    >\n                      {formatValue(value)}\n                    </span>\n                  </span>\n                </span>\n                <span\n                  className=\"flex w-9 shrink-0 items-center justify-end gap-1 pr-1 text-[12px] tabular-nums\"\n                  style={{\n                    color:\n                      moved > 0 ? pal.up : moved < 0 ? pal.down : pal.faint,\n                  }}\n                >\n                  {moved !== 0 && (\n                    <svg\n                      width=\"8\"\n                      height=\"7\"\n                      viewBox=\"0 0 8 7\"\n                      fill=\"currentColor\"\n                      aria-hidden=\"true\"\n                      style={{\n                        transform: moved < 0 ? \"rotate(180deg)\" : undefined,\n                      }}\n                    >\n                      <path d=\"M4 0 8 7H0Z\" />\n                    </svg>\n                  )}\n                  {moved === 0 ? \"–\" : Math.abs(moved)}\n                </span>\n              </div>\n            );\n          })}\n        </div>\n      )}\n\n      <div className=\"mt-3 flex flex-wrap items-center justify-between gap-2\">\n        <Pills\n          label=\"Period\"\n          options={periods}\n          value={period}\n          onChange={(i) => {\n            setPeriod(i);\n            onPeriodChange?.(periods[i]);\n          }}\n          pal={pal}\n        />\n        <span className=\"text-[12px]\" style={{ color: pal.sub }}>\n          {before ? `Rank change vs ${periods[period - 1]}` : \"First period\"}\n        </span>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}