{
  "$schema": "https://registry.buildy.tw/schema/registry-item.json",
  "dependencies": [],
  "description": "UI8Kit 3 Slot primitive (unstyled), from @ui8kit/registry",
  "devDependencies": [],
  "digest": "0.1.0",
  "files": [
    {
      "content": "import {\n  Children,\n  cloneElement,\n  forwardRef,\n  isValidElement,\n  type ComponentProps,\n  type ElementType,\n  type MutableRefObject,\n  type ReactElement,\n  type ReactNode,\n  type Ref,\n} from \"react\";\nimport { cn } from \"../../utils\";\n\n/**\n * Slot accepts arbitrary props and merges them onto its single child.\n * Props are intentionally permissive (string-keyed) because Slot is a\n * composition primitive — the parent component decides what to forward.\n */\nexport type SlotProps = {\n  children?: ReactNode;\n  className?: string;\n  ref?: Ref<HTMLElement>;\n  [key: string]: unknown;\n};\n\nfunction mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T) => {\n    for (const r of refs) {\n      if (typeof r === \"function\") {\n        r(node);\n      } else if (r && typeof r === \"object\") {\n        (r as MutableRefObject<T>).current = node;\n      }\n    }\n  };\n}\n\nfunction isEventHandler(key: string, value: unknown): value is (...args: unknown[]) => void {\n  return key.startsWith(\"on\") && typeof value === \"function\";\n}\n\n/**\n * Slot merges its props onto its single child element (Radix-style `asChild`).\n *\n * - `className` is merged via `cn` (clsx + tailwind-merge), so caller classes win.\n * - `ref` is merged with the child's own ref.\n * - `on*` event handlers fire child-first, then slot's.\n * - Other props from slot override child's (slot wins).\n *\n * Use this to compose components: `<Button asChild><a href=\"/x\">x</a></Button>`.\n */\nexport const Slot = forwardRef<HTMLElement, SlotProps>(function Slot(\n  { children, className, ...rest },\n  ref\n) {\n  const child = Children.toArray(children as ReactNode[])[0] as ReactNode;\n  if (!isValidElement(child)) {\n    return null;\n  }\n\n  const childProps = (child as ReactElement<Record<string, unknown>>).props;\n  const childRef = (childProps as { ref?: Ref<HTMLElement> }).ref as Ref<HTMLElement> | undefined;\n\n  const merged: Record<string, unknown> = { ...childProps };\n  for (const [key, value] of Object.entries(rest)) {\n    if (isEventHandler(key, value)) {\n      const slotHandler = value;\n      const childHandler = childProps[key];\n      if (typeof childHandler === \"function\") {\n        merged[key] = (...args: unknown[]) => {\n          (childHandler as (...a: unknown[]) => void)(...args);\n          slotHandler(...args);\n        };\n      } else {\n        merged[key] = slotHandler;\n      }\n    } else if (value !== undefined) {\n      merged[key] = value;\n    }\n  }\n\n  const childClassName =\n    typeof childProps.className === \"string\" ? childProps.className : undefined;\n  merged.className = cn(String(className ?? \"\"), childClassName);\n  merged.ref = mergeRefs(ref, childRef);\n\n  return cloneElement(child as ReactElement<Record<string, unknown>>, merged);\n});\n\nSlot.displayName = \"Slot\";\n\nexport type SlotChildProps<C extends ElementType> = ComponentProps<C> & {\n  asChild?: boolean;\n  children?: ReactNode;\n};\n",
      "path": "kit/ui/slot/slot.tsx",
      "target": "kit/ui/slot/slot.tsx"
    }
  ],
  "meta": {
    "category": "kit",
    "kind": "primitive",
    "tags": [
      "react",
      "primitive"
    ]
  },
  "name": "kit-slot",
  "registryDependencies": [
    "utils"
  ],
  "runtime": "react",
  "title": "Kit Slot",
  "type": "registry:ui"
}
