{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"goal-progress","type":"registry:block","title":"Goal progress","description":"Quarter goals with linear progress bars that fill in sequence, milestone ticks, and a count-up percentage. A goal hitting 100% earns a quiet check mark and a soft ring pulse.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/goal-progress/goal-progress.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  MotionConfig,\n  animate,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { Check } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/* timing shared by every row so the bars fill, count up, and complete in lock-step */\nconst FILL_DURATION = 1.0;\nconst STAGGER = 0.14;\nconst BASE_DELAY = 0.15;\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type GoalProgressGoal = {\n  id: string;\n  label: string;\n  /** Progress from 0 to 100. */\n  progress: number;\n  /** Short context line, e.g. \"$84.3k of $100k MRR\". */\n  detail?: string;\n  /** Chart colour token 1–5. Defaults to 1. */\n  tone?: number;\n};\n\nexport type GoalProgressProps = {\n  className?: string;\n  title?: string;\n  description?: string;\n  goals?: GoalProgressGoal[];\n  formatProgress?: (progress: number) => string;\n};\n\n/* ------------------------------------------------------------------ */\n/* deterministic demo data (no Math.random / Date.now at module load)  */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_GOALS: GoalProgressGoal[] = [\n  {\n    id: \"revenue\",\n    label: \"Recurring revenue\",\n    progress: 84,\n    detail: \"$84.3k of $100k MRR\",\n  },\n  {\n    id: \"signups\",\n    label: \"New signups\",\n    progress: 64,\n    detail: \"1,024 of 1,600 accounts\",\n  },\n  {\n    id: \"activation\",\n    label: \"Activation rate\",\n    progress: 48,\n    detail: \"48% of new signups activated\",\n  },\n  {\n    id: \"expansion\",\n    label: \"Expansion revenue\",\n    progress: 100,\n    detail: \"$40k of $40k added\",\n  },\n];\n\n/* ------------------------------------------------------------------ */\n/* helpers                                                             */\n/* ------------------------------------------------------------------ */\n\nfunction clamp(v: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, v));\n}\n\n/* count-up that shares the fill's duration + easing so the number lands\n   exactly when the bar does */\nfunction useCountUp(\n  target: number,\n  opts: { start: boolean; reduce: boolean; delay: number }\n) {\n  const [value, setValue] = useState(target);\n  const started = useRef(false);\n\n  useEffect(() => {\n    if (!opts.start) return;\n    if (opts.reduce) {\n      setValue(target);\n      return;\n    }\n    if (started.current) return;\n    started.current = true;\n\n    const controls = animate(0, target, {\n      duration: FILL_DURATION,\n      ease: EASE,\n      delay: opts.delay,\n      onUpdate: (v) => setValue(v),\n      onComplete: () => setValue(target),\n    });\n\n    return () => controls.stop();\n  }, [opts.start, target, opts.reduce, opts.delay]);\n\n  return value;\n}\n\nconst MILESTONES = [25, 50, 75] as const;\n\n/* ------------------------------------------------------------------ */\n/* row                                                                 */\n/* ------------------------------------------------------------------ */\n\ntype GoalRowProps = {\n  goal: GoalProgressGoal;\n  index: number;\n  show: boolean;\n  reduce: boolean;\n  format: (value: number) => string;\n};\n\nfunction GoalRow({ goal, index, show, reduce, format }: GoalRowProps) {\n  const pct = clamp(goal.progress, 0, 100);\n  const done = pct >= 100;\n  const color = `var(--chart-${clamp(goal.tone ?? 1, 1, 5)})`;\n\n  const fillDelay = BASE_DELAY + index * STAGGER;\n  const value = useCountUp(pct, { start: show, reduce, delay: fillDelay });\n\n  /* the check mark lands a touch before the bar finishes; the ring follows once */\n  const checkDelay = fillDelay + FILL_DURATION * 0.82;\n\n  return (\n    <motion.li\n      initial={{ opacity: 0, y: reduce ? 0 : 12 }}\n      animate={{ opacity: show ? 1 : 0, y: 0 }}\n      transition={{\n        duration: reduce ? 0 : 0.5,\n        delay: reduce ? 0 : index * 0.06,\n        ease: EASE,\n      }}\n      className=\"rounded-lg px-2 py-2.5 transition-colors hover:bg-muted/40\"\n    >\n      <div className=\"flex items-baseline justify-between gap-3\">\n        <span className=\"min-w-0 truncate text-[13.5px] font-medium text-card-foreground\">\n          {goal.label}\n        </span>\n\n        <div className=\"flex shrink-0 items-center gap-1.5\">\n          {done ? (\n            <motion.span\n              initial={\n                reduce ? { scale: 1, opacity: 1 } : { scale: 0, opacity: 0 }\n              }\n              animate={{ scale: 1, opacity: 1 }}\n              transition={\n                reduce\n                  ? { duration: 0 }\n                  : { duration: 0.35, delay: checkDelay, ease: EASE }\n              }\n              className=\"relative inline-flex h-[18px] w-[18px] items-center justify-center rounded-full bg-success/10 text-success\"\n            >\n              <Check className=\"h-3 w-3\" strokeWidth={3} />\n              {!reduce ? (\n                <motion.span\n                  aria-hidden=\"true\"\n                  initial={{ scale: 0.5, opacity: 0.6 }}\n                  animate={{ scale: 2.1, opacity: 0 }}\n                  transition={{\n                    duration: 0.9,\n                    delay: checkDelay,\n                    ease: \"easeOut\",\n                  }}\n                  className=\"absolute inset-0 rounded-full ring-1 ring-success\"\n                />\n              ) : null}\n            </motion.span>\n          ) : null}\n          <span className=\"text-[15px] font-semibold tracking-tight tabular-nums\">\n            {format(value)}\n          </span>\n        </div>\n      </div>\n\n      {goal.detail ? (\n        <p className=\"mt-0.5 truncate text-[12px] text-muted-foreground\">\n          {goal.detail}\n        </p>\n      ) : null}\n\n      <div\n        role=\"progressbar\"\n        aria-label={goal.label}\n        aria-valuemin={0}\n        aria-valuemax={100}\n        aria-valuenow={Math.round(pct)}\n        aria-valuetext={`${Math.round(pct)}%`}\n        className=\"relative mt-2.5 h-1.5 w-full overflow-visible rounded-full bg-muted\"\n      >\n        <motion.div\n          initial={{ scaleX: reduce ? pct / 100 : 0 }}\n          animate={{ scaleX: show ? pct / 100 : 0 }}\n          transition={\n            reduce\n              ? { duration: 0 }\n              : { duration: FILL_DURATION, delay: fillDelay, ease: EASE }\n          }\n          style={{ background: color, transformOrigin: \"0% 50%\" }}\n          className=\"absolute inset-0 rounded-full\"\n        />\n\n        {MILESTONES.map((m) => (\n          <span\n            key={m}\n            aria-hidden=\"true\"\n            className=\"absolute top-1/2 h-2.5 w-px -translate-y-1/2 bg-border\"\n            style={{ left: `${m}%` }}\n          />\n        ))}\n      </div>\n    </motion.li>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function GoalProgress({\n  className,\n  title = \"Quarter goals\",\n  description = \"Q4 · progress against targets\",\n  goals = DEFAULT_GOALS,\n  formatProgress,\n}: GoalProgressProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n  const show = inView;\n\n  const format = formatProgress ?? ((v: number) => `${Math.round(v)}%`);\n\n  const completed = goals.filter((g) => clamp(g.progress, 0, 100) >= 100).length;\n\n  const ariaLabel = `${title}. ${goals\n    .map((g) => `${g.label} ${format(clamp(g.progress, 0, 100))}`)\n    .join(\", \")}. ${completed} of ${goals.length} complete.`;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={ref}\n        initial={{ opacity: 0, y: 20 }}\n        animate={show ? { opacity: 1, y: 0 } : { opacity: 0, y: 20 }}\n        transition={{ duration: 0.6, ease: EASE }}\n        className={cn(\n          \"rounded-xl border border-border bg-card text-card-foreground shadow-sm\",\n          className\n        )}\n      >\n        <div className=\"p-5 sm:p-6\">\n          <div className=\"flex flex-wrap items-start justify-between gap-3\">\n            <div>\n              <h2 className=\"text-[15px] font-semibold tracking-tight\">\n                {title}\n              </h2>\n              {description ? (\n                <p className=\"mt-0.5 text-[13px] text-muted-foreground\">\n                  {description}\n                </p>\n              ) : null}\n            </div>\n\n            <motion.span\n              initial={{ opacity: reduce ? 1 : 0 }}\n              animate={{ opacity: show ? 1 : 0 }}\n              transition={{\n                duration: reduce ? 0 : 0.5,\n                delay: reduce ? 0 : 0.2,\n                ease: EASE,\n              }}\n              className=\"inline-flex items-center gap-1.5 rounded-full border border-border px-2.5 py-1 text-[12px] font-medium text-muted-foreground\"\n            >\n              <span className=\"inline-flex h-[14px] w-[14px] items-center justify-center rounded-full bg-success/10 text-success\">\n                <Check className=\"h-2.5 w-2.5\" strokeWidth={3} />\n              </span>\n              <span className=\"tabular-nums\">\n                {completed} of {goals.length} complete\n              </span>\n            </motion.span>\n          </div>\n\n          <ul\n            className=\"mt-4 -mx-2 flex flex-col gap-1\"\n            role=\"list\"\n            aria-label={ariaLabel}\n          >\n            {goals.map((goal, index) => (\n              <GoalRow\n                key={goal.id}\n                goal={goal}\n                index={index}\n                show={show}\n                reduce={reduce}\n                format={format}\n              />\n            ))}\n          </ul>\n        </div>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n\nexport default GoalProgress;\n"}]}