{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "progress-bars",
  "type": "registry:ui",
  "title": "Progress Bars",
  "description": "A minimal textured bar chart with vertical and horizontal layouts, shipping a line fill and a dot matrix fill, driven by nothing more than a value per item.",
  "author": "Aditya Ojha <https://akoder.xyz>",
  "categories": [
    "chart",
    "progress",
    "visualization",
    "accessibility"
  ],
  "dependencies": [
    "motion",
    "radix-ui"
  ],
  "registryDependencies": [
    "tooltip"
  ],
  "meta": {
    "docs": "https://akoder.xyz/components/progress-bars",
    "source": "https://github.com/AdityaKodez/adityaojha/blob/main/components/ui/progress-bars.tsx"
  },
  "files": [
    {
      "path": "components/ui/progress-bars.tsx",
      "content": "\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport type { CSSProperties, ReactNode } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"./tooltip\";\n\nexport interface ProgressBarItem {\n  id: string;\n  /** Optional caption rendered next to the bar. */\n  label?: string;\n  value: number;\n  /** Extra detail line shown inside the tooltip. */\n  tooltip?: ReactNode;\n}\n\nexport interface ProgressBarsProps {\n  items: ProgressBarItem[];\n  orientation?: \"vertical\" | \"horizontal\";\n  /** Largest possible item value. */\n  max?: number;\n  /** Show the scale and guide lines in vertical orientation. */\n  showScale?: boolean;\n  showValues?: boolean;\n  showTooltip?: boolean;\n  formatValue?: (value: number, max: number) => string;\n  /** Vertical plot height in pixels. */\n  height?: number;\n  animate?: boolean;\n  ariaLabel?: string;\n  className?: string;\n}\n\n/**\n * Fill textures. Both are anchored to the bottom left so the pattern stays put\n * while a bar grows, and both fall back to a literal color outside this site.\n */\nconst LINE_FILL: CSSProperties = {\n  backgroundImage:\n    \"repeating-linear-gradient(to bottom, var(--foreground, #111111) 0, var(--foreground, #111111) 1px, transparent 1px, transparent 3px)\",\n  backgroundPosition: \"bottom left\",\n};\n\nconst DOT_FILL: CSSProperties = {\n  backgroundImage:\n    \"radial-gradient(circle at center, var(--foreground, #111111) 1px, transparent 1.3px)\",\n  backgroundSize: \"5px 5px\",\n  backgroundPosition: \"bottom left\",\n};\n\nconst SCALE_STEPS = [0, 25, 50, 75, 100];\n\nconst EASE = [0.22, 1, 0.36, 1] as const;\n\nconst PERCENT_FORMATTER = new Intl.NumberFormat(undefined, {\n  style: \"percent\",\n  maximumFractionDigits: 0,\n});\n\nfunction defaultFormatValue(value: number, max: number) {\n  return PERCENT_FORMATTER.format(value / max);\n}\n\nfunction clampValue(value: number, max: number) {\n  if (!Number.isFinite(value) || max <= 0) return 0;\n  return Math.min(Math.max(value, 0), max);\n}\n\nfunction ItemTooltip({\n  item,\n  value,\n  enabled,\n  children,\n}: {\n  item: ProgressBarItem;\n  value: string;\n  enabled: boolean;\n  children: ReactNode;\n}) {\n  if (!enabled) return <>{children}</>;\n\n  return (\n    <Tooltip>\n      <TooltipTrigger asChild>{children}</TooltipTrigger>\n      <TooltipContent side=\"top\" sideOffset={8} className=\"max-w-56\">\n        <div className=\"space-y-0.5\">\n          <p className=\"font-medium\">{item.label ? `${item.label} · ${value}` : value}</p>\n          {item.tooltip ? <div className=\"text-muted-foreground\">{item.tooltip}</div> : null}\n        </div>\n      </TooltipContent>\n    </Tooltip>\n  );\n}\n\nfunction BarChart({\n  fill,\n  items,\n  orientation = \"vertical\",\n  max = 100,\n  showScale = true,\n  showValues = true,\n  showTooltip = true,\n  formatValue = defaultFormatValue,\n  height = 240,\n  animate = true,\n  ariaLabel,\n  className,\n}: ProgressBarsProps & { fill: CSSProperties; ariaLabel: string }) {\n  const reducedMotion = useReducedMotion();\n  const shouldAnimate = animate && !reducedMotion;\n  const range = max > 0 ? max : 100;\n\n  if (items.length === 0) return null;\n\n  const fillClassName =\n    \"transition-opacity group-hover:opacity-70 group-focus-visible:opacity-70\";\n  const trackClassName = \"overflow-hidden ring-1 ring-inset ring-border/70 rounded-lg\";\n\n  if (orientation === \"horizontal\") {\n    return (\n      <section aria-label={ariaLabel} className={cn(\"w-full space-y-3\", className)} role=\"list\">\n        {items.map((item, index) => {\n          const percentage = (clampValue(item.value, range) / range) * 100;\n          const formatted = formatValue(item.value, range);\n\n          return (\n            <ItemTooltip key={item.id} item={item} value={formatted} enabled={showTooltip}>\n              <div\n                role=\"listitem\"\n                tabIndex={0}\n                aria-label={item.label ? `${item.label}, ${formatted}` : formatted}\n                className=\"group grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-1.5 outline-none focus-visible:ring-1 focus-visible:ring-ring sm:grid-cols-[minmax(6rem,0.5fr)_minmax(0,1fr)_3rem]\"\n              >\n                {item.label ? <p className=\"truncate text-sm leading-tight\">{item.label}</p> : <span />}\n                {showValues ? (\n                  <span className=\"col-start-2 row-start-1 text-right text-xs tabular-nums sm:col-start-3\">\n                    {formatted}\n                  </span>\n                ) : null}\n                <div\n                  role=\"progressbar\"\n                  aria-valuenow={clampValue(item.value, range)}\n                  aria-valuemin={0}\n                  aria-valuemax={range}\n                  aria-valuetext={formatted}\n                  aria-label={item.label || ariaLabel}\n                  className={cn(\"col-span-2 h-7 sm:col-span-1 sm:col-start-2 sm:row-start-1\", trackClassName)}\n                >\n                  <motion.span\n                    className={cn(\"block h-full\", fillClassName)}\n                    style={fill}\n                    initial={shouldAnimate ? { width: \"0%\" } : false}\n                    whileInView={{ width: `${percentage}%` }}\n                    viewport={{ once: true, amount: 0.35 }}\n                    transition={{\n                      duration: shouldAnimate ? 0.3 : 0,\n                      delay: shouldAnimate ? index * 0.05 : 0,\n                      ease: EASE,\n                    }}\n                  />\n                </div>\n              </div>\n            </ItemTooltip>\n          );\n        })}\n      </section>\n    );\n  }\n\n  return (\n    <section aria-label={ariaLabel} className={cn(\"w-full\", className)}>\n      <div className={cn(\"grid min-w-0 gap-x-3\", showScale ? \"grid-cols-[2.5rem_minmax(0,1fr)]\" : \"grid-cols-1\")}>\n        {showScale ? (\n          <div\n            aria-hidden=\"true\"\n            className=\"relative mt-7 text-right font-mono text-[10px] tabular-nums text-muted-foreground\"\n            style={{ height }}\n          >\n            {SCALE_STEPS.map((step) => (\n              <span\n                key={step}\n                className={cn(\"absolute right-0 leading-none\", step === 0 ? \"translate-y-1/2\" : \"-translate-y-1/2\")}\n                style={{ bottom: `${step}%` }}\n              >\n                {formatValue((step / 100) * range, range)}\n              </span>\n            ))}\n          </div>\n        ) : null}\n\n        {/* Value labels sit above each fill. The plot uses fractional grid tracks\n            instead of fixed-width bars so it always fits its container. */}\n        <div className=\"min-w-0 pt-7 pb-1\">\n          <div className=\"relative min-w-0\">\n            <div aria-hidden=\"true\" className=\"absolute inset-x-0 top-0\" style={{ height }}>\n              {SCALE_STEPS.filter((step) => step > 0).map((step) => (\n                <span\n                  key={step}\n                  className=\"absolute inset-x-0  border-dashed border-border/80\"\n                  style={{ bottom: `${step}%` }}\n                />\n              ))}\n            </div>\n\n            <div\n              className=\"relative grid min-w-0 gap-x-1.5 sm:gap-x-3\"\n              role=\"list\"\n              style={{ gridTemplateColumns: `repeat(${items.length}, minmax(0, 1fr))` }}\n            >\n              {items.map((item, index) => {\n                const percentage = (clampValue(item.value, range) / range) * 100;\n                const formatted = formatValue(item.value, range);\n\n                return (\n                  <ItemTooltip key={item.id} item={item} value={formatted} enabled={showTooltip}>\n                    <div\n                      role=\"listitem\"\n                      tabIndex={0}\n                      aria-label={item.label ? `${item.label}, ${formatted}` : formatted}\n                      className=\"group min-w-0 outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n                    >\n                      <div className=\"relative\" style={{ height }}>\n                        {showValues ? (\n                          <span\n                            className=\"absolute inset-x-0 -translate-y-1.5 truncate text-center text-[10px] tabular-nums sm:text-xs\"\n                            style={{ bottom: `${percentage}%` }}\n                          >\n                            {formatted}\n                          </span>\n                        ) : null}\n                        <div\n                          role=\"progressbar\"\n                          aria-valuenow={clampValue(item.value, range)}\n                          aria-valuemin={0}\n                          aria-valuemax={range}\n                          aria-valuetext={formatted}\n                          aria-label={item.label || ariaLabel}\n                          className={cn(\"absolute inset-x-px bottom-0 top-0 sm:inset-x-1.5\", trackClassName)}\n                        >\n                          <motion.span\n                            className={cn(\"absolute inset-x-0 bottom-0\", fillClassName)}\n                            style={fill}\n                            initial={shouldAnimate ? { height: \"0%\" } : false}\n                            whileInView={{ height: `${percentage}%` }}\n                            viewport={{ once: true, amount: 0.35 }}\n                            transition={{\n                              duration: shouldAnimate ? 0.3 : 0,\n                              delay: shouldAnimate ? index * 0.05 : 0,\n                              ease: EASE,\n                            }}\n                          />\n                        </div>\n                      </div>\n                      {item.label ? (\n                        <p className=\"mt-3 truncate pt-3 text-center text-xs leading-tight\">\n                          {item.label}\n                        </p>\n                      ) : null}\n                    </div>\n                  </ItemTooltip>\n                );\n              })}\n            </div>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\n/** Bars filled with etched horizontal rules. */\nexport function ProgressBars({ ariaLabel = \"Progress bars\", ...props }: ProgressBarsProps) {\n  return <BarChart {...props} fill={LINE_FILL} ariaLabel={ariaLabel} />;\n}\n\n/** The same bars filled with a matrix of dots instead of rules. */\nexport function DotProgress({ ariaLabel = \"Dot progress\", ...props }: ProgressBarsProps) {\n  return <BarChart {...props} fill={DOT_FILL} ariaLabel={ariaLabel} />;\n}\n",
      "type": "registry:ui"
    }
  ],
  "docs": "## Installation\n\n```bash\nnpx shadcn@latest add @akoder/progress-bars\n```\n\n## Usage\n\n```tsx\nimport { DotProgress, ProgressBars } from \"@/components/ui/progress-bars\";\n\nconst milestones = [\n  { id: \"design\", label: \"design\", value: 82 },\n  { id: \"build\", label: \"build\", value: 64 },\n  { id: \"launch\", label: \"launch\", value: 49 },\n];\n\nexport function ProjectProgress() {\n  return <ProgressBars items={milestones} />;\n}\n\n// Same props, dot matrix fill instead of etched rules.\nexport function ProjectDots() {\n  return <DotProgress items={milestones} orientation=\"horizontal\" />;\n}\n```"
}