{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-pill-group",
  "title": "Pill Group",
  "description": "A horizontal filter bar with pill-shaped toggle buttons, item counts, per-item intent colors, icon support, and automatic scroll overflow with fade indicators.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/button",
    "@lema-ds/skeleton",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider",
    "@lema-ds/tokens"
  ],
  "files": [
    {
      "path": "components/ds/ds-pill-group.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport type { HTMLAttributes } from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { Button } from \"@/components/ui/button\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport type PillGroupIntent = \"default\" | \"success\" | \"warning\" | \"destructive\"\nexport type PillGroupSize = \"sm\" | \"md\" | \"lg\"\n\nexport interface PillGroupItem {\n  value: string\n  label: string\n  /** Numeric count shown as a dimmed suffix next to the label. */\n  count?: number\n  /** Lucide icon component rendered before the label. */\n  icon?: React.ElementType\n  /** Disables this individual item without affecting the rest. */\n  disabled?: boolean\n  /** Active-state color. Defaults to \"default\" (inverted bg-foreground). */\n  intent?: PillGroupIntent\n}\n\nexport interface PillGroupProps extends Omit<\n  HTMLAttributes<HTMLDivElement>,\n  \"onChange\" | \"defaultValue\"\n> {\n  items: PillGroupItem[]\n  /**\n   * Controlled selected value(s).\n   * Pass a `string` for single-select or `string[]` for multi-select.\n   * Pass `null` to represent \"nothing selected\".\n   */\n  value?: string | string[] | null\n  /** Initial selected value(s) for uncontrolled usage. */\n  defaultValue?: string | string[] | null\n  /** Allow selecting multiple items simultaneously. */\n  multiple?: boolean\n  onChange?: (value: string | string[] | null) => void\n  size?: PillGroupSize\n  /**\n   * Show counts next to item labels.\n   * Auto-enabled when at least one item has a `count` field.\n   */\n  showCount?: boolean\n  loading?: boolean\n  disabled?: boolean\n  locale?: UILocale\n  /** Accessible label for the filter group. Falls back to i18n string. */\n  label?: string\n  /** Number of skeleton pills shown while loading. Defaults to items.length or 3. */\n  skeletonCount?: number\n}\n\nexport type PillGroupItemVariants = VariantProps<typeof pillGroupItemVariants>\n\n// ── Variants ───────────────────────────────────────────────────────────────\n\nexport const pillGroupItemVariants = cva(\n  [\n    \"relative inline-flex shrink-0 items-center gap-1 rounded-full font-medium select-none\",\n    // Override Button's unconditional transition-colors with a motion-safe version\n    \"motion-safe:transition-colors motion-safe:duration-150 motion-reduce:transition-none\",\n    \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:outline-none\",\n    \"disabled:pointer-events-none disabled:opacity-40\",\n    // Icon sizing — overrides Button's [&_svg]:size-4 per size slot\n    \"[&_svg]:shrink-0\",\n  ],\n  {\n    variants: {\n      size: {\n        sm: \"h-8 min-h-[44px] px-2.5 text-xs [&_svg]:size-3\",\n        md: \"h-8 min-h-[44px] px-3 text-sm [&_svg]:size-3.5\",\n        lg: \"h-9 min-h-[44px] px-4 text-base [&_svg]:size-4\",\n      },\n      active: {\n        true: \"\",\n        false: \"text-muted-foreground hover:bg-accent/50 hover:text-foreground\",\n      },\n      intent: {\n        default: \"\",\n        success: \"\",\n        warning: \"\",\n        destructive: \"\",\n      },\n    },\n    compoundVariants: [\n      {\n        active: true,\n        intent: \"default\",\n        className:\n          \"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90\",\n      },\n      {\n        active: true,\n        intent: \"success\",\n        className:\n          \"bg-success text-success-foreground shadow-xs hover:bg-success/90\",\n      },\n      {\n        active: true,\n        intent: \"warning\",\n        className:\n          \"bg-warning text-warning-foreground shadow-xs hover:bg-warning/90\",\n      },\n      {\n        active: true,\n        intent: \"destructive\",\n        className:\n          \"text-destructive-foreground bg-destructive shadow-xs hover:bg-destructive/90\",\n      },\n    ],\n    defaultVariants: {\n      size: \"md\",\n      active: false,\n      intent: \"default\",\n    },\n  }\n)\n\nexport const pillGroupCountVariants = cva(\"font-normal tabular-nums\", {\n  variants: {\n    active: {\n      true: \"opacity-60\",\n      false: \"text-muted-foreground\",\n    },\n  },\n  defaultVariants: { active: false },\n})\n\n// ── Helpers ────────────────────────────────────────────────────────────────\n\nfunction useScrollFade(ref: React.RefObject<HTMLDivElement | null>) {\n  const [canScrollLeft, setCanScrollLeft] = React.useState(false)\n  const [canScrollRight, setCanScrollRight] = React.useState(false)\n\n  const check = React.useCallback(() => {\n    const el = ref.current\n    if (!el) return\n    setCanScrollLeft(el.scrollLeft > 2)\n    setCanScrollRight(el.scrollLeft < el.scrollWidth - el.clientWidth - 2)\n  }, [ref])\n\n  React.useEffect(() => {\n    const el = ref.current\n    if (!el) return\n    check()\n    el.addEventListener(\"scroll\", check, { passive: true })\n    const ro = new ResizeObserver(check)\n    ro.observe(el)\n    return () => {\n      el.removeEventListener(\"scroll\", check)\n      ro.disconnect()\n    }\n  }, [check, ref])\n\n  return { canScrollLeft, canScrollRight }\n}\n\nfunction itemIsActive(\n  value: string,\n  selection: string | string[] | null | undefined,\n  multiple: boolean\n): boolean {\n  if (selection == null) return false\n  return multiple\n    ? Array.isArray(selection) && selection.includes(value)\n    : selection === value\n}\n\nfunction nextSelection(\n  value: string,\n  selection: string | string[] | null | undefined,\n  multiple: boolean\n): string | string[] | null {\n  if (multiple) {\n    const cur = Array.isArray(selection) ? selection : []\n    return cur.includes(value)\n      ? cur.filter((v) => v !== value)\n      : [...cur, value]\n  }\n  return selection === value ? null : value\n}\n\n// ── Component ──────────────────────────────────────────────────────────────\n\nexport const PillGroup = React.forwardRef<HTMLDivElement, PillGroupProps>(\n  (\n    {\n      items,\n      value: controlledValue,\n      defaultValue = null,\n      multiple = false,\n      onChange,\n      size = \"md\",\n      showCount,\n      loading = false,\n      disabled = false,\n      locale: localeProp,\n      label,\n      skeletonCount,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const t = UI_I18N[locale].pillGroup\n    const scrollRef = React.useRef<HTMLDivElement>(null)\n    const { canScrollLeft, canScrollRight } = useScrollFade(scrollRef)\n\n    const isControlled = controlledValue !== undefined\n    const [internalValue, setInternalValue] = React.useState<\n      string | string[] | null\n    >(defaultValue ?? null)\n\n    const selection = isControlled ? controlledValue : internalValue\n\n    const handleSelect = React.useCallback(\n      (itemValue: string, itemDisabled?: boolean) => {\n        if (disabled || itemDisabled) return\n        const next = nextSelection(itemValue, selection, multiple)\n        if (!isControlled) setInternalValue(next)\n        onChange?.(next)\n      },\n      [selection, multiple, disabled, isControlled, onChange]\n    )\n\n    const hasAnyCount = items.some((it) => it.count !== undefined)\n    const shouldShowCount = showCount ?? hasAnyCount\n\n    const trackPadding = size === \"sm\" ? \"p-0.5\" : \"p-1\"\n    const pillHeight =\n      size === \"sm\"\n        ? \"h-8 min-h-[44px]\"\n        : size === \"lg\"\n          ? \"h-9 min-h-[44px]\"\n          : \"h-8 min-h-[44px]\"\n    const skeletonWidths = [\"w-12\", \"w-24\", \"w-20\", \"w-16\", \"w-28\", \"w-14\"]\n\n    if (loading) {\n      const n = skeletonCount ?? (items.length > 0 ? items.length : 3)\n      return (\n        <div\n          ref={ref}\n          data-slot=\"pill-group\"\n          className={cn(\n            \"inline-flex items-center gap-0.5 rounded-full border bg-muted/30\",\n            trackPadding,\n            className\n          )}\n          {...props}\n        >\n          {Array.from({ length: n }).map((_, i) => (\n            <Skeleton\n              key={i}\n              className={cn(\n                \"rounded-full\",\n                pillHeight,\n                skeletonWidths[i % skeletonWidths.length]\n              )}\n            />\n          ))}\n        </div>\n      )\n    }\n\n    return (\n      <div\n        ref={ref}\n        data-slot=\"pill-group\"\n        className={cn(\n          \"relative inline-flex max-w-full overflow-hidden rounded-full border bg-muted/30\",\n          trackPadding,\n          disabled && \"pointer-events-none opacity-50\",\n          className\n        )}\n        {...props}\n      >\n        {/* Left scroll-fade — appears when items overflow left */}\n        {canScrollLeft && (\n          <div\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute inset-y-0 left-0 z-10 w-10 bg-linear-to-r from-background/80 to-transparent\"\n          />\n        )}\n\n        {/* Scrollable track — hides native scrollbar cross-browser */}\n        <div\n          ref={scrollRef}\n          className=\"scrollbar-none overflow-x-auto [&::-webkit-scrollbar]:hidden\"\n        >\n          <div\n            role={multiple ? \"group\" : \"radiogroup\"}\n            aria-label={label ?? t.filterLabel}\n            aria-disabled={disabled || undefined}\n            className=\"flex items-center gap-0.5\"\n          >\n            {items.map((item) => {\n              const active = itemIsActive(item.value, selection, multiple)\n              const Icon = item.icon\n              const intent = item.intent ?? \"default\"\n\n              return (\n                <Button\n                  key={item.value}\n                  variant=\"ghost\"\n                  role={multiple ? \"checkbox\" : \"radio\"}\n                  aria-checked={active}\n                  disabled={disabled || item.disabled}\n                  onClick={() => handleSelect(item.value, item.disabled)}\n                  className={cn(\n                    pillGroupItemVariants({ size, active, intent })\n                  )}\n                  data-slot=\"pill-group-item\"\n                  data-active={active || undefined}\n                  data-value={item.value}\n                >\n                  {Icon && <Icon aria-hidden=\"true\" />}\n                  <span className=\"truncate\">{item.label}</span>\n                  {shouldShowCount && item.count !== undefined && (\n                    <span\n                      className={cn(pillGroupCountVariants({ active }))}\n                      aria-hidden=\"true\"\n                    >\n                      {item.count.toLocaleString(locale)}\n                    </span>\n                  )}\n                </Button>\n              )\n            })}\n          </div>\n        </div>\n\n        {/* Right scroll-fade — appears when items overflow right */}\n        {canScrollRight && (\n          <div\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute inset-y-0 right-0 z-10 w-10 bg-linear-to-l from-background/80 to-transparent\"\n          />\n        )}\n      </div>\n    )\n  }\n)\n\nPillGroup.displayName = \"PillGroup\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
