UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

35 lines (34 loc) 1.13 kB
let vue = require("vue"); let _zag_js_vue = require("@zag-js/vue"); //#region src/utils/dynamic.ts var Dynamic = (0, vue.defineComponent)({ name: "Dynamic", inheritAttrs: false, setup(_, { attrs, slots }) { return () => { if (!slots.default) return null; const children = renderSlotFragments(slots.default()); const [firstChildren, ...otherChildren] = children; if (firstChildren && Object.keys(attrs).length > 0) { delete firstChildren.props?.ref; const mergedProps = (0, _zag_js_vue.mergeProps)(attrs, firstChildren.props ?? {}); const cloned = (0, vue.cloneVNode)(firstChildren, mergedProps); for (const prop in mergedProps) if (prop.startsWith("on")) { cloned.props ||= {}; cloned.props[prop] = mergedProps[prop]; } return children.length === 1 ? cloned : [cloned, ...otherChildren]; } return children; }; } }); function renderSlotFragments(children) { if (!children) return []; return children.flatMap((child) => { if (child.type === vue.Fragment) return renderSlotFragments(child.children); return [child]; }); } //#endregion exports.Dynamic = Dynamic;