{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-sticky-feature-list",
  "title": "StickyFeatureList",
  "description": "Lista de recursos com barra lateral fixa e navegação contextual por seção.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-sticky-feature-list.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\n\n// ── Types ──\n\nexport type StickyFeatureListSize = \"sm\" | \"md\" | \"lg\"\n\nexport interface StickyFeatureListProps\n  extends\n    Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\">,\n    VariantProps<typeof stickyFeatureListRootVariants> {\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  label?: string\n  locale?: UILocale\n}\n\nexport type StickyFeatureListNavProps = React.HTMLAttributes<HTMLDivElement>\n\nexport interface StickyFeatureListItemProps\n  extends\n    Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"value\">,\n    VariantProps<typeof stickyFeatureListItemVariants> {\n  value: string\n  title: string\n  description?: string\n}\n\nexport type StickyFeatureListPanelsProps = React.HTMLAttributes<HTMLDivElement>\n\nexport interface StickyFeatureListPanelProps extends React.HTMLAttributes<HTMLDivElement> {\n  value: string\n}\n\n// ── Context ──\n\ninterface StickyFeatureListContextValue {\n  activeValue: string | undefined\n  setActiveValue: (value: string) => void\n  registerItem: (value: string, node: HTMLButtonElement | null) => void\n  focusSibling: (value: string, direction: 1 | -1) => void\n}\n\nconst StickyFeatureListContext =\n  React.createContext<StickyFeatureListContextValue | null>(null)\n\nfunction useStickyFeatureListContext(component: string) {\n  const context = React.useContext(StickyFeatureListContext)\n  if (!context) {\n    throw new Error(`${component} must be used within a <StickyFeatureList>`)\n  }\n  return context\n}\n\n// ── Variants ──\n\nexport const stickyFeatureListRootVariants = cva(\n  \"grid grid-cols-1 gap-8 lg:grid-cols-2 lg:gap-16\",\n  {\n    variants: {\n      size: { sm: \"\", md: \"\", lg: \"\" },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\nexport const stickyFeatureListItemVariants = cva(\n  \"flex w-full flex-col gap-1.5 rounded-lg border border-transparent px-4 py-4 text-left transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring data-[state=active]:border-border data-[state=active]:bg-muted data-[state=inactive]:hover:bg-accent/50\",\n  {\n    variants: {\n      size: {\n        sm: \"gap-1 px-3 py-3\",\n        md: \"gap-1.5 px-4 py-4\",\n        lg: \"gap-2 px-5 py-5\",\n      },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\nexport const stickyFeatureListItemTitleVariants = cva(\n  \"font-semibold text-foreground data-[state=inactive]:text-muted-foreground\",\n  {\n    variants: {\n      size: { sm: \"text-sm\", md: \"text-base\", lg: \"text-lg\" },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\nexport const stickyFeatureListItemDescriptionVariants = cva(\n  \"leading-relaxed text-muted-foreground\",\n  {\n    variants: {\n      size: { sm: \"text-xs\", md: \"text-sm\", lg: \"text-base\" },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\n// ── StickyFeatureList ──\n\nexport const StickyFeatureList = React.forwardRef<\n  HTMLDivElement,\n  StickyFeatureListProps\n>(\n  (\n    {\n      value: controlledValue,\n      defaultValue,\n      onValueChange,\n      label,\n      locale: localeProp,\n      size = \"md\",\n      className,\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const [internalValue, setInternalValue] = React.useState(defaultValue)\n    const isControlled = controlledValue !== undefined\n    const activeValue = isControlled ? controlledValue : internalValue\n\n    const itemsRef = React.useRef<Map<string, HTMLButtonElement | null>>(\n      new Map()\n    )\n    const orderRef = React.useRef<string[]>([])\n\n    const setActiveValue = React.useCallback(\n      (next: string) => {\n        if (!isControlled) setInternalValue(next)\n        onValueChange?.(next)\n      },\n      [isControlled, onValueChange]\n    )\n\n    const registerItem = React.useCallback(\n      (itemValue: string, node: HTMLButtonElement | null) => {\n        if (node) {\n          itemsRef.current.set(itemValue, node)\n          if (!orderRef.current.includes(itemValue)) {\n            orderRef.current.push(itemValue)\n          }\n        } else {\n          itemsRef.current.delete(itemValue)\n          orderRef.current = orderRef.current.filter((v) => v !== itemValue)\n        }\n      },\n      []\n    )\n\n    const focusSibling = React.useCallback(\n      (fromValue: string, direction: 1 | -1) => {\n        const order = orderRef.current\n        const currentIndex = order.indexOf(fromValue)\n        if (currentIndex === -1 || order.length === 0) return\n        const nextIndex =\n          (currentIndex + direction + order.length) % order.length\n        const nextValue = order[nextIndex]\n        const node = itemsRef.current.get(nextValue)\n        if (!node) return\n        node.focus()\n        setActiveValue(nextValue)\n      },\n      [setActiveValue]\n    )\n\n    // Auto-select the first registered item when no value/defaultValue is\n    // provided, so the roving-tabindex list always has one focusable tab.\n    React.useEffect(() => {\n      if (!isControlled && internalValue === undefined && orderRef.current[0]) {\n        setInternalValue(orderRef.current[0])\n      }\n      // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, [])\n\n    return (\n      <StickyFeatureListContext.Provider\n        value={{ activeValue, setActiveValue, registerItem, focusSibling }}\n      >\n        <div\n          ref={ref}\n          className={cn(stickyFeatureListRootVariants({ size }), className)}\n          data-slot=\"sticky-feature-list\"\n          aria-label={label ?? UI_I18N[locale].stickyFeatureList.sectionNav}\n          {...props}\n        >\n          {children}\n        </div>\n      </StickyFeatureListContext.Provider>\n    )\n  }\n)\nStickyFeatureList.displayName = \"StickyFeatureList\"\n\n// ── StickyFeatureListNav ──\n\nexport const StickyFeatureListNav = React.forwardRef<\n  HTMLDivElement,\n  StickyFeatureListNavProps\n>(({ className, ...props }, ref) => (\n  <div\n    ref={ref}\n    role=\"tablist\"\n    aria-orientation=\"vertical\"\n    className={cn(\"flex flex-col gap-2\", className)}\n    data-slot=\"sticky-feature-list-nav\"\n    {...props}\n  />\n))\nStickyFeatureListNav.displayName = \"StickyFeatureListNav\"\n\n// ── StickyFeatureListItem ──\n\nexport const StickyFeatureListItem = React.forwardRef<\n  HTMLButtonElement,\n  StickyFeatureListItemProps\n>(({ value, title, description, size = \"md\", className, ...props }, ref) => {\n  const { activeValue, setActiveValue, registerItem, focusSibling } =\n    useStickyFeatureListContext(\"StickyFeatureListItem\")\n  const isActive = activeValue === value\n\n  const setRefs = React.useCallback(\n    (node: HTMLButtonElement | null) => {\n      registerItem(value, node)\n      if (typeof ref === \"function\") ref(node)\n      else if (ref)\n        (ref as React.RefObject<HTMLButtonElement | null>).current = node\n    },\n    [ref, registerItem, value]\n  )\n\n  const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n    if (event.key === \"ArrowDown\") {\n      event.preventDefault()\n      focusSibling(value, 1)\n    } else if (event.key === \"ArrowUp\") {\n      event.preventDefault()\n      focusSibling(value, -1)\n    }\n    props.onKeyDown?.(event)\n  }\n\n  return (\n    <button\n      ref={setRefs}\n      type=\"button\"\n      role=\"tab\"\n      id={`sticky-feature-tab-${value}`}\n      aria-selected={isActive}\n      aria-controls={`sticky-feature-panel-${value}`}\n      tabIndex={isActive ? 0 : -1}\n      data-state={isActive ? \"active\" : \"inactive\"}\n      onClick={() => setActiveValue(value)}\n      onKeyDown={handleKeyDown}\n      className={cn(stickyFeatureListItemVariants({ size }), className)}\n      {...props}\n    >\n      <span\n        data-state={isActive ? \"active\" : \"inactive\"}\n        className={cn(stickyFeatureListItemTitleVariants({ size }))}\n      >\n        {title}\n      </span>\n      {description && (\n        <span\n          className={cn(stickyFeatureListItemDescriptionVariants({ size }))}\n        >\n          {description}\n        </span>\n      )}\n    </button>\n  )\n})\nStickyFeatureListItem.displayName = \"StickyFeatureListItem\"\n\n// ── StickyFeatureListPanels ──\n\nexport const StickyFeatureListPanels = React.forwardRef<\n  HTMLDivElement,\n  StickyFeatureListPanelsProps\n>(({ className, children, ...props }, ref) => (\n  <div\n    ref={ref}\n    className={cn(\"sticky top-24 h-fit\", className)}\n    data-slot=\"sticky-feature-list-panels\"\n    {...props}\n  >\n    {children}\n  </div>\n))\nStickyFeatureListPanels.displayName = \"StickyFeatureListPanels\"\n\n// ── StickyFeatureListPanel ──\n\nexport const StickyFeatureListPanel = React.forwardRef<\n  HTMLDivElement,\n  StickyFeatureListPanelProps\n>(({ value, className, children, ...props }, ref) => {\n  const { activeValue } = useStickyFeatureListContext(\"StickyFeatureListPanel\")\n  const isActive = activeValue === value\n\n  return (\n    <div\n      ref={ref}\n      role=\"tabpanel\"\n      id={`sticky-feature-panel-${value}`}\n      aria-labelledby={`sticky-feature-tab-${value}`}\n      hidden={!isActive}\n      className={cn(\"overflow-hidden rounded-2xl\", className)}\n      {...props}\n    >\n      {children}\n    </div>\n  )\n})\nStickyFeatureListPanel.displayName = \"StickyFeatureListPanel\"\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
