@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
48 lines (45 loc) • 1.77 kB
JavaScript
import * as datePicker from '@zag-js/date-picker';
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';
const useDatePicker = (props = {}, emit) => {
const id = useId();
const env = useEnvironmentContext(DEFAULT_ENVIRONMENT);
const locale = useLocaleContext(DEFAULT_LOCALE);
const context = computed(() => {
const localeProps = toValue(props);
return {
id,
dir: locale.value.dir,
locale: locale.value.locale,
value: localeProps.modelValue,
getRootNode: env?.value.getRootNode,
...cleanProps(localeProps),
onFocusChange: (details) => {
emit?.("focusChange", details);
emit?.("update:focusedValue", details.focusedValue);
localeProps.onFocusChange?.(details);
},
onViewChange: (details) => {
emit?.("viewChange", details);
emit?.("update:view", details.view);
localeProps.onViewChange?.(details);
},
onOpenChange: (details) => {
emit?.("openChange", details);
emit?.("update:open", details.open);
localeProps.onOpenChange?.(details);
},
onValueChange: (details) => {
emit?.("valueChange", details);
emit?.("update:modelValue", details.value);
localeProps.onValueChange?.(details);
}
};
});
const service = useMachine(datePicker.machine, context);
return computed(() => datePicker.connect(service, normalizeProps));
};
export { useDatePicker };