{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contributions-card",
  "title": "Contributions Card",
  "description": "A contribution-graph card: a headline total with delta, a row of stat tiles, a period switcher, and a year of daily activity.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "card",
    "tabs",
    "tooltip"
  ],
  "files": [
    {
      "path": "registry/dashboardcn/blocks/contributions-card.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { formatNumber, type NumberFormat } from \"@/registry/dashboardcn/lib/format\"\nimport {\n  Card,\n  CardAction,\n  CardContent,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\"\nimport {\n  ActivityHeatmap,\n  type ActivityHeatmapProps,\n} from \"@/registry/dashboardcn/ui/activity-heatmap\"\nimport { DeltaBadge } from \"@/registry/dashboardcn/ui/delta-badge\"\nimport { MetricValue } from \"@/registry/dashboardcn/ui/metric-value\"\nimport { PeriodTabs, type PeriodOption } from \"@/registry/dashboardcn/ui/period-tabs\"\n\nexport interface ContributionsStat {\n  label: string\n  /** Numbers are formatted with `format`; strings render as-is, e.g. \"12h 54m\". */\n  value: number | string\n  format?: NumberFormat\n  currency?: string\n  /** Suffix after the number, e.g. \"days\". */\n  unit?: string\n}\n\nexport interface ContributionsCardProps\n  extends Omit<React.ComponentProps<typeof Card>, \"children\"> {\n  title: string\n  /** Headline number. Defaults to the sum of `data`. */\n  value?: number\n  format?: NumberFormat\n  currency?: string\n  /** Change vs the previous period, as a fraction. */\n  delta?: number\n  deltaLabel?: string\n  invertDelta?: boolean\n  /** Tiles between the headline and the heatmap. */\n  stats?: ContributionsStat[]\n  /** Label above the heatmap, e.g. \"Activity\". */\n  heatmapLabel?: string\n  /** Options for the switcher next to the heatmap label. Omit to hide it. */\n  periods?: PeriodOption[]\n  period?: string\n  defaultPeriod?: string\n  onPeriodChange?: (period: string) => void\n  data: ActivityHeatmapProps[\"data\"]\n  endDate?: ActivityHeatmapProps[\"endDate\"]\n  weeks?: ActivityHeatmapProps[\"weeks\"]\n  startDate?: ActivityHeatmapProps[\"startDate\"]\n  /** Any CSS color for the heatmap. Defaults to chart-1. */\n  color?: ActivityHeatmapProps[\"color\"]\n  colors?: ActivityHeatmapProps[\"colors\"]\n  scale?: ActivityHeatmapProps[\"scale\"]\n  cellSize?: ActivityHeatmapProps[\"cellSize\"]\n  gap?: ActivityHeatmapProps[\"gap\"]\n  /** Label for the value in the tooltip, e.g. \"commits\". */\n  unit?: ActivityHeatmapProps[\"unit\"]\n  weekdayLabels?: ActivityHeatmapProps[\"weekdayLabels\"]\n  showLegend?: ActivityHeatmapProps[\"showLegend\"]\n  valueFormatter?: ActivityHeatmapProps[\"valueFormatter\"]\n  onCellClick?: ActivityHeatmapProps[\"onCellClick\"]\n  /** Slot in the top-right corner, e.g. a menu button. */\n  action?: React.ReactNode\n}\n\n/** A contribution-graph card: a headline total with delta, a row of stat tiles, and a year of daily activity. */\nfunction ContributionsCard({\n  title,\n  value,\n  format = \"number\",\n  currency,\n  delta,\n  deltaLabel,\n  invertDelta,\n  stats,\n  heatmapLabel = \"Activity\",\n  periods,\n  period,\n  defaultPeriod,\n  onPeriodChange,\n  data,\n  endDate,\n  weeks,\n  startDate,\n  color,\n  colors,\n  scale,\n  cellSize = 11,\n  gap = 3,\n  unit = \"contributions\",\n  weekdayLabels = \"none\",\n  showLegend = false,\n  valueFormatter,\n  onCellClick,\n  action,\n  className,\n  ...props\n}: ContributionsCardProps) {\n  const total = React.useMemo(\n    () => value ?? data.reduce((sum, datum) => sum + datum.value, 0),\n    [value, data]\n  )\n\n  return (\n    <Card\n      data-slot=\"contributions-card\"\n      className={cn(\"max-w-fit gap-5\", className)}\n      {...props}\n    >\n      <CardHeader>\n        <CardDescription>{title}</CardDescription>\n        <CardTitle className=\"flex flex-wrap items-center gap-2 text-3xl font-semibold tabular-nums tracking-tight\">\n          <MetricValue value={total} format={format} currency={currency} />\n          {delta !== undefined ? (\n            <DeltaBadge delta={delta} invert={invertDelta} variant=\"soft\" className=\"text-sm\" />\n          ) : null}\n        </CardTitle>\n        {deltaLabel ? <CardDescription>{deltaLabel}</CardDescription> : null}\n        {action ? <CardAction>{action}</CardAction> : null}\n      </CardHeader>\n      <CardContent className=\"flex flex-col gap-5\">\n        {stats?.length ? (\n          // The query context sits here rather than on the card so the card\n          // itself can still size to the heatmap — an inline-size container\n          // contributes no intrinsic width to its own box.\n          <div className=\"@container/card\">\n            <dl className=\"grid grid-cols-2 gap-2 @md/card:grid-cols-4\">\n              {stats.map((stat) => (\n                <div\n                  key={stat.label}\n                  className=\"flex min-w-0 flex-col gap-0.5 rounded-lg border px-3 py-2.5\"\n                >\n                  <dd className=\"order-1 truncate text-lg font-semibold tabular-nums tracking-tight\">\n                    {typeof stat.value === \"number\"\n                      ? formatNumber(stat.value, {\n                          format: stat.format,\n                          currency: stat.currency,\n                          maximumFractionDigits: stat.format ? undefined : 1,\n                        })\n                      : stat.value}\n                    {stat.unit ? (\n                      <span className=\"text-muted-foreground ml-1 text-sm font-normal\">\n                        {stat.unit}\n                      </span>\n                    ) : null}\n                  </dd>\n                  <dt className=\"text-muted-foreground order-2 truncate text-xs\">{stat.label}</dt>\n                </div>\n              ))}\n            </dl>\n          </div>\n        ) : null}\n        <div className=\"flex flex-col gap-3\">\n          {heatmapLabel || periods?.length ? (\n            <div className=\"flex flex-wrap items-center justify-between gap-3\">\n              {heatmapLabel ? (\n                <span className=\"text-sm font-medium\">{heatmapLabel}</span>\n              ) : null}\n              {periods?.length ? (\n                <PeriodTabs\n                  options={periods}\n                  value={period}\n                  defaultValue={defaultPeriod}\n                  onValueChange={onPeriodChange}\n                />\n              ) : null}\n            </div>\n          ) : null}\n          <ActivityHeatmap\n            data={data}\n            endDate={endDate}\n            weeks={weeks}\n            startDate={startDate}\n            color={color}\n            colors={colors}\n            scale={scale}\n            cellSize={cellSize}\n            gap={gap}\n            unit={unit}\n            weekdayLabels={weekdayLabels}\n            showLegend={showLegend}\n            valueFormatter={valueFormatter}\n            onCellClick={onCellClick}\n          />\n        </div>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { ContributionsCard }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/dashboardcn/ui/activity-heatmap.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { formatNumber } from \"@/registry/dashboardcn/lib/format\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\nexport interface ActivityDatum {\n  /** ISO date, YYYY-MM-DD. */\n  date: string\n  value: number\n}\n\nexport interface ActivityHeatmapProps extends React.ComponentProps<\"div\"> {\n  data: ActivityDatum[]\n  /** Last day shown. Defaults to today. */\n  endDate?: Date\n  /** Number of week columns. Ignored when `startDate` is set. */\n  weeks?: number\n  /** First day shown. Overrides `weeks`. */\n  startDate?: Date\n  /** Any CSS color. Levels are mixed from this and `--muted`. Defaults to chart-1. */\n  color?: string\n  /**\n   * Explicit color per level, from empty to most active.\n   * Overrides `color`. Length sets the number of levels.\n   */\n  colors?: string[]\n  /** How values map to levels. `sqrt` spreads out small values. */\n  scale?: \"linear\" | \"sqrt\"\n  /** Cell size in px. */\n  cellSize?: number\n  /** Gap between cells in px. */\n  gap?: number\n  valueFormatter?: (value: number) => string\n  /** Label for the value in the tooltip, e.g. \"events\". */\n  unit?: string\n  showMonthLabels?: boolean\n  /** Which weekday labels to show along the left edge. */\n  weekdayLabels?: \"mwf\" | \"all\" | \"none\"\n  showLegend?: boolean\n  /** Scroll to the most recent weeks when the grid overflows. */\n  scrollToEnd?: boolean\n  /** Replace the tooltip body. Return `null` to hide it for that cell. */\n  renderTooltip?: (datum: { date: Date; value: number }) => React.ReactNode\n  onCellClick?: (datum: { date: Date; value: number }) => void\n}\n\nconst DAY = 24 * 60 * 60 * 1000\nconst WEEKDAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"]\n\nfunction toKey(date: Date) {\n  const y = date.getFullYear()\n  const m = String(date.getMonth() + 1).padStart(2, \"0\")\n  const d = String(date.getDate()).padStart(2, \"0\")\n  return `${y}-${m}-${d}`\n}\n\nfunction startOfDay(date: Date) {\n  return new Date(date.getFullYear(), date.getMonth(), date.getDate())\n}\n\nfunction addDays(date: Date, days: number) {\n  return new Date(date.getTime() + days * DAY)\n}\n\nfunction levelFor(\n  value: number,\n  max: number,\n  levels: number,\n  scale: \"linear\" | \"sqrt\"\n) {\n  if (value <= 0 || max <= 0) return 0\n  let t = value / max\n  if (scale === \"sqrt\") t = Math.sqrt(t)\n  return Math.min(levels - 1, Math.max(1, Math.ceil(t * (levels - 1))))\n}\n\nfunction mixedColors(color: string, levels: number) {\n  return Array.from({ length: levels }, (_, level) => {\n    if (level === 0) return \"var(--muted)\"\n    const pct = Math.round(25 + ((level - 1) / (levels - 2)) * 75)\n    return `color-mix(in oklab, ${color} ${pct}%, var(--muted))`\n  })\n}\n\nfunction ActivityHeatmap({\n  data,\n  endDate,\n  weeks = 52,\n  startDate,\n  color = \"var(--chart-1)\",\n  colors,\n  scale = \"linear\",\n  cellSize = 12,\n  gap = 3,\n  valueFormatter = (value) => formatNumber(value),\n  unit = \"events\",\n  showMonthLabels = true,\n  weekdayLabels = \"mwf\",\n  showLegend = true,\n  scrollToEnd = true,\n  renderTooltip,\n  onCellClick,\n  className,\n  ...props\n}: ActivityHeatmapProps) {\n  const endTime = startOfDay(endDate ?? new Date()).getTime()\n  const startTime = startDate\n    ? startOfDay(startDate).getTime()\n    : endTime - (weeks * 7 - 1) * DAY\n\n  const values = React.useMemo(\n    () => new Map(data.map((d) => [d.date, d.value])),\n    [data]\n  )\n  const max = React.useMemo(\n    () => data.reduce((acc, d) => Math.max(acc, d.value), 0),\n    [data]\n  )\n\n  // Columns are full weeks, Sunday first. Days before `start` in the first\n  // week and after `end` in the last are left empty rather than filled in.\n  const columns = React.useMemo(() => {\n    const start = new Date(startTime)\n    const end = new Date(endTime)\n    const result: (Date | null)[][] = []\n    let cursor = addDays(start, -start.getDay())\n    while (cursor <= end) {\n      const week: (Date | null)[] = []\n      for (let i = 0; i < 7; i++) {\n        const day = addDays(cursor, i)\n        week.push(day < start || day > end ? null : day)\n      }\n      result.push(week)\n      cursor = addDays(cursor, 7)\n    }\n    return result\n  }, [startTime, endTime])\n\n  // Month labels span the weeks whose first shown day falls in that month.\n  const months = React.useMemo(() => {\n    const groups: { label: string; from: number; to: number }[] = []\n    const formatter = new Intl.DateTimeFormat(\"en-US\", { month: \"short\" })\n    columns.forEach((week, index) => {\n      const first = week.find((d): d is Date => d !== null)\n      if (!first) return\n      const key = `${first.getFullYear()}-${first.getMonth()}`\n      const last = groups[groups.length - 1]\n      if (last && last.label === key) {\n        last.to = index\n      } else {\n        groups.push({ label: key, from: index, to: index })\n      }\n    })\n    return groups\n      .filter((g) => g.to - g.from >= 1)\n      .map((g) => ({\n        ...g,\n        label: formatter.format(columns[g.from]!.find(Boolean) as Date),\n      }))\n  }, [columns])\n\n  const palette = colors && colors.length > 1 ? colors : mixedColors(color, 5)\n  const levels = palette.length\n\n  const dateFormatter = new Intl.DateTimeFormat(\"en-US\", {\n    weekday: \"short\",\n    month: \"short\",\n    day: \"numeric\",\n    year: \"numeric\",\n  })\n\n  const scrollRef = React.useRef<HTMLDivElement>(null)\n  React.useLayoutEffect(() => {\n    const node = scrollRef.current\n    if (!node || !scrollToEnd) return\n    node.scrollLeft = node.scrollWidth\n  }, [scrollToEnd, columns.length, cellSize, gap])\n\n  const hasHeader = showMonthLabels\n  const hasWeekdays = weekdayLabels !== \"none\"\n  const fontSize = Math.max(10, Math.min(12, cellSize))\n\n  return (\n    <div\n      data-slot=\"activity-heatmap\"\n      className={cn(\"flex min-w-0 flex-col gap-2 text-xs\", className)}\n      {...props}\n    >\n      <div className=\"flex min-w-0\">\n        {hasWeekdays ? (\n          <div\n            aria-hidden\n            className=\"grid shrink-0 pr-1\"\n            style={{\n              gap,\n              gridTemplateRows: `${hasHeader ? `${fontSize}px` : \"0px\"} repeat(7, ${cellSize}px)`,\n            }}\n          >\n            <div />\n            {WEEKDAYS.map((day, index) => (\n              <div\n                key={day}\n                className=\"text-muted-foreground flex items-center leading-none whitespace-nowrap\"\n                style={{ fontSize }}\n              >\n                {weekdayLabels === \"all\" || index % 2 === 1 ? day : \"\"}\n              </div>\n            ))}\n          </div>\n        ) : null}\n        <div\n          ref={scrollRef}\n          className=\"min-w-0 flex-1 overflow-x-auto overscroll-x-contain [scrollbar-width:thin] [scrollbar-color:color-mix(in_oklab,var(--foreground)_20%,transparent)_transparent]\"\n        >\n          <TooltipProvider delayDuration={100} skipDelayDuration={0}>\n            <div\n              role=\"group\"\n              aria-label=\"Activity heatmap\"\n              className=\"grid w-max\"\n              style={{\n                gap,\n                gridTemplateColumns: `repeat(${columns.length}, ${cellSize}px)`,\n                gridTemplateRows: `${hasHeader ? `${fontSize}px` : \"0px\"} repeat(7, ${cellSize}px)`,\n              }}\n            >\n              {hasHeader\n                ? months.map((month) => (\n                    <div\n                      key={`${month.from}-${month.label}`}\n                      className=\"text-muted-foreground self-end leading-none whitespace-nowrap\"\n                      style={{\n                        gridRow: 1,\n                        gridColumn: `${month.from + 1} / ${month.to + 2}`,\n                        fontSize,\n                      }}\n                    >\n                      {month.label}\n                    </div>\n                  ))\n                : null}\n\n              {columns.map((week, weekIndex) =>\n                week.map((day, dayIndex) => {\n                  const style = {\n                    gridColumn: weekIndex + 1,\n                    gridRow: dayIndex + 2,\n                  }\n                  if (!day) {\n                    return <div key={dayIndex} aria-hidden style={style} />\n                  }\n                  const value = values.get(toKey(day)) ?? 0\n                  const level = levelFor(value, max, levels, scale)\n                  const datum = { date: day, value }\n                  const body = renderTooltip ? (\n                    renderTooltip(datum)\n                  ) : (\n                    <>\n                      <span className=\"font-medium tabular-nums\">\n                        {valueFormatter(value)} {unit}\n                      </span>\n                      <span className=\"text-background/70 block\">\n                        {dateFormatter.format(day)}\n                      </span>\n                    </>\n                  )\n                  const label = `${valueFormatter(value)} ${unit} on ${dateFormatter.format(day)}`\n\n                  const cell = (\n                    <button\n                      type=\"button\"\n                      aria-label={label}\n                      data-level={level}\n                      data-date={toKey(day)}\n                      onClick={onCellClick ? () => onCellClick(datum) : undefined}\n                      className={cn(\n                        \"focus-visible:ring-ring/60 ring-inset rounded-[2px] outline-none transition-[filter] duration-100 hover:brightness-110 focus-visible:ring-2 dark:hover:brightness-125\",\n                        \"inset-ring-foreground/6 inset-ring\",\n                        onCellClick ? \"cursor-pointer\" : \"cursor-default\"\n                      )}\n                      style={{ ...style, backgroundColor: palette[level] }}\n                    />\n                  )\n\n                  if (body === null) {\n                    return <React.Fragment key={dayIndex}>{cell}</React.Fragment>\n                  }\n\n                  return (\n                    <Tooltip key={dayIndex}>\n                      <TooltipTrigger asChild>{cell}</TooltipTrigger>\n                      <TooltipContent sideOffset={4} className=\"text-left\">\n                        {body}\n                      </TooltipContent>\n                    </Tooltip>\n                  )\n                })\n              )}\n            </div>\n          </TooltipProvider>\n        </div>\n      </div>\n\n      {showLegend ? (\n        <div\n          className=\"text-muted-foreground flex items-center justify-end gap-1\"\n          style={{ fontSize }}\n        >\n          <span className=\"mr-0.5\">Less</span>\n          {palette.map((fill, level) => (\n            <span\n              key={level}\n              className=\"inset-ring-foreground/6 inset-ring rounded-[2px]\"\n              style={{\n                width: cellSize,\n                height: cellSize,\n                backgroundColor: fill,\n              }}\n            />\n          ))}\n          <span className=\"ml-0.5\">More</span>\n        </div>\n      ) : null}\n    </div>\n  )\n}\n\nexport { ActivityHeatmap }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/delta-badge.tsx",
      "content": "import * as React from \"react\"\nimport { Minus, TrendingDown, TrendingUp } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { formatDelta } from \"@/registry/dashboardcn/lib/format\"\n\nexport type DeltaDirection = \"up\" | \"down\" | \"flat\"\n\nexport function getDeltaDirection(delta: number | undefined): DeltaDirection {\n  if (delta === undefined || delta === 0 || !Number.isFinite(delta)) return \"flat\"\n  return delta > 0 ? \"up\" : \"down\"\n}\n\nconst directionIcon: Record<DeltaDirection, React.ElementType> = {\n  up: TrendingUp,\n  down: TrendingDown,\n  flat: Minus,\n}\n\nexport interface DeltaBadgeProps extends React.ComponentProps<\"span\"> {\n  /** Fractional change, e.g. 0.124 for +12.4%. */\n  delta: number\n  /** Treat a decrease as good and an increase as bad (churn, latency, errors). */\n  invert?: boolean\n  variant?: \"outline\" | \"soft\" | \"text\"\n  showIcon?: boolean\n}\n\nfunction DeltaBadge({\n  delta,\n  invert = false,\n  variant = \"outline\",\n  showIcon = true,\n  className,\n  children,\n  ...props\n}: DeltaBadgeProps) {\n  const direction = getDeltaDirection(delta)\n  const positive = direction === \"flat\" ? null : (direction === \"up\") !== invert\n  const Icon = directionIcon[direction]\n\n  return (\n    <span\n      data-slot=\"delta-badge\"\n      data-direction={direction}\n      data-positive={positive}\n      className={cn(\n        \"inline-flex items-center gap-1 text-xs font-medium tabular-nums\",\n        variant === \"outline\" && \"rounded-md border px-1.5 py-0.5\",\n        variant === \"soft\" && \"rounded-md px-1.5 py-0.5\",\n        variant === \"soft\" && positive === true && \"bg-emerald-500/10\",\n        variant === \"soft\" && positive === false && \"bg-red-500/10\",\n        variant === \"soft\" && positive === null && \"bg-muted\",\n        positive === true && \"text-emerald-600 dark:text-emerald-400\",\n        positive === false && \"text-red-600 dark:text-red-400\",\n        positive === null && \"text-muted-foreground\",\n        className\n      )}\n      {...props}\n    >\n      {showIcon ? <Icon className=\"size-3\" aria-hidden=\"true\" /> : null}\n      {children ?? formatDelta(delta)}\n    </span>\n  )\n}\n\nexport { DeltaBadge }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/metric-value.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { formatNumber, type NumberFormat } from \"@/registry/dashboardcn/lib/format\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\n/** Values at or above this are abbreviated by default. */\nexport const DEFAULT_COMPACT_FROM = 100_000\n\nexport interface MetricValueProps extends Omit<React.ComponentProps<\"span\">, \"children\"> {\n  /** Strings render as-is. */\n  value: number | string\n  format?: NumberFormat\n  currency?: string\n  maximumFractionDigits?: number\n  /** Values at or above this are abbreviated (e.g. $158K) with the full value in a tooltip. Set to Infinity to always show the full value. */\n  compactFrom?: number\n  /** Text after the number, e.g. a unit. */\n  suffix?: React.ReactNode\n}\n\n/** A formatted number. Large values are abbreviated and reveal the full value on hover. */\nfunction MetricValue({\n  value,\n  format,\n  currency,\n  maximumFractionDigits,\n  compactFrom = DEFAULT_COMPACT_FROM,\n  suffix,\n  className,\n  ...props\n}: MetricValueProps) {\n  const classes = cn(\"tabular-nums\", className)\n\n  if (typeof value !== \"number\") {\n    return (\n      <span data-slot=\"metric-value\" className={classes} {...props}>\n        {value}\n        {suffix}\n      </span>\n    )\n  }\n\n  const full = formatNumber(value, { format, currency, maximumFractionDigits })\n  const abbreviate = format !== \"percent\" && Math.abs(value) >= compactFrom\n  if (!abbreviate) {\n    return (\n      <span data-slot=\"metric-value\" className={classes} {...props}>\n        {full}\n        {suffix}\n      </span>\n    )\n  }\n\n  return (\n    <TooltipProvider>\n      <Tooltip>\n        <TooltipTrigger asChild>\n          <span\n            data-slot=\"metric-value\"\n            data-compact=\"\"\n            className={cn(classes, \"cursor-default\")}\n            {...props}\n          >\n            {formatNumber(value, { format, currency, compact: true })}\n            {suffix}\n          </span>\n        </TooltipTrigger>\n        <TooltipContent className=\"tabular-nums\">\n          {full}\n          {suffix}\n        </TooltipContent>\n      </Tooltip>\n    </TooltipProvider>\n  )\n}\n\nexport { MetricValue }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/period-tabs.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Tabs, TabsList, TabsTrigger } from \"@/components/ui/tabs\"\n\nexport interface PeriodOption {\n  value: string\n  label: string\n}\n\nexport const defaultPeriods: PeriodOption[] = [\n  { value: \"week\", label: \"Week\" },\n  { value: \"month\", label: \"Month\" },\n  { value: \"year\", label: \"Year\" },\n]\n\nexport interface PeriodTabsProps\n  extends Omit<React.ComponentProps<typeof Tabs>, \"children\"> {\n  options?: PeriodOption[]\n  size?: \"sm\" | \"default\"\n  /** Slide a single pill between tabs instead of swapping backgrounds. */\n  animated?: boolean\n}\n\ninterface IndicatorRect {\n  left: number\n  top: number\n  width: number\n  height: number\n}\n\n/** Small segmented control for switching a chart's time range. */\nfunction PeriodTabs({\n  options = defaultPeriods,\n  size = \"sm\",\n  animated = false,\n  className,\n  value,\n  defaultValue,\n  onValueChange,\n  ...props\n}: PeriodTabsProps) {\n  const listRef = React.useRef<HTMLDivElement>(null)\n  const [internalValue, setInternalValue] = React.useState(\n    defaultValue ?? options[0]?.value\n  )\n  const active = value ?? internalValue\n  const [rect, setRect] = React.useState<IndicatorRect | null>(null)\n\n  const measure = React.useCallback(() => {\n    const list = listRef.current\n    if (!list) return\n    const trigger = list.querySelector<HTMLElement>('[data-state=\"active\"]')\n    if (!trigger) return\n    setRect({\n      left: trigger.offsetLeft,\n      top: trigger.offsetTop,\n      width: trigger.offsetWidth,\n      height: trigger.offsetHeight,\n    })\n  }, [])\n\n  React.useLayoutEffect(() => {\n    if (!animated) return\n    measure()\n  }, [animated, active, options, size, measure])\n\n  React.useEffect(() => {\n    if (!animated || !listRef.current) return\n    const observer = new ResizeObserver(measure)\n    observer.observe(listRef.current)\n    return () => observer.disconnect()\n  }, [animated, measure])\n\n  return (\n    <Tabs\n      data-slot=\"period-tabs\"\n      className={cn(\"w-fit\", className)}\n      value={value}\n      defaultValue={defaultValue}\n      onValueChange={(next) => {\n        setInternalValue(next)\n        onValueChange?.(next)\n      }}\n      {...props}\n    >\n      <TabsList\n        ref={listRef}\n        className={cn(\n          \"relative\",\n          size === \"sm\" && \"group-data-[orientation=horizontal]/tabs:h-8 p-1\"\n        )}\n      >\n        {animated && rect ? (\n          <span\n            aria-hidden\n            data-slot=\"period-tabs-indicator\"\n            className=\"pointer-events-none absolute rounded-md bg-background shadow-sm transition-[left,top,width,height] duration-300 ease-[cubic-bezier(0.25,1,0.5,1)] motion-reduce:transition-none dark:border dark:border-input dark:bg-input/30\"\n            style={rect}\n          />\n        ) : null}\n        {options.map((option) => (\n          <TabsTrigger\n            key={option.value}\n            value={option.value}\n            className={cn(\n              size === \"sm\" && \"h-6 px-2.5 text-xs\",\n              animated &&\n                \"relative z-10 data-[state=active]:bg-transparent group-data-[variant=default]/tabs-list:data-[state=active]:shadow-none dark:data-[state=active]:border-transparent dark:data-[state=active]:bg-transparent\"\n            )}\n          >\n            {option.label}\n          </TabsTrigger>\n        ))}\n      </TabsList>\n    </Tabs>\n  )\n}\n\nexport { PeriodTabs }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/lib/format.ts",
      "content": "export type NumberFormat = \"number\" | \"compact\" | \"currency\" | \"percent\"\n\nexport interface FormatNumberOptions {\n  format?: NumberFormat\n  /** ISO 4217 code, used when format is \"currency\". Defaults to USD. */\n  currency?: string\n  locale?: string\n  maximumFractionDigits?: number\n  /** Abbreviate large values, e.g. \"$158K\" instead of \"$158,143\". */\n  compact?: boolean\n}\n\nconst formatterCache = new Map<string, Intl.NumberFormat>()\n\nfunction getFormatter(locale: string, options: Intl.NumberFormatOptions) {\n  const key = locale + JSON.stringify(options)\n  let formatter = formatterCache.get(key)\n  if (!formatter) {\n    formatter = new Intl.NumberFormat(locale, options)\n    formatterCache.set(key, formatter)\n  }\n  return formatter\n}\n\n/**\n * Format a metric value for display.\n *\n * formatNumber(1234567)                          -> \"1,234,567\"\n * formatNumber(1234567, { format: \"compact\" })   -> \"1.2M\"\n * formatNumber(48.2, { format: \"currency\" })     -> \"$48.20\"\n * formatNumber(158143, { format: \"currency\", compact: true }) -> \"$158K\"\n * formatNumber(0.124, { format: \"percent\" })     -> \"12.4%\"\n */\nexport function formatNumber(\n  value: number,\n  {\n    format = \"number\",\n    currency = \"USD\",\n    locale = \"en-US\",\n    maximumFractionDigits,\n    compact = false,\n  }: FormatNumberOptions = {}\n): string {\n  if (!Number.isFinite(value)) return \"—\"\n\n  // Compact values keep three significant digits: $158K, $1.23M, 41.2K.\n  const compactOptions: Intl.NumberFormatOptions = compact\n    ? maximumFractionDigits === undefined\n      ? { notation: \"compact\", maximumSignificantDigits: 3 }\n      : { notation: \"compact\", maximumFractionDigits }\n    : {}\n  switch (format) {\n    case \"compact\":\n      return getFormatter(locale, {\n        notation: \"compact\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value)\n    case \"currency\":\n      return getFormatter(locale, {\n        style: \"currency\",\n        currency,\n        maximumFractionDigits: maximumFractionDigits ?? 2,\n        ...compactOptions,\n      }).format(value)\n    case \"percent\":\n      return getFormatter(locale, {\n        style: \"percent\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value)\n    default:\n      return getFormatter(locale, {\n        maximumFractionDigits: maximumFractionDigits ?? 0,\n        ...compactOptions,\n      }).format(value)\n  }\n}\n\n/**\n * Format a fractional change as a signed percentage.\n *\n * formatDelta(0.124)  -> \"+12.4%\"\n * formatDelta(-0.03)  -> \"-3.0%\"\n * formatDelta(0)      -> \"0.0%\"\n */\nexport function formatDelta(delta: number, locale = \"en-US\"): string {\n  if (!Number.isFinite(delta)) return \"—\"\n  return getFormatter(locale, {\n    style: \"percent\",\n    signDisplay: \"exceptZero\",\n    maximumFractionDigits: 1,\n    minimumFractionDigits: 1,\n  }).format(delta)\n}\n\n/**\n * Fractional change between two values. Returns 0 when there is no baseline.\n */\nexport function computeDelta(current: number, previous: number): number {\n  if (!previous) return 0\n  return (current - previous) / Math.abs(previous)\n}\n",
      "type": "registry:lib"
    }
  ],
  "categories": [
    "dashboard",
    "charts"
  ],
  "type": "registry:block"
}