UNPKG

reka-ui

Version:

Vue port for Radix UI Primitives.

30 lines (28 loc) 1.07 kB
import { renderSlotFragments } from "../shared/renderSlotFragments.js"; import { Comment, cloneVNode, defineComponent, mergeProps } from "vue"; //#region src/Primitive/Slot.ts const Slot = defineComponent({ name: "PrimitiveSlot", inheritAttrs: false, setup(_, { attrs, slots }) { return () => { if (!slots.default) return null; const children = renderSlotFragments(slots.default()); const firstNonCommentChildrenIndex = children.findIndex((child) => child.type !== Comment); if (firstNonCommentChildrenIndex === -1) return children; const firstNonCommentChildren = children[firstNonCommentChildrenIndex]; delete firstNonCommentChildren.props?.ref; const mergedProps = firstNonCommentChildren.props ? mergeProps(attrs, firstNonCommentChildren.props) : attrs; const cloned = cloneVNode({ ...firstNonCommentChildren, props: {} }, mergedProps); if (children.length === 1) return cloned; children[firstNonCommentChildrenIndex] = cloned; return children; }; } }); //#endregion export { Slot }; //# sourceMappingURL=Slot.js.map