{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "goals",
  "title": "Goals",
  "description": "Primitives for goals and targets: pace against a straight line to the target, a progress bar with an expected-by-now marker and the projection hatched, and the pace as a coloured word.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/status-label.json",
    "https://www.dashboardblocks.com/r/radix/use-reveal.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/goals.tsx",
      "content": "'use client'\n\nimport { useBlockState } from '@/registry/components/dashboardblocks/block-state'\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport { useReveal } from '@/registry/hooks/use-reveal'\n\nimport { cn } from '@/lib/utils'\n\ntype PaceStatus = 'ahead' | 'on-track' | 'behind' | 'met'\n\ninterface Pace {\n  expected: number\n  /** Share of the period that has passed, 0–1. */\n  elapsed: number\n  projected: number\n  status: PaceStatus\n}\n\ninterface PaceInput {\n  current: number\n  /** Share of the period that has passed, 0–1. */\n  elapsed: number\n  target: number\n  /** How far from the expected value still counts as on track, 0.05 by default. */\n  tolerance?: number\n}\n\nfunction getPace({ current, elapsed, target, tolerance = 0.05 }: PaceInput): Pace {\n  const clamped = Math.min(1, Math.max(0, elapsed))\n  const expected = target * clamped\n  const projected = clamped > 0 ? current / clamped : current\n  let status: PaceStatus = 'on-track'\n  if (current >= target) status = 'met'\n  else if (current > expected * (1 + tolerance)) status = 'ahead'\n  else if (current < expected * (1 - tolerance)) status = 'behind'\n  return { elapsed: clamped, expected, projected, status }\n}\n\nfunction getElapsed(start: Date, end: Date, now: Date) {\n  const total = end.getTime() - start.getTime()\n  return total > 0 ? (now.getTime() - start.getTime()) / total : 1\n}\n\nconst paceConfig: Record<PaceStatus, { label: string; tone: StatusTone }> = {\n  ahead: { label: 'Ahead', tone: 'good' },\n  behind: { label: 'Behind', tone: 'warning' },\n  met: { label: 'Goal met', tone: 'good' },\n  'on-track': { label: 'On track', tone: 'good' },\n}\n\nfunction PaceLabel({ className, status }: { className?: string; status: PaceStatus }) {\n  const config = paceConfig[status]\n  return (\n    <StatusLabel className={className} tone={config.tone}>\n      {config.label}\n    </StatusLabel>\n  )\n}\n\nfunction projectedFill(color: string) {\n  return `repeating-linear-gradient(-45deg, color-mix(in oklab, ${color} 55%, transparent) 0 2px, color-mix(in oklab, ${color} 18%, transparent) 2px 5px)`\n}\n\ninterface GoalProgressProps {\n  animated?: boolean\n  className?: string\n  /** @default 'var(--color-chart-2)' */\n  color?: string\n  current: number\n  expected?: number\n  /** Where the current pace ends up, drawn hatched past `current`. */\n  projected?: number\n  /** @default 'md' */\n  size?: 'sm' | 'md'\n  target: number\n}\n\nfunction GoalProgress({\n  animated = true,\n  className,\n  color = 'var(--color-chart-2)',\n  current,\n  expected,\n  projected,\n  size = 'md',\n  target,\n}: GoalProgressProps) {\n  const { ref, revealed } = useReveal(animated)\n  const state = useBlockState()\n\n  const clamp = (value: number) =>\n    target > 0 ? Math.min(1, Math.max(0, value / target)) : 0\n  const share = clamp(current)\n  const ahead = projected !== undefined ? Math.max(0, clamp(projected) - share) : 0\n  const marker =\n    expected !== undefined && target > 0 ? Math.min(1, expected / target) : null\n\n  return (\n    <div\n      ref={ref}\n      aria-hidden\n      className={cn('relative w-full', size === 'md' ? 'h-2.5' : 'h-1.5', className)}\n    >\n      {state ? (\n        <div\n          className={cn(\n            'bg-muted h-full w-full rounded-full',\n            state === 'loading' && 'animate-pulse motion-reduce:animate-none',\n          )}\n        />\n      ) : (\n        <div\n          className='bg-muted flex h-full w-full overflow-hidden rounded-full transition-[clip-path] duration-1000 ease-[cubic-bezier(0.33,1,0.68,1)] motion-reduce:transition-none'\n          style={{ clipPath: `inset(0 ${revealed ? 0 : 100}% 0 0)` }}\n        >\n          <span\n            className='h-full'\n            style={{ backgroundColor: color, width: `${share * 100}%` }}\n          />\n          {ahead > 0 && (\n            <span\n              className='h-full'\n              style={{ background: projectedFill(color), width: `${ahead * 100}%` }}\n            />\n          )}\n        </div>\n      )}\n      {!state && marker !== null && (\n        <span\n          className='bg-foreground ring-background absolute top-1/2 h-[calc(100%+8px)] w-0.5 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2'\n          style={{ left: `${marker * 100}%` }}\n        />\n      )}\n    </div>\n  )\n}\n\nfunction GoalProgressKey({\n  className,\n  color = 'var(--color-chart-2)',\n  label = 'Expected by today',\n  shape = 'expected',\n}: {\n  className?: string\n  /** @default 'var(--color-chart-2)' */\n  color?: string\n  label?: string\n  /** @default 'expected' */\n  shape?: 'expected' | 'progress' | 'projected'\n}) {\n  const state = useBlockState()\n  if (state === 'empty' || state === 'error') return null\n\n  return (\n    <span\n      className={cn(\n        'text-muted-foreground inline-flex items-center gap-1.5 text-xs',\n        className,\n      )}\n    >\n      {shape === 'expected' ? (\n        <span aria-hidden className='bg-foreground h-3 w-0.5 rounded-full' />\n      ) : (\n        <span\n          aria-hidden\n          className='h-2 w-3 rounded-full'\n          style={{\n            background: shape === 'projected' ? projectedFill(color) : color,\n          }}\n        />\n      )}\n      {label}\n    </span>\n  )\n}\n\nexport { GoalProgress, GoalProgressKey, PaceLabel, getElapsed, getPace, paceConfig }\n\nexport type { GoalProgressProps, Pace, PaceInput, PaceStatus }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/goals.tsx"
    }
  ],
  "type": "registry:component"
}
