{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-panel-05",
  "description": "A donut splitting a total into parts, with each value and share listed beside it.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/breakdown.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/ring.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/chart-panel/chart-panel-05.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { BreakdownTable } from '@/registry/components/dashboardblocks/breakdown'\nimport {\n  ChartTooltipContent,\n  type ChartValueFormatter,\n} from '@/registry/components/dashboardblocks/chart'\nimport { Ring } from '@/registry/components/dashboardblocks/ring'\nimport {\n  formatCompact,\n  formatNumber,\n  formatPercent,\n} from '@/registry/lib/dashboardblocks/format'\nimport { useState } from 'react'\nimport {\n  Cell,\n  Pie,\n  PieChart,\n  type PieSectorDataItem,\n  ResponsiveContainer,\n  Sector,\n  Tooltip,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Segment {\n  color: string\n  label: string\n  value: number\n}\n\ninterface ChartPanel5Props extends BlockStateProps {\n  description: string\n  formatter?: ChartValueFormatter\n  /** Leave out, or pass none, to show the empty state. */\n  segments?: Segment[]\n  title: string\n  totalLabel?: string\n}\n\nconst exampleProps: ChartPanel5Props = {\n  description: 'Where visitors came from in the last 30 days.',\n  segments: [\n    { color: 'var(--color-chart-2)', label: 'Organic search', value: 38_420 },\n    { color: 'var(--color-chart-3)', label: 'Direct', value: 21_760 },\n    { color: 'var(--color-chart-4)', label: 'Social', value: 12_180 },\n    {\n      color: 'color-mix(in oklab, var(--color-muted-foreground) 35%, transparent)',\n      label: 'Other',\n      value: 6_940,\n    },\n  ],\n  title: 'Traffic sources',\n  totalLabel: 'Visitors',\n}\n\nconst ACTIVE_GROWTH_PX = 4\n\nconst ChartPanel5 = (props: ChartPanel5Props) => {\n  const {\n    description,\n    formatter = (value) => formatNumber(value),\n    segments = [],\n    errorMessage,\n    status,\n    title,\n    totalLabel = 'Total',\n  } = props\n  const state = getBlockState(status, segments)\n  const [activeIndex, setActiveIndex] = useState<number | null>(null)\n  const total = segments.reduce((sum, segment) => sum + segment.value, 0)\n  const share = (value: number) =>\n    formatPercent(total === 0 ? 0 : value / total, { maximumFractionDigits: 0 })\n  const top = segments.reduce<Segment | undefined>(\n    (best, segment) => (best && best.value >= segment.value ? best : segment),\n    undefined,\n  )\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <div className='flex flex-col items-center gap-6 border-t pt-4 @lg:flex-row'>\n              {state ? (\n                <Ring className='size-44' percentage={0} radius={41} strokeWidth={12} />\n              ) : (\n                <div\n                  className='relative size-44 shrink-0'\n                  onPointerLeave={() => setActiveIndex(null)}\n                >\n                  <ResponsiveContainer width='100%' height='100%'>\n                    <PieChart\n                      aria-label={`${title} chart`}\n                      margin={{ top: 0, right: 0, bottom: 0, left: 0 }}\n                    >\n                      <Tooltip\n                        content={(tooltipProps) => (\n                          <ChartTooltipContent\n                            {...tooltipProps}\n                            valueFormatter={formatter}\n                          />\n                        )}\n                      />\n                      <Pie\n                        activeShape={(sector: PieSectorDataItem) => (\n                          <Sector\n                            {...sector}\n                            outerRadius={\n                              Number(sector.outerRadius ?? 0) + ACTIVE_GROWTH_PX\n                            }\n                          />\n                        )}\n                        cornerRadius={3}\n                        data={segments}\n                        dataKey='value'\n                        endAngle={-270}\n                        innerRadius='70%'\n                        nameKey='label'\n                        onMouseEnter={(_, index) => setActiveIndex(index)}\n                        outerRadius='94%'\n                        paddingAngle={1}\n                        startAngle={90}\n                        stroke='var(--color-background)'\n                        strokeWidth={2}\n                      >\n                        {segments.map((segment) => (\n                          <Cell key={segment.label} fill={segment.color} />\n                        ))}\n                      </Pie>\n                    </PieChart>\n                  </ResponsiveContainer>\n                  <div className='pointer-events-none absolute inset-0 flex flex-col items-center justify-center'>\n                    <span className='text-2xl font-light tracking-tight tabular-nums'>\n                      {formatCompact(total)}\n                    </span>\n                    <span className='text-muted-foreground text-xs'>{totalLabel}</span>\n                  </div>\n                </div>\n              )}\n              <div className='flex w-full min-w-0 flex-col gap-2'>\n                <BlockReady className='text-sm'>\n                  {top && (\n                    <p className='text-muted-foreground text-sm'>\n                      <span className='text-foreground font-medium'>{top.label}</span>{' '}\n                      brings {share(top.value)} of {totalLabel.toLowerCase()}.\n                    </p>\n                  )}\n                </BlockReady>\n                <BlockStateRows rows={4} />\n                {!state && (\n                  <BreakdownTable\n                    caption={`${title}: ${description}`}\n                    format={formatter}\n                    highlightIndex={activeIndex}\n                    labels={['Source', totalLabel, 'Share']}\n                    segments={segments}\n                  />\n                )}\n              </div>\n            </div>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { ChartPanel5, exampleProps as chartPanel5ExampleProps, type ChartPanel5Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/chart-panel/chart-panel-05.tsx"
    }
  ],
  "meta": {
    "shows": "A donut splitting a total into parts, with each value and share listed beside it.",
    "size": "half",
    "usedWith": [
      "breakdown-01",
      "leaderboard-01"
    ],
    "component": "ChartPanel5",
    "props": "{ description: string; formatter?: (value: number) => string; segments?: { color: string; label: string; value: number }[]; title: string; totalLabel?: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
