@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
35 lines (32 loc) • 1.23 kB
JavaScript
import * as steps from '@zag-js/steps';
import { useMachine, normalizeProps } from '@zag-js/vue';
import { useId, computed, toValue } from 'vue';
import { useEnvironmentContext, DEFAULT_ENVIRONMENT } from '../../providers/environment/use-environment-context.js';
import { useLocaleContext, DEFAULT_LOCALE } from '../../providers/locale/use-locale-context.js';
import { cleanProps } from '../../utils/clean-props.js';
function useSteps(props = {}, emit) {
const env = useEnvironmentContext(DEFAULT_ENVIRONMENT);
const locale = useLocaleContext(DEFAULT_LOCALE);
const id = useId();
const context = computed(() => {
const localProps = toValue(props);
return {
id,
dir: locale.value.dir,
getRootNode: env?.value?.getRootNode,
...cleanProps(localProps),
onStepChange: (details) => {
emit?.("stepChange", details);
emit?.("update:step", details.step);
localProps.onStepChange?.(details);
},
onStepComplete: () => {
emit?.("stepComplete");
localProps.onStepComplete?.();
}
};
});
const service = useMachine(steps.machine, context);
return computed(() => steps.connect(service, normalizeProps));
}
export { useSteps };