{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tick-bar",
  "type": "registry:component",
  "title": "Segmented progress",
  "description": "Make a count or capacity visible as a series of filled marks.",
  "categories": [
    "metrics"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/tick-bar.tsx",
      "type": "registry:component",
      "target": "components/overtrue/tick-bar.tsx",
      "content": "/** Adapted from dashboardcn (MIT), copyright 2026 dashboardcn contributors.\n * Source: https://github.com/NoahGdev/dashboardcn/tree/b1ffacbca0f7a0be60135c8665b9e8c267205c48\n *\n * MIT License\n *\n * Copyright (c) 2026 dashboardcn contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n * ---\n *\n * Portions of this project are derived from shadcn/ui and shadcn/registry-template\n * (https://github.com/shadcn-ui/ui), Copyright (c) 2023 shadcn, licensed under the\n * MIT License. The notice above applies to those portions as well.\n */\n\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface TickBarProps extends React.ComponentProps<\"div\"> {\n  /** Current value, from 0 to max. */\n  value: number;\n  max?: number;\n  /** Number of ticks. */\n  segments?: number;\n  /** Any CSS color for the filled ticks. Defaults to chart-1. */\n  color?: string;\n  /** Any CSS color for the unfilled ticks. Defaults to a faint foreground. */\n  trackColor?: string;\n  /** \"tick\" draws thin bars; \"pill\" draws wide rounded ones. */\n  shape?: \"tick\" | \"pill\";\n  /** Reveal filled ticks in sequence when the bar mounts. */\n  animate?: boolean;\n  /** Total reveal time in milliseconds. */\n  animationDuration?: number;\n  /** Show the current value at the end of the bar. */\n  showValue?: boolean;\n  /** Formats the readout and the announced value. Defaults to a whole percentage. */\n  valueFormatter?: (value: number, max: number) => string;\n}\n\nconst REDUCED_QUERY = \"(prefers-reduced-motion: reduce)\";\nfunction subscribeReducedMotion(callback: () => void) {\n  const query = window.matchMedia(REDUCED_QUERY);\n  query.addEventListener(\"change\", callback);\n  return () => query.removeEventListener(\"change\", callback);\n}\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    subscribeReducedMotion,\n    () => window.matchMedia(REDUCED_QUERY).matches,\n    () => false,\n  );\n}\n\n/** Glide a number toward its target on cubic-bezier(0.22, 1, 0.36, 1). */\nfunction useTweened(target: number, duration: number, initial: number) {\n  const reduced = useReducedMotion();\n  const [shown, setShown] = React.useState(initial);\n  const current = React.useRef(initial);\n  React.useEffect(() => {\n    if (current.current === target) return;\n    if (reduced || duration <= 0) {\n      current.current = target;\n      setShown(target);\n      return;\n    }\n    const from = current.current;\n    const start = performance.now();\n    let frame = 0;\n    const step = (now: number) => {\n      const t = Math.min(1, (now - start) / duration);\n      current.current = from + (target - from) * (1 - (1 - t) ** 4);\n      setShown(t === 1 ? target : current.current);\n      if (t < 1) frame = requestAnimationFrame(step);\n    };\n    frame = requestAnimationFrame(step);\n    return () => cancelAnimationFrame(frame);\n  }, [target, duration, reduced]);\n  return shown;\n}\n\nconst percent = (value: number, max: number) =>\n  `${Math.round(Math.min(1, Math.max(0, value / (max || 1))) * 100)}%`;\n\n/** A progress bar drawn as a row of ticks, lit up to the current value. */\nfunction TickBar({\n  value,\n  max = 100,\n  segments = 40,\n  color = \"var(--color-chart-1)\",\n  trackColor = \"color-mix(in oklab, var(--color-foreground) 12%, transparent)\",\n  shape = \"tick\",\n  animate = false,\n  animationDuration = 700,\n  showValue = false,\n  valueFormatter = percent,\n  className,\n  style,\n  ...props\n}: TickBarProps) {\n  const count = Math.max(1, Math.round(segments));\n  const safe = Number.isFinite(value) ? value : 0;\n  const fraction = Math.min(1, Math.max(0, safe / (max || 1)));\n  // Any non-zero value lights at least one tick so small values still register.\n  const filled = fraction === 0 ? 0 : Math.max(1, Math.round(fraction * count));\n\n  // Light new ticks in sequence from where the fill was, and unlight in reverse.\n  const previous = React.useRef(animate ? 0 : filled);\n  const from = previous.current;\n  React.useEffect(() => {\n    previous.current = filled;\n  }, [filled]);\n  const changed = Math.abs(filled - from);\n  const step = changed ? (animationDuration * 0.8) / changed : 0;\n\n  const shown = useTweened(\n    safe,\n    showValue ? animationDuration : 0,\n    animate ? 0 : safe,\n  );\n  const pill = shape === \"pill\";\n\n  return (\n    <div\n      data-slot=\"tick-bar\"\n      data-shape={shape}\n      role=\"progressbar\"\n      aria-valuemin={0}\n      aria-valuemax={max}\n      aria-valuenow={value}\n      aria-valuetext={valueFormatter(safe, max)}\n      className={cn(\n        \"flex w-full items-center\",\n        pill ? \"h-3.5 gap-1\" : \"h-6\",\n        className,\n      )}\n      style={\n        {\n          ...style,\n          \"--tick-color\": color,\n          \"--tick-track\": trackColor,\n        } as React.CSSProperties\n      }\n      {...props}\n    >\n      {Array.from({ length: count }, (_, index) => {\n        const lit = index < filled;\n        const head = lit && index === filled - 1;\n        const delay =\n          filled > from && index >= from && index < filled\n            ? (index - from) * step\n            : filled < from && index >= filled && index < from\n              ? (from - 1 - index) * step\n              : 0;\n        return (\n          <span\n            key={index}\n            data-slot=\"tick-bar-tick\"\n            data-filled={lit}\n            data-head={head || undefined}\n            className={cn(\n              \"relative h-full min-w-0 flex-1\",\n              !pill && \"flex justify-center\",\n            )}\n          >\n            <span\n              className={cn(\n                \"block h-full rounded-full bg-(--tick-track) transition-[background-color,opacity,scale,box-shadow] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n                pill ? \"w-full\" : \"w-[3px] max-w-full scale-y-[0.58]\",\n                \"data-[lit=true]:bg-(--tick-color) data-[lit=true]:opacity-(--tick-alpha) data-[lit=true]:scale-y-100\",\n                \"data-[head=true]:dark:shadow-[0_0_10px_1px_color-mix(in_oklab,var(--tick-color)_70%,transparent)]\",\n                animate &&\n                  \"starting:data-[lit=true]:bg-(--tick-track) starting:data-[lit=true]:opacity-100\",\n                animate && !pill && \"starting:data-[lit=true]:scale-y-[0.58]\",\n              )}\n              data-lit={lit}\n              data-head={head || undefined}\n              style={\n                {\n                  // Filled ticks brighten toward the leading edge.\n                  \"--tick-alpha\": lit\n                    ? (0.55 + 0.45 * ((index + 1) / filled) ** 1.5).toFixed(3)\n                    : 1,\n                  transitionDelay: delay ? `${Math.round(delay)}ms` : undefined,\n                } as React.CSSProperties\n              }\n            />\n          </span>\n        );\n      })}\n      {showValue ? (\n        <span\n          data-slot=\"tick-bar-value\"\n          aria-hidden=\"true\"\n          className=\"ml-3 shrink-0 text-sm leading-none font-semibold tracking-[-0.01em] text-foreground tabular-nums\"\n        >\n          {valueFormatter(shown, max)}\n        </span>\n      ) : null}\n    </div>\n  );\n}\n\nexport { TickBar };\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/tick-bar. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
