UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

47 lines (45 loc) 1.91 kB
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); const require_children = require('../../utils/children.cjs'); const require_props = require('../../core/components/props.cjs'); let react = require("react"); react = require_rolldown_runtime.__toESM(react); let react_jsx_runtime = require("react/jsx-runtime"); react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime); //#region src/components/slot/slot.tsx /** * `Slot` is a component that merges its props onto its immediate child. * * @see https://yamada-ui.com/docs/components/slot */ const Slot = ({ children,...rest }) => { const validChildren = require_children.useValidChildren(children); const slottable = require_children.useFindChild(validChildren, Slottable); if (slottable) { const newElement = slottable.props.children; const newChildren = validChildren.map((child) => { if (child === slottable) { if (react.Children.count(newElement) > 1) return react.Children.only(null); return (0, react.isValidElement)(newElement) ? newElement.props.children : null; } else return child; }); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlotClone, { ...rest, children: (0, react.isValidElement)(newElement) ? (0, react.cloneElement)(newElement, void 0, newChildren) : null }); } return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlotClone, { ...rest, children }); }; const SlotClone = ({ children,...rest }) => { if ((0, react.isValidElement)(children)) return (0, react.cloneElement)(children, require_props.mergeProps(rest, children.props)()); return react.Children.count(children) > 1 ? react.Children.only(null) : null; }; const Slottable = ({ children }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children }); }; //#endregion exports.Slot = Slot; exports.Slottable = Slottable; //# sourceMappingURL=slot.cjs.map