{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "trend-sparkline",
  "type": "registry:component",
  "title": "Inline trend",
  "description": "Add just enough history to a number without introducing a chart axis.",
  "categories": [
    "charts"
  ],
  "dependencies": [
    "recharts-analytics@npm:recharts@3.10.1"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/trend-sparkline.tsx",
      "type": "registry:component",
      "target": "components/overtrue/trend-sparkline.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\";\nimport {\n  Area,\n  AreaChart,\n  AreaRevealShape,\n  Line,\n  LineChart,\n  ResponsiveContainer,\n  Tooltip,\n  YAxis,\n  type AreaRevealShapeProps,\n  type TooltipContentProps,\n} from \"recharts-analytics\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface SparklineProps extends React.ComponentProps<\"div\"> {\n  /** Series to plot, oldest first. */\n  data: number[];\n  variant?: \"area\" | \"line\";\n  /** Area fill: a plain gradient, or a dot grid that fades out toward the line. */\n  fill?: \"gradient\" | \"dots\";\n  /** Any CSS color. Defaults to the theme primary. */\n  color?: string;\n  curve?: \"monotone\" | \"linear\" | \"step\";\n  strokeWidth?: number;\n  /** Animate after hydration and when data changes. Respects reduced motion. */\n  animate?: boolean;\n  animationDuration?: number;\n  /** Mark the most recent value with a haloed point. */\n  endpoint?: boolean;\n  /** Show a hover and keyboard readout of each value. */\n  tooltip?: boolean;\n  /** Formats values in the readout. */\n  valueFormatter?: (value: number, index: number) => string;\n}\n\nconst reducedMotionQuery = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribeToReducedMotion(onChange: () => void) {\n  const query = window.matchMedia(reducedMotionQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n}\n\nfunction getReducedMotionSnapshot() {\n  return window.matchMedia(reducedMotionQuery).matches;\n}\n\nfunction getReducedMotionServerSnapshot() {\n  return true;\n}\n\nconst defaultFormatter = (value: number) =>\n  value.toLocaleString(\"en-US\", { maximumFractionDigits: 2 });\n\n/** Area shape that masks the fill to a dot grid while keeping the stroke solid. */\nfunction DotGridAreaShape({\n  maskId,\n  ...props\n}: AreaRevealShapeProps & { maskId: string }) {\n  return (\n    <>\n      <g mask={`url(#${maskId})`}>\n        <AreaRevealShape {...props} stroke=\"none\" />\n      </g>\n      <AreaRevealShape {...props} id={undefined} fill=\"none\" />\n    </>\n  );\n}\n\n/** A solid point with a soft halo, used for the latest value and the hovered one. */\nfunction HaloDot({\n  cx,\n  cy,\n  color,\n  className,\n  style,\n}: {\n  cx?: number;\n  cy?: number;\n  color: string;\n  className?: string;\n  style?: React.CSSProperties;\n}) {\n  if (cx == null || cy == null) return null;\n  return (\n    <g className={className} style={style}>\n      <circle cx={cx} cy={cy} r={5.25} fill={color} fillOpacity={0.18} />\n      <circle\n        cx={cx}\n        cy={cy}\n        r={2.75}\n        fill={color}\n        stroke=\"var(--color-card)\"\n        strokeWidth={1.5}\n      />\n    </g>\n  );\n}\n\nfunction SparklineTooltip({\n  active,\n  payload,\n  color,\n  format,\n}: Pick<Partial<TooltipContentProps>, \"active\" | \"payload\"> & {\n  color: string;\n  format: (value: number, index: number) => string;\n}) {\n  const entry = payload?.[0];\n  if (!active || !entry || typeof entry.value !== \"number\") return null;\n  const index = (entry.payload as { i: number } | undefined)?.i ?? 0;\n  return (\n    <div\n      data-slot=\"sparkline-tooltip\"\n      className=\"flex items-center gap-2 rounded-xl border border-border/70 bg-popover/90 px-2.5 py-1.5 text-xs text-popover-foreground shadow-xl backdrop-blur-md\"\n    >\n      <span\n        aria-hidden=\"true\"\n        className=\"size-2 shrink-0 rounded-full\"\n        style={{ backgroundColor: color }}\n      />\n      <span className=\"font-medium tabular-nums\">\n        {format(entry.value, index)}\n      </span>\n    </div>\n  );\n}\n\nfunction Sparkline({\n  data,\n  variant = \"area\",\n  fill = \"gradient\",\n  color = \"var(--color-primary)\",\n  curve = \"monotone\",\n  strokeWidth = 2,\n  animate = true,\n  animationDuration = 700,\n  endpoint = true,\n  tooltip = false,\n  valueFormatter = defaultFormatter,\n  className,\n  style,\n  ...props\n}: SparklineProps) {\n  const id = React.useId();\n  const reducedMotion = React.useSyncExternalStore(\n    subscribeToReducedMotion,\n    getReducedMotionSnapshot,\n    getReducedMotionServerSnapshot,\n  );\n  const animationActive = animate && !reducedMotion;\n  const dots = variant === \"area\" && fill === \"dots\";\n  const points = React.useMemo(() => data.map((y, i) => ({ i, y })), [data]);\n  const margin = { top: 2, right: 0, bottom: 0, left: 0 };\n  // Scale to the data, not to zero, so the shape of the trend reads at any size.\n  const domain = React.useMemo((): [number, number] => {\n    const values = data.filter(Number.isFinite);\n    if (!values.length) return [0, 1];\n    const low = Math.min(...values);\n    const high = Math.max(...values);\n    const pad = high === low ? Math.abs(high) * 0.1 || 1 : (high - low) * 0.12;\n    return [low - pad * 1.5, high + pad];\n  }, [data]);\n  const axis = <YAxis hide domain={domain} />;\n  const last = points.length - 1;\n  const dot = endpoint\n    ? (dotProps: { cx?: number; cy?: number; index: number }) =>\n        dotProps.index === last ? (\n          <HaloDot\n            key=\"endpoint\"\n            cx={dotProps.cx}\n            cy={dotProps.cy}\n            color={color}\n            className={cn(\n              \"transition-opacity duration-300 ease-out\",\n              animationActive && \"starting:opacity-0\",\n            )}\n            style={\n              animationActive\n                ? { transitionDelay: `${animationDuration}ms` }\n                : undefined\n            }\n          />\n        ) : null\n    : false;\n  const activeDot = tooltip\n    ? (dotProps: { cx?: number; cy?: number }) => (\n        <HaloDot cx={dotProps.cx} cy={dotProps.cy} color={color} />\n      )\n    : false;\n  const readout = tooltip ? (\n    <Tooltip\n      cursor={{\n        stroke: \"color-mix(in oklab, var(--color-foreground) 25%, transparent)\",\n        strokeWidth: 1,\n      }}\n      isAnimationActive={false}\n      allowEscapeViewBox={{ x: true, y: true }}\n      offset={12}\n      wrapperStyle={{ outline: \"none\", zIndex: 10 }}\n      content={(contentProps) => (\n        <SparklineTooltip\n          active={contentProps.active}\n          payload={contentProps.payload}\n          color={color}\n          format={valueFormatter}\n        />\n      )}\n    />\n  ) : null;\n\n  return (\n    <div\n      data-slot=\"sparkline\"\n      data-variant={variant}\n      aria-hidden={tooltip ? undefined : true}\n      className={cn(\n        \"h-10 w-full [&_.recharts-surface]:overflow-visible\",\n        // In dark mode the line glows in its own color.\n        \"dark:[&_:is(.recharts-area-curve,.recharts-line-curve)]:[filter:drop-shadow(0_0_6px_color-mix(in_oklab,var(--sparkline-color)_50%,transparent))]\",\n        className,\n      )}\n      style={{ ...style, [\"--sparkline-color\" as string]: color }}\n      {...props}\n    >\n      <ResponsiveContainer width=\"100%\" height=\"100%\">\n        {variant === \"line\" ? (\n          <LineChart data={points} margin={margin} accessibilityLayer={tooltip}>\n            {axis}\n            {readout}\n            <Line\n              type={curve}\n              dataKey=\"y\"\n              stroke={color}\n              strokeWidth={strokeWidth}\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n              dot={dot}\n              activeDot={activeDot}\n              isAnimationActive={animationActive}\n              animationDuration={animationDuration}\n              animationEasing=\"ease-out\"\n            />\n          </LineChart>\n        ) : (\n          <AreaChart data={points} margin={margin} accessibilityLayer={tooltip}>\n            <defs>\n              <linearGradient id={id} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                <stop\n                  offset=\"0%\"\n                  stopColor={color}\n                  stopOpacity={dots ? 0.08 : 0.32}\n                />\n                <stop\n                  offset=\"100%\"\n                  stopColor={color}\n                  stopOpacity={dots ? 0.9 : 0}\n                />\n              </linearGradient>\n              {dots ? (\n                <>\n                  <pattern\n                    id={`${id}-dots`}\n                    patternUnits=\"userSpaceOnUse\"\n                    width={4}\n                    height={4}\n                  >\n                    <circle cx={2} cy={2} r={0.9} fill=\"#fff\" />\n                  </pattern>\n                  <mask\n                    id={`${id}-mask`}\n                    maskUnits=\"userSpaceOnUse\"\n                    x={0}\n                    y={0}\n                    width=\"100%\"\n                    height=\"100%\"\n                  >\n                    <rect\n                      width=\"100%\"\n                      height=\"100%\"\n                      fill={`url(#${id}-dots)`}\n                    />\n                  </mask>\n                </>\n              ) : null}\n            </defs>\n            {axis}\n            {readout}\n            <Area\n              type={curve}\n              dataKey=\"y\"\n              stroke={color}\n              strokeWidth={strokeWidth}\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n              fill={`url(#${id})`}\n              fillOpacity={dots ? 1 : undefined}\n              dot={dot}\n              activeDot={activeDot}\n              isAnimationActive={animationActive}\n              animationDuration={animationDuration}\n              animationEasing=\"ease-out\"\n              shape={\n                dots\n                  ? (shapeProps: AreaRevealShapeProps) => (\n                      <DotGridAreaShape {...shapeProps} maskId={`${id}-mask`} />\n                    )\n                  : undefined\n              }\n            />\n          </AreaChart>\n        )}\n      </ResponsiveContainer>\n    </div>\n  );\n}\n\nexport { Sparkline };\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/trend-sparkline. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
