{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric",
  "title": "Metric",
  "description": "Metric from the Get IT Done design system.",
  "dependencies": [
    "@radix-ui/react-slot@^1.5.0",
    "class-variance-authority@^0.7.0"
  ],
  "registryDependencies": [
    "https://zero-design.itdone.de/r/labels-context.json",
    "https://zero-design.itdone.de/r/recipes.json",
    "https://zero-design.itdone.de/r/utils.json",
    "https://zero-design.itdone.de/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/ui/metric.tsx",
      "content": "'use client';\n\nimport { Slot, Slottable } from '@radix-ui/react-slot';\nimport { cva, type VariantProps } from 'class-variance-authority';\nimport * as React from 'react';\n\nimport { focusRing, transitionBase } from '@/lib/recipes';\nimport { cn } from '@/lib/utils';\nimport { usePreset } from '@/components/ui/labels-context';\n\n// Figma: Metric item 1560:266217 (Variant=Strip|Compact|Compact chart|Simple|Icon 01|Icon 02|Chart) and KpiStrip 10151:371413.\nconst metricItemVariants = cva(['relative min-w-0 text-left', ...transitionBase], {\n  variants: {\n    variant: {\n      // Flat cell inside a KpiStrip: no surface, optional left divider.\n      strip: 'flex min-w-0 flex-1 flex-col justify-center gap-micro px-4 py-1',\n      // Self-contained one-line tile.\n      compact: 'flex h-kpi-strip items-center gap-2 rounded-surface border border-solid border-border bg-card pl-4 pr-3 py-2 shadow-elevation-surface',\n      // Stacked card with optional leading icon and trailing chart slot.\n      card: 'flex flex-col gap-2 rounded-surface border border-solid border-border bg-card shadow-elevation-surface',\n    },\n    // Card padding: `compact` tightens p-6 to p-4 (footer action bleed follows).\n    density: {\n      default: '',\n      compact: '',\n    },\n    interactive: {\n      true: ['cursor-pointer', ...focusRing, 'hover:bg-muted', 'active:bg-muted-strong'],\n      false: '',\n    },\n    selected: {\n      true: 'border-border-brand bg-background-brand-subtle',\n      false: '',\n    },\n    disabled: {\n      true: 'pointer-events-none opacity-disabled',\n      false: '',\n    },\n    // Anchor tile: no browser link styling, the tile keeps its own text roles.\n    link: {\n      true: 'no-underline text-inherit',\n      false: '',\n    },\n  },\n  compoundVariants: [\n    // The strip clips overflow, so its focus ring sits inside the tile (same recipe as ButtonGroup).\n    { variant: 'strip', interactive: true, className: 'focus-visible:ring-inset focus-visible:ring-offset-0' },\n    { variant: 'strip', selected: true, className: 'border-b-2 border-solid' },\n    { variant: 'card', density: 'default', className: 'p-6' },\n    { variant: 'card', density: 'compact', className: 'p-4' },\n  ],\n  defaultVariants: { variant: 'strip', density: 'default', interactive: false, selected: false, disabled: false, link: false },\n});\n\nconst deltaToneClass = {\n  neutral: 'text-text-subtle',\n  success: 'text-text-success',\n  destructive: 'text-text-destructive',\n  warning: 'text-text-warning',\n} as const;\n\nconst deltaChipClass = {\n  neutral: 'bg-muted text-text-muted',\n  success: 'bg-background-success-subtle text-general-success-on-container',\n  destructive: 'bg-background-destructive-subtle text-text-destructive-on-subtle',\n  warning: 'bg-background-warning-subtle text-general-warning-on-container',\n} as const;\n\nexport type MetricDeltaTone = keyof typeof deltaToneClass;\n\nexport interface MetricItemProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, 'onClick'>,\n    // Partial keeps both optional whatever cva version the consumer resolves (cva 0.7.1 types defaulted variants as required).\n    Partial<Pick<VariantProps<typeof metricItemVariants>, 'variant' | 'density'>> {\n  label: React.ReactNode;\n  value: React.ReactNode;\n  // Change vs. a previous period, e.g. \"+3 vs last week\".\n  delta?: React.ReactNode;\n  deltaTone?: MetricDeltaTone;\n  // Left separator line (strip variant). KpiStrip hides it on the first item automatically.\n  divider?: boolean;\n  selected?: boolean;\n  loading?: boolean;\n  disabled?: boolean;\n  // Makes the item a real button (filter-by-metric pattern). With `href` or `asChild` it is a click listener on the link.\n  onClick?: React.MouseEventHandler<HTMLButtonElement>;\n  // Makes the item a real link (`<a href>`): middle click, new tab and the context menu work. Label, value, delta and caption form the link name. Wins over `onClick` as the element, so it is never a button.\n  href?: string;\n  target?: React.HTMLAttributeAnchorTarget;\n  rel?: string;\n  // The single child is the link element (Next.js `Link`, router link). The tile classes, state and content are merged into it. Replaces the extra-content `children`, which is not rendered then.\n  asChild?: boolean;\n  // Leading icon. Card: icon tile above the label. Strip and compact: small decorative icon before the label.\n  icon?: React.ReactNode;\n  // Supporting line under the value, e.g. \"Target 160 h\" (all variants).\n  caption?: React.ReactNode;\n  // Trailing chart or sparkline slot (compact, card).\n  chart?: React.ReactNode;\n  // Action row at the bottom edge of the card variant (\"View report\" link or button).\n  footerAction?: React.ReactNode;\n}\n\nconst MetricItem = React.forwardRef<HTMLElement, MetricItemProps>(\n  (\n    {\n      className,\n      variant = 'strip',\n      density = 'default',\n      label,\n      value,\n      delta,\n      deltaTone = 'neutral',\n      divider = true,\n      selected = false,\n      loading = false,\n      disabled = false,\n      onClick,\n      href,\n      target,\n      rel,\n      asChild = false,\n      icon,\n      caption,\n      chart,\n      footerAction,\n      children,\n      ...props\n    },\n    ref,\n  ) => {\n    const isStrip = variant === 'strip';\n    const isLink = (Boolean(href) || asChild) && !disabled && !loading;\n    const interactive = (Boolean(onClick) || isLink) && !disabled && !loading;\n    const classes = cn(metricItemVariants({ variant, density, interactive, selected, disabled, link: isLink }), className);\n\n    const labelClass = cn('block truncate', isStrip || variant === 'compact' ? 'typography-kpi-label' : 'typography-label', selected ? 'text-text-brand-on-subtle' : 'text-text-subtle');\n    const valueClass = isStrip || variant === 'compact' ? 'typography-kpi-value' : 'typography-kpi-value-lg';\n    // Skeleton bars keep the loaded line geometry: with the same type role, and the real text as transparent filler when the consumer passes it while loading, they wrap and measure exactly like the loaded item. Without text they fall back to a fixed width.\n    const bar = 'rounded-item bg-overlay-skeleton-default text-transparent motion-reduce:animate-none select-none';\n    const filler = (content: React.ReactNode, width: string) => (content ? <span className={cn(bar, 'break-words md:truncate')}>{content}</span> : <span className={cn(bar, 'inline-block align-top', width)}>&nbsp;</span>);\n\n    const body = loading ? (\n      <>\n        {icon && variant === 'card' ? <span className=\"mb-2 flex h-avatar-lg w-avatar-lg items-center justify-center rounded-full bg-background-brand-subtle text-icon-brand\">{icon}</span> : null}\n        <span className={labelClass}>{label}</span>\n        <span className=\"flex items-baseline gap-2 max-md:flex-wrap\" aria-hidden=\"true\">\n          <span className={valueClass}>{filler(value, 'w-16')}</span>\n          <span className=\"typography-kpi-label break-words md:truncate\">{filler(delta, 'w-12')}</span>\n        </span>\n        {caption ? <span className=\"typography-kpi-label block break-words md:truncate\" aria-hidden=\"true\">{filler(caption, 'w-24')}</span> : null}\n      </>\n    ) : (\n      <>\n        {icon && variant === 'card' ? <span className=\"mb-2 flex h-avatar-lg w-avatar-lg items-center justify-center rounded-full bg-background-brand-subtle text-icon-brand\">{icon}</span> : null}\n        {icon && variant !== 'card' ? (\n          <span className=\"flex min-w-0 items-center gap-1\">\n            <span aria-hidden=\"true\" className=\"inline-flex shrink-0 text-icon-subtle [&>svg]:h-icon-md [&>svg]:w-icon-md\">\n              {icon}\n            </span>\n            <span className={cn('block truncate typography-kpi-label', selected ? 'text-text-brand-on-subtle' : 'text-text-subtle')}>{label}</span>\n          </span>\n        ) : (\n          <span className={labelClass}>{label}</span>\n        )}\n        <span className=\"flex items-baseline gap-2 max-md:flex-wrap\">\n          <span className={cn('text-text-default', valueClass)}>{value}</span>\n          {delta ? (\n            <span\n              className={cn(\n                'typography-kpi-label break-words md:truncate',\n                variant === 'card' ? cn('rounded-full px-2', deltaChipClass[deltaTone]) : deltaToneClass[deltaTone],\n              )}\n            >\n              {delta}\n            </span>\n          ) : null}\n        </span>\n        {caption ? <span className={cn('typography-kpi-label block break-words md:truncate', selected ? 'text-general-brand-on-container' : 'text-text-subtle')}>{caption}</span> : null}\n        {asChild ? null : children}\n      </>\n    );\n\n    const inner = (\n      <>\n        {isStrip && divider ? <span aria-hidden=\"true\" data-kpi-divider=\"\" className=\"absolute inset-y-0 left-0 w-px bg-border\" /> : null}\n        {variant === 'card' ? body : <span className=\"flex min-w-0 flex-1 flex-col gap-micro\">{body}</span>}\n        {!loading && chart ? <span className=\"shrink-0\">{chart}</span> : null}\n        {variant === 'card' && !loading && !interactive && footerAction ? (\n          <span className={cn('mt-4 flex items-center justify-end border-t border-solid border-border py-4', density === 'compact' ? '-mx-4 -mb-4 px-4' : '-mx-6 -mb-6 px-6')}>{footerAction}</span>\n        ) : null}\n      </>\n    );\n\n    if (isLink) {\n      const linkProps = {\n        ref: ref as React.Ref<HTMLAnchorElement>,\n        className: classes,\n        'aria-current': selected ? ('true' as const) : undefined,\n        'data-selected': selected || undefined,\n        onClick: onClick as unknown as React.MouseEventHandler<HTMLAnchorElement> | undefined,\n        ...(props as React.AnchorHTMLAttributes<HTMLAnchorElement>),\n      };\n      if (asChild) {\n        return (\n          <Slot {...linkProps}>\n            <Slottable>{children}</Slottable>\n            {inner}\n          </Slot>\n        );\n      }\n      return (\n        <a href={href} target={target} rel={rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined)} {...linkProps}>\n          {inner}\n        </a>\n      );\n    }\n    if (interactive) {\n      return (\n        <button\n          ref={ref as React.Ref<HTMLButtonElement>}\n          type=\"button\"\n          className={classes}\n          aria-pressed={selected}\n          onClick={onClick}\n          {...(props as React.ButtonHTMLAttributes<HTMLButtonElement>)}\n        >\n          {inner}\n        </button>\n      );\n    }\n    return (\n      <div\n        ref={ref as React.Ref<HTMLDivElement>}\n        className={classes}\n        aria-busy={loading || undefined}\n        aria-disabled={disabled || undefined}\n        data-selected={selected || undefined}\n        {...(props as React.HTMLAttributes<HTMLDivElement>)}\n      >\n        {inner}\n      </div>\n    );\n  },\n);\nMetricItem.displayName = 'MetricItem';\n\n// KPI strip: one bordered bar holding several strip metric items separated by dividers. Below md the items wrap into two columns.\nexport interface KpiStripProps extends React.HTMLAttributes<HTMLDivElement> {\n  // Fill of the strip. `card` (default) is the card surface. `raised` is for a strip on a `background-subtle` section: in dark the card fill can be darker than that section (zero theme), so `raised` uses the `surface-strip-raised` role (card in light, muted in dark) and never sinks below its surroundings.\n  surface?: 'card' | 'raised';\n}\n\nconst KpiStrip = React.forwardRef<HTMLDivElement, KpiStripProps>(({ className, surface = 'card', ...props }, ref) => {\n  const zero = usePreset() === 'zero';\n  return (\n  <div\n    ref={ref}\n    role=\"group\"\n    className={cn(\n      'grid w-full grid-cols-2 items-stretch overflow-hidden rounded-surface border border-solid border-border md:flex',\n      surface === 'raised' ? 'bg-surface-strip-raised' : 'bg-card',\n      zero && 'md:min-h-[var(--size-kpi-strip)]',\n      '[&>:first-child_[data-kpi-divider]]:hidden',\n      // Below md the grid wraps: rows get a top rule, the first item of a row has no left divider.\n      'max-md:[&>*]:py-3 max-md:[&>:nth-child(n+3)]:border-t max-md:[&>:nth-child(n+3)]:border-solid max-md:[&>:nth-child(n+3)]:border-border max-md:[&>:nth-child(odd)_[data-kpi-divider]]:hidden',\n      className,\n    )}\n    {...props}\n  />\n  );\n});\nKpiStrip.displayName = 'KpiStrip';\n\nexport { KpiStrip, MetricItem, metricItemVariants };\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}