{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "timeline-04",
  "description": "Each phase's plan as a dashed outline with what actually happened as a bar beneath it, and how many days it slipped.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json",
    "https://www.dashboardblocks.com/r/radix/timeline.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/timeline/timeline-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { ChartPlaceholder, useChartId } from '@/registry/components/dashboardblocks/chart'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport {\n  TIMELINE_AXIS_HEIGHT,\n  TimelineChart,\n  formatTimelineDate,\n  formatTimelineRange,\n  getDaysBetween,\n  getTimelineTicks,\n} from '@/registry/components/dashboardblocks/timeline'\nimport { formatNumber, formatSigned } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Phase {\n  actual?: { end?: Date; start: Date }\n  id: string\n  label: string\n  planned: { end: Date; start: Date }\n}\n\ninterface Timeline4Props extends BlockStateProps {\n  /** What the plan is for, such as a project name. */\n  description: string\n  end: Date\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  /** In order. Leave out, or pass none, to show the empty state. */\n  phases?: Phase[]\n  start: Date\n  title: string\n}\n\nconst date = (month: number, day: number) => new Date(Date.UTC(2026, month - 1, day))\n\nconst exampleProps: Timeline4Props = {\n  description: 'Billing migration',\n  end: date(11, 30),\n  now: date(9, 26),\n  phases: [\n    {\n      actual: { end: date(7, 17), start: date(7, 1) },\n      id: 'discovery',\n      label: 'Discovery',\n      planned: { end: date(7, 14), start: date(7, 1) },\n    },\n    {\n      actual: { end: date(8, 21), start: date(7, 20) },\n      id: 'design',\n      label: 'Design',\n      planned: { end: date(8, 7), start: date(7, 15) },\n    },\n    {\n      actual: { start: date(8, 24) },\n      id: 'build',\n      label: 'Build',\n      planned: { end: date(9, 25), start: date(8, 10) },\n    },\n    {\n      id: 'migration',\n      label: 'Data migration',\n      planned: { end: date(10, 23), start: date(9, 28) },\n    },\n    {\n      id: 'rollout',\n      label: 'Rollout',\n      planned: { end: date(11, 20), start: date(10, 26) },\n    },\n  ],\n  start: date(7, 1),\n  title: 'Plan vs actual',\n}\n\nconst ROW_HEIGHT = 36\nconst PLACEHOLDER_ROWS = 5\nconst BAR_HEIGHT = 12\nconst MIN_BAR_WIDTH = 4\n\nfunction describeSlip(slip: number) {\n  if (slip === 0) return 'On time'\n  const days = `${Math.abs(slip)} ${Math.abs(slip) === 1 ? 'day' : 'days'}`\n  return slip > 0 ? `${days} late` : `${days} early`\n}\n\nconst formatDays = (days: number) => `${formatNumber(days)}d`\n\nfunction Slip({ slip }: { slip: number | null }) {\n  if (slip === null) {\n    return <span className='text-muted-foreground text-right text-sm'>—</span>\n  }\n  return (\n    <StatusLabel\n      variant='text'\n      className='text-right tabular-nums'\n      tone={slip > 0 ? 'bad' : 'good'}\n    >\n      {slip === 0 ? 'On time' : formatSigned(slip, formatDays)}\n    </StatusLabel>\n  )\n}\n\nconst Timeline4 = (props: Timeline4Props) => {\n  const { description, end, now, phases = [], start, errorMessage, status, title } = props\n  const id = useChartId()\n  const state = getBlockState(status, phases)\n  const ticks = getTimelineTicks(start, end, 'month')\n  const projections = phases.map((phase) => {\n    if (!phase.actual || phase.actual.end) return null\n    const planned = phase.planned.end.getTime() - phase.planned.start.getTime()\n    return new Date(Math.max(now.getTime(), phase.actual.start.getTime() + planned))\n  })\n  const slips = phases.map((phase, index) => {\n    const finish = phase.actual?.end ?? projections[index]\n    return finish ? getDaysBetween(phase.planned.end, finish) : null\n  })\n  const current = phases.findIndex((phase) => phase.actual && !phase.actual.end)\n  const latest = [...slips].reverse().find((slip) => slip !== null) ?? 0\n  const describe = (phase: Phase, index: number) => {\n    const projection = projections[index]\n    const planned = `planned ${formatTimelineRange(phase.planned.start, phase.planned.end)}`\n    if (!phase.actual) return `${planned}, not started`\n    if (phase.actual.end)\n      return `${planned}, actual ${formatTimelineRange(phase.actual.start, phase.actual.end)}`\n    return `${planned}, actual from ${formatTimelineDate(phase.actual.start)}, still running${projection ? `, projected to end ${formatTimelineDate(projection)}` : ''}`\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'>\n                {description}. Each phase&apos;s plan is dashed, with what happened below\n                it.\n              </p>\n            </header>\n            {state && (\n              <div className='flex flex-col gap-1'>\n                <KPIValue />\n                {state === 'loading' && <BlockStateText className='text-sm' />}\n              </div>\n            )}\n            {state === 'loading' && (\n              <div className='border-t pt-4'>\n                <ChartPlaceholder\n                  height={TIMELINE_AXIS_HEIGHT + PLACEHOLDER_ROWS * ROW_HEIGHT}\n                />\n              </div>\n            )}\n            {!state && (\n              <div className='flex flex-col gap-1'>\n                <p className='text-4xl font-light tracking-tight tabular-nums'>\n                  {Math.abs(latest)}\n                  <span className='text-muted-foreground ml-1 text-base font-normal tracking-normal'>\n                    {Math.abs(latest) === 1 ? 'day' : 'days'}\n                  </span>\n                </p>\n                <p className='text-sm'>\n                  <StatusLabel variant='text' tone={latest > 0 ? 'bad' : 'good'}>\n                    {latest > 0\n                      ? 'Behind plan'\n                      : latest < 0\n                        ? 'Ahead of plan'\n                        : 'On plan'}\n                  </StatusLabel>\n                  <span className='text-muted-foreground'>\n                    {current >= 0\n                      ? `, if ${phases[current].label.toLowerCase()} takes as long as planned.`\n                      : '.'}\n                  </span>\n                </p>\n              </div>\n            )}\n            {!state && (\n              <div\n                role='region'\n                aria-label={title}\n                // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- a scrolling region must be focusable so keyboard users can reach the columns that don't fit\n                tabIndex={0}\n                className='focus-visible:ring-ring/50 overflow-x-auto rounded-sm border-t pt-4 pb-1 outline-none [scrollbar-width:thin] focus-visible:ring-3'\n              >\n                <div className='grid min-w-[34rem] grid-cols-[7rem_minmax(0,1fr)_4rem] gap-x-3'>\n                  <ol className='bg-background sticky left-0 z-20 flex flex-col'>\n                    <li aria-hidden style={{ height: TIMELINE_AXIS_HEIGHT }} />\n                    {phases.map((phase, index) => (\n                      <li\n                        key={phase.id}\n                        className='flex items-center text-sm'\n                        style={{ height: ROW_HEIGHT }}\n                      >\n                        <span className='truncate'>{phase.label}</span>\n                        <span className='sr-only'>, {describe(phase, index)}</span>\n                      </li>\n                    ))}\n                  </ol>\n                  <TimelineChart\n                    end={end}\n                    now={now}\n                    renderRow={(phase, band) => {\n                      const index = phases.indexOf(phase)\n                      const plannedLeft = band.x(phase.planned.start)\n                      const plannedRight = band.x(phase.planned.end)\n                      const actualStart = phase.actual && band.x(phase.actual.start)\n                      const actualEnd = phase.actual && band.x(phase.actual.end ?? now)\n                      const projection = projections[index]\n                      const projectionEnd = projection && band.x(projection)\n                      const nowX = band.x(now)\n                      const top = band.y + 4\n                      const bottom = band.y + band.height - 4 - BAR_HEIGHT\n                      const extentLeft = Math.min(plannedLeft, actualStart ?? plannedLeft)\n                      const extentRight = Math.max(\n                        plannedRight,\n                        actualEnd ?? plannedRight,\n                        projectionEnd ?? plannedRight,\n                      )\n                      const key = `${id}-${index}`\n                      return (\n                        <>\n                          <rect\n                            fill='none'\n                            height={BAR_HEIGHT}\n                            rx={3}\n                            stroke='var(--color-muted-foreground)'\n                            strokeDasharray='3 3'\n                            strokeOpacity={0.7}\n                            width={Math.max(0, plannedRight - plannedLeft)}\n                            x={plannedLeft}\n                            y={top}\n                          />\n                          {projectionEnd !== undefined && projectionEnd !== null && (\n                            <path\n                              d={`M${nowX},${bottom + 0.5}H${projectionEnd - 0.5}V${bottom + BAR_HEIGHT - 0.5}H${nowX}`}\n                              fill='none'\n                              stroke='var(--color-chart-2)'\n                              strokeDasharray='3 3'\n                            />\n                          )}\n                          {actualStart !== undefined && actualEnd !== undefined && (\n                            <>\n                              {!phase.actual?.end && (\n                                <defs>\n                                  <linearGradient\n                                    id={`${key}-running`}\n                                    x1='0'\n                                    x2='1'\n                                    y1='0'\n                                    y2='0'\n                                  >\n                                    <stop\n                                      offset='70%'\n                                      style={{\n                                        stopColor: 'var(--color-chart-2)',\n                                      }}\n                                    />\n                                    <stop\n                                      offset='100%'\n                                      style={{\n                                        stopColor:\n                                          'color-mix(in oklab, var(--color-chart-2) 25%, transparent)',\n                                      }}\n                                    />\n                                  </linearGradient>\n                                </defs>\n                              )}\n                              <rect\n                                fill={\n                                  phase.actual?.end\n                                    ? 'var(--color-chart-2)'\n                                    : `url(#${key}-running)`\n                                }\n                                height={BAR_HEIGHT}\n                                rx={3}\n                                width={Math.max(MIN_BAR_WIDTH, actualEnd - actualStart)}\n                                x={actualStart}\n                                y={bottom}\n                              />\n                            </>\n                          )}\n                          {band.active && (\n                            <rect\n                              fill='none'\n                              height={band.height - 2}\n                              rx={5}\n                              stroke='var(--color-foreground)'\n                              strokeWidth={2}\n                              width={extentRight - extentLeft + 6}\n                              x={extentLeft - 3}\n                              y={band.y + 1}\n                            />\n                          )}\n                        </>\n                      )\n                    }}\n                    rowHeight={ROW_HEIGHT}\n                    rows={phases}\n                    start={start}\n                    ticks={ticks}\n                    tooltip={(phase) => {\n                      const index = phases.indexOf(phase)\n                      const projection = projections[index]\n                      return (\n                        <>\n                          <span className='font-medium'>{phase.label}</span>\n                          <span className='text-muted-foreground tabular-nums'>\n                            Planned{' '}\n                            {formatTimelineRange(phase.planned.start, phase.planned.end)}\n                          </span>\n                          <span className='tabular-nums'>\n                            {!phase.actual\n                              ? 'Not started'\n                              : phase.actual.end\n                                ? `Took ${formatTimelineRange(phase.actual.start, phase.actual.end)}`\n                                : `Started ${formatTimelineDate(phase.actual.start)}${projection ? `, on course to end ${formatTimelineDate(projection)}` : ''}`}\n                          </span>\n                          {slips[index] !== null && (\n                            <StatusLabel\n                              variant='text'\n                              className='text-xs'\n                              tone={slips[index] > 0 ? 'bad' : 'good'}\n                            >\n                              {describeSlip(slips[index])}\n                            </StatusLabel>\n                          )}\n                        </>\n                      )\n                    }}\n                  />\n                  <ol aria-hidden className='flex flex-col'>\n                    <li\n                      className='text-muted-foreground text-right text-xs leading-5'\n                      style={{ height: TIMELINE_AXIS_HEIGHT }}\n                    >\n                      Slip\n                    </li>\n                    {phases.map((phase, index) => (\n                      <li\n                        key={phase.id}\n                        className='flex items-center justify-end'\n                        style={{ height: ROW_HEIGHT }}\n                      >\n                        <Slip slip={slips[index]} />\n                      </li>\n                    ))}\n                  </ol>\n                </div>\n              </div>\n            )}\n            {state !== 'error' && state !== 'empty' && (\n              <ul\n                aria-hidden\n                className='text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs'\n              >\n                <li className='flex items-center gap-1.5'>\n                  <span className='border-muted-foreground/70 h-2.5 w-4 rounded-sm border border-dashed' />\n                  Planned\n                </li>\n                <li className='flex items-center gap-1.5'>\n                  <span className='h-2.5 w-4 rounded-sm bg-chart-2' />\n                  Actual\n                </li>\n                <li className='flex items-center gap-1.5'>\n                  <span\n                    className='h-2.5 w-4 rounded-sm'\n                    style={{\n                      background:\n                        'linear-gradient(to right, var(--color-chart-2) 50%, color-mix(in oklab, var(--color-chart-2) 25%, transparent))',\n                    }}\n                  />\n                  Still running\n                </li>\n                <li className='flex items-center gap-1.5'>\n                  <span className='h-2.5 w-4 rounded-sm border border-dashed border-chart-2' />\n                  Projected\n                </li>\n              </ul>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Timeline4,\n  exampleProps as timeline4ExampleProps,\n  type Phase,\n  type Timeline4Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/timeline/timeline-04.tsx"
    }
  ],
  "meta": {
    "shows": "Each phase's plan as a dashed outline with what actually happened as a bar beneath it, and how many days it slipped.",
    "size": "full",
    "usedWith": [
      "timeline-01",
      "timeline-02"
    ],
    "component": "Timeline4",
    "props": "{ description: string; end: Date; now: Date; phases?: { actual?: { end?: Date; start: Date }; id: string; label: string; planned: { end: Date; start: Date } }[]; start: Date; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
