@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
37 lines (36 loc) • 1.38 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 * as dateInput from "@zag-js/date-input";
import { computed, toValue, useId } from "vue";
import { normalizeProps as normalizeProps$1, useMachine } from "@zag-js/vue";
//#region src/components/date-input/use-date-input.ts
var useDateInput = (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);
localeProps.onFocusChange?.(details);
},
onValueChange: (details) => {
emit?.("valueChange", details);
emit?.("update:modelValue", details.value);
localeProps.onValueChange?.(details);
}
};
});
const service = useMachine(dateInput.machine, context);
return computed(() => dateInput.connect(service, normalizeProps$1));
};
//#endregion
export { useDateInput };