@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
41 lines (40 loc) • 1.5 kB
JavaScript
import { DEFAULT_ENVIRONMENT, useEnvironmentContext } from "../../providers/environment/use-environment-context.js";
import { DEFAULT_LOCALE, useLocaleContext } from "../../providers/locale/use-locale-context.js";
import { cleanProps } from "../../utils/clean-props.js";
import { useDrawerStackStore } from "./use-drawer-stack-store.js";
import * as drawer from "@zag-js/drawer";
import { computed, toValue, useId } from "vue";
import { normalizeProps as normalizeProps$1, useMachine } from "@zag-js/vue";
//#region src/components/drawer/use-drawer.ts
var useDrawer = (props = {}, emit) => {
const id = useId();
const env = useEnvironmentContext(DEFAULT_ENVIRONMENT);
const locale = useLocaleContext(DEFAULT_LOCALE);
const stack = useDrawerStackStore();
const context = computed(() => {
const localeProps = toValue(props);
return {
id,
dir: locale.value.dir,
getRootNode: env?.value.getRootNode,
stack,
...cleanProps(localeProps),
onOpenChange: (details) => {
emit?.("openChange", details);
localeProps.onOpenChange?.(details);
},
onTriggerValueChange: (details) => {
emit?.("triggerValueChange", details);
localeProps.onTriggerValueChange?.(details);
},
onSnapPointChange: (details) => {
emit?.("snapPointChange", details);
localeProps.onSnapPointChange?.(details);
}
};
});
const service = useMachine(drawer.machine, context);
return computed(() => drawer.connect(service, normalizeProps$1));
};
//#endregion
export { useDrawer };