{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"progress-bars","type":"registry:block","title":"Progress bars","description":"Workspace storage as one segmented bar that fills in cascade, with a warning tick, hover-synced legend rows and a count-up total.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/progress-bars/progress-bars.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 { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type ProgressBarsSegment = {\n  id: string;\n  label: string;\n  /** Size in the same unit as `capacity`. */\n  value: number;\n  /** Chart colour token 1–5. Defaults to the segment index + 1. */\n  tone?: number;\n};\n\nexport type ProgressBarsProps = {\n  className?: string;\n  title?: string;\n  description?: string;\n  /** Total space available. Defaults to 500 (GB). */\n  capacity?: number;\n  /** Unit printed after every value. Defaults to \"GB\". */\n  unit?: string;\n  segments?: ProgressBarsSegment[];\n  /** Store the warning tick at this percentage. Defaults to 90. */\n  warnAt?: number;\n};\n\n/* ------------------------------------------------------------------ */\n/* deterministic demo data                                             */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_SEGMENTS: ProgressBarsSegment[] = [\n  { id: \"projects\", label: \"Project files\", value: 152, tone: 1 },\n  { id: \"media\", label: \"Media\", value: 97, tone: 2 },\n  { id: \"backups\", label: \"Snapshots\", value: 58, tone: 3 },\n  { id: \"other\", label: \"Other\", value: 26, tone: 4 },\n];\n\n/* ------------------------------------------------------------------ */\n/* helpers                                                             */\n/* ------------------------------------------------------------------ */\n\nfunction clamp(value: number, min: number, max: number) {\n  return Math.min(max, Math.max(min, value));\n}\n\nfunction formatNumber(value: number) {\n  return Math.round(value).toLocaleString(\"en-US\");\n}\n\nfunction useCountUp(target: number, start: boolean, reduce: boolean) {\n  const [value, setValue] = useState(target);\n  const started = useRef(false);\n\n  useEffect(() => {\n    if (!start) return;\n    if (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: 1,\n      ease: EASE,\n      onUpdate: (next) => setValue(next),\n      onComplete: () => setValue(target),\n    });\n    return () => controls.stop();\n  }, [start, target, reduce]);\n\n  return value;\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function ProgressBars({\n  className,\n  title = \"Storage\",\n  description = \"Northwind Labs · workspace\",\n  capacity = 500,\n  unit = \"GB\",\n  segments = DEFAULT_SEGMENTS,\n  warnAt = 90,\n}: ProgressBarsProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n\n  const safeSegments = segments.length > 0 ? segments : DEFAULT_SEGMENTS;\n  const safeCapacity = Math.max(1, capacity);\n  const used = safeSegments.reduce((sum, item) => sum + Math.max(0, item.value), 0);\n  const usedPct = clamp((used / safeCapacity) * 100, 0, 100);\n  const free = Math.max(0, safeCapacity - used);\n  const displayUsed = useCountUp(used, inView, reduce);\n\n  const [activeId, setActiveId] = useState<string | null>(null);\n\n  const summary = `${formatNumber(used)} of ${formatNumber(safeCapacity)} ${unit} used. ${safeSegments\n    .map((item) => `${item.label} ${formatNumber(item.value)} ${unit}`)\n    .join(\", \")}.`;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={ref}\n        initial={reduce ? false : { opacity: 0, y: 16 }}\n        animate={inView || reduce ? { opacity: 1, y: 0 } : { opacity: 0, y: 16 }}\n        transition={{ duration: reduce ? 0 : 0.6, ease: EASE }}\n        className={cn(\n          \"w-full rounded-xl border border-border bg-card p-5 text-card-foreground sm:p-6\",\n          className\n        )}\n      >\n        <div className=\"flex flex-wrap items-start justify-between gap-3\">\n          <div className=\"min-w-0\">\n            <h2 className=\"text-[15px] font-semibold tracking-tight\">{title}</h2>\n            <p className=\"mt-0.5 text-[13px] text-muted-foreground\">{description}</p>\n          </div>\n\n          <span className=\"shrink-0 rounded-full border border-border px-2.5 py-1 text-[11.5px] font-medium tabular-nums text-muted-foreground\">\n            {Math.round(usedPct)}% of {formatNumber(safeCapacity)} {unit}\n          </span>\n        </div>\n\n        <div className=\"mt-7 flex flex-wrap items-baseline gap-x-2 gap-y-0.5\">\n          <span className=\"text-[40px] font-semibold leading-none tracking-[-0.035em] tabular-nums text-foreground sm:text-[44px]\">\n            {formatNumber(displayUsed)}\n          </span>\n          <span className=\"text-[13px] text-muted-foreground\">\n            {unit} used\n          </span>\n          <span className=\"ml-auto text-[12px] tabular-nums text-muted-foreground\">\n            {formatNumber(free)} {unit} free\n          </span>\n        </div>\n\n        <div\n          role=\"img\"\n          aria-label={summary}\n          className=\"relative mt-5\"\n        >\n          <div className=\"flex h-3 w-full gap-[2px] rounded-full bg-muted\">\n            {safeSegments.map((segment, index) => {\n              const share = clamp(segment.value, 0, safeCapacity) / safeCapacity;\n              const tone = clamp(segment.tone ?? index + 1, 1, 5);\n              const dim = activeId !== null && activeId !== segment.id;\n\n              return (\n                <motion.span\n                  key={segment.id}\n                  aria-hidden=\"true\"\n                  className=\"h-full min-w-[3px] rounded-[3px]\"\n                  style={{\n                    flexGrow: share,\n                    flexBasis: 0,\n                    background: `var(--chart-${tone})`,\n                    transformOrigin: \"0% 50%\",\n                  }}\n                  initial={{ scaleX: reduce ? 1 : 0, opacity: dim ? 0.35 : 1 }}\n                  animate={{\n                    scaleX: inView || reduce ? 1 : 0,\n                    opacity: dim ? 0.32 : 1,\n                    scaleY: activeId === segment.id ? 1.25 : 1,\n                  }}\n                  transition={{\n                    scaleX: {\n                      duration: reduce ? 0 : 0.7,\n                      ease: EASE,\n                      delay: reduce ? 0 : index * 0.09,\n                    },\n                    opacity: { duration: reduce ? 0 : 0.2, ease: EASE },\n                    scaleY: {\n                      duration: reduce ? 0 : 0.25,\n                      ease: EASE,\n                    },\n                  }}\n                />\n              );\n            })}\n          </div>\n\n          {warnAt > 0 && warnAt < 100 ? (\n            <span\n              aria-hidden=\"true\"\n              className=\"absolute -top-1 bottom-5 w-px bg-border\"\n              style={{ left: `${warnAt}%` }}\n            />\n          ) : null}\n\n          <div className=\"mt-2 flex items-center justify-between text-[10.5px] tabular-nums text-muted-foreground\">\n            <span>0 {unit}</span>\n            <span>\n              alert at {formatNumber((safeCapacity * warnAt) / 100)} {unit}\n            </span>\n            <span>\n              {formatNumber(safeCapacity)} {unit}\n            </span>\n          </div>\n        </div>\n\n        <ul className=\"mt-5 -mx-2 flex flex-col\" role=\"list\">\n          {safeSegments.map((segment, index) => {\n            const tone = clamp(segment.tone ?? index + 1, 1, 5);\n            const pct = clamp((segment.value / safeCapacity) * 100, 0, 100);\n            const active = activeId === segment.id;\n\n            return (\n              <li key={segment.id}>\n                <button\n                  type=\"button\"\n                  onMouseEnter={() => setActiveId(segment.id)}\n                  onMouseLeave={() => setActiveId(null)}\n                  onFocus={() => setActiveId(segment.id)}\n                  onBlur={() => setActiveId(null)}\n                  onClick={() =>\n                    setActiveId((current) =>\n                      current === segment.id ? null : segment.id\n                    )\n                  }\n                  aria-pressed={active}\n                  className={cn(\n                    \"flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset motion-reduce:transition-none\",\n                    active ? \"bg-muted/60\" : \"hover:bg-muted/40\"\n                  )}\n                >\n                  <span\n                    aria-hidden=\"true\"\n                    className=\"h-2.5 w-2.5 shrink-0 rounded-[3px]\"\n                    style={{ background: `var(--chart-${tone})` }}\n                  />\n                  <span className=\"min-w-0 flex-1\">\n                    <span className=\"flex items-baseline justify-between gap-3\">\n                      <span className=\"truncate text-[13px] font-medium text-foreground\">\n                        {segment.label}\n                      </span>\n                      <span className=\"shrink-0 text-[12px] tabular-nums text-muted-foreground\">\n                        {formatNumber(segment.value)} {unit}\n                      </span>\n                    </span>\n                    <span className=\"mt-1.5 block h-1 w-full overflow-hidden rounded-full bg-muted\">\n                      <span\n                        className=\"block h-full rounded-full transition-transform duration-300 motion-reduce:transition-none\"\n                        style={{\n                          width: `${pct}%`,\n                          background: `var(--chart-${tone})`,\n                          transform: `scaleX(${inView || reduce ? 1 : 0})`,\n                          transformOrigin: \"0% 50%\",\n                        }}\n                      />\n                    </span>\n                  </span>\n                  <span className=\"w-10 shrink-0 text-right text-[12px] tabular-nums text-muted-foreground\">\n                    {Math.round(pct)}%\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ul>\n\n        <p className=\"mt-3 border-t border-border pt-3.5 text-[11.5px] text-muted-foreground\">\n          Snapshots are kept for 30 days.{\" \"}\n          <span className=\"text-foreground\">Auto-archive starts at 90%.</span>\n        </p>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n\nexport default ProgressBars;\n"}]}