UNPKG

@ark-ui/vue

Version:

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

40 lines (37 loc) 1.11 kB
import { defineComponent, h } from 'vue'; import { Dynamic } from '../utils/dynamic.js'; const SELF_CLOSING_TAGS = "br, hr, img, input, area, textarea".split(", "); const isSelfClosingTag = (tag) => typeof tag === "string" && SELF_CLOSING_TAGS.includes(tag); const withAsChild = (component) => { return defineComponent({ name: "Polymorphic", inheritAttrs: false, props: { asChild: { type: Boolean, default: false } }, setup(props, { attrs, slots }) { if (!props.asChild) return () => h(component, attrs, isSelfClosingTag(component) ? void 0 : slots.default?.()); return () => h(Dynamic, attrs, slots); } }); }; function jsxFactory() { const cache = /* @__PURE__ */ new Map(); const factory = new Proxy(withAsChild, { apply(_target, _thisArg, argArray) { return withAsChild(argArray[0]); }, get(_, element) { if (!cache.has(element)) { cache.set(element, withAsChild(element)); } return cache.get(element); } }); return factory; } const ark = jsxFactory(); export { ark, jsxFactory };