@ark-ui/solid
Version:
A collection of unstyled, accessible UI components for Solid, utilizing state machines for seamless interaction.
40 lines (37 loc) • 1.14 kB
JavaScript
import { createComponent, Dynamic, mergeProps } from 'solid-js/web';
import { mergeProps as mergeProps$1 } from '@zag-js/solid';
import { splitProps } from 'solid-js';
// src/components/factory.tsx
var withAsProp = (Component) => {
const ArkComponent = (props) => {
const [localProps, parentProps] = splitProps(props, ["asChild"]);
if (localProps.asChild) {
const propsFn = (userProps) => {
const [, restProps] = splitProps(parentProps, ["ref"]);
return mergeProps$1(restProps, userProps);
};
return localProps.asChild(propsFn);
}
return createComponent(Dynamic, mergeProps({
component: Component
}, parentProps));
};
return ArkComponent;
};
function jsxFactory() {
const cache = /* @__PURE__ */ new Map();
return new Proxy(withAsProp, {
apply(_target, _thisArg, argArray) {
return withAsProp(argArray[0]);
},
get(_, element) {
const asElement = element;
if (!cache.has(asElement)) {
cache.set(asElement, withAsProp(asElement));
}
return cache.get(asElement);
}
});
}
var ark = jsxFactory();
export { ark };