{"version":3,"file":"slot.cjs","names":["Slot: FC<SlotProps>","useValidChildren","useFindChild","Children","SlotClone: FC<SlotCloneProps>","mergeProps","Slottable: FC<PropsWithChildren>"],"sources":["../../../../src/components/slot/slot.tsx"],"sourcesContent":["import type {\n  FC,\n  HTMLAttributes,\n  PropsWithChildren,\n  RefAttributes,\n} from \"react\"\nimport { Children, cloneElement, isValidElement } from \"react\"\nimport { mergeProps } from \"../../core\"\nimport { useFindChild, useValidChildren } from \"../../utils\"\n\nexport interface SlotProps\n  extends HTMLAttributes<HTMLElement>,\n    RefAttributes<HTMLElement>,\n    PropsWithChildren {}\n\n/**\n * `Slot` is a component that merges its props onto its immediate child.\n *\n * @see https://yamada-ui.com/docs/components/slot\n */\nexport const Slot: FC<SlotProps> = ({ children, ...rest }) => {\n  const validChildren = useValidChildren(children)\n  const slottable = useFindChild(validChildren, Slottable)\n\n  if (slottable) {\n    const newElement = slottable.props.children\n\n    const newChildren = validChildren.map((child) => {\n      if (child === slottable) {\n        if (Children.count(newElement) > 1) return Children.only(null)\n        return isValidElement<PropsWithChildren>(newElement)\n          ? newElement.props.children\n          : null\n      } else {\n        return child\n      }\n    })\n\n    return (\n      <SlotClone {...rest}>\n        {isValidElement(newElement)\n          ? cloneElement(newElement, undefined, newChildren)\n          : null}\n      </SlotClone>\n    )\n  }\n\n  return <SlotClone {...rest}>{children}</SlotClone>\n}\n\ninterface SlotCloneProps\n  extends RefAttributes<HTMLElement>,\n    PropsWithChildren {}\n\nconst SlotClone: FC<SlotCloneProps> = ({ children, ...rest }) => {\n  if (isValidElement<RefAttributes<HTMLElement>>(children))\n    return cloneElement(children, mergeProps(rest, children.props)())\n\n  return Children.count(children) > 1 ? Children.only(null) : null\n}\n\nexport const Slottable: FC<PropsWithChildren> = ({ children }) => {\n  // eslint-disable-next-line react/jsx-no-useless-fragment\n  return <>{children}</>\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAaA,QAAuB,EAAE,SAAU,GAAG,WAAW;CAC5D,MAAM,gBAAgBC,kCAAiB,SAAS;CAChD,MAAM,YAAYC,8BAAa,eAAe,UAAU;AAExD,KAAI,WAAW;EACb,MAAM,aAAa,UAAU,MAAM;EAEnC,MAAM,cAAc,cAAc,KAAK,UAAU;AAC/C,OAAI,UAAU,WAAW;AACvB,QAAIC,eAAS,MAAM,WAAW,GAAG,EAAG,QAAOA,eAAS,KAAK,KAAK;AAC9D,qCAAyC,WAAW,GAChD,WAAW,MAAM,WACjB;SAEJ,QAAO;IAET;AAEF,SACE,2CAAC;GAAU,GAAI;uCACG,WAAW,2BACV,YAAY,QAAW,YAAY,GAChD;IACM;;AAIhB,QAAO,2CAAC;EAAU,GAAI;EAAO;GAAqB;;AAOpD,MAAMC,aAAiC,EAAE,SAAU,GAAG,WAAW;AAC/D,+BAA+C,SAAS,CACtD,gCAAoB,UAAUC,yBAAW,MAAM,SAAS,MAAM,EAAE,CAAC;AAEnE,QAAOF,eAAS,MAAM,SAAS,GAAG,IAAIA,eAAS,KAAK,KAAK,GAAG;;AAG9D,MAAaG,aAAoC,EAAE,eAAe;AAEhE,QAAO,yEAAG,WAAY"}