UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

50 lines (49 loc) 1.8 kB
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 { useFieldContext } from "../field/use-field-context.js"; import * as pinInput from "@zag-js/pin-input"; import { computed, toValue, useId } from "vue"; import { normalizeProps as normalizeProps$1, useMachine } from "@zag-js/vue"; //#region src/components/pin-input/use-pin-input.ts var usePinInput = (props = {}, emit) => { const id = useId(); const env = useEnvironmentContext(DEFAULT_ENVIRONMENT); const locale = useLocaleContext(DEFAULT_LOCALE); const field = useFieldContext(); const context = computed(() => { const localeProps = toValue(props); return { id, ids: { label: field?.value.ids.label, hiddenInput: field?.value.ids.control }, disabled: field?.value.disabled, readOnly: field?.value.readOnly, required: field?.value.required, invalid: field?.value.invalid, dir: locale.value.dir, value: localeProps.modelValue, getRootNode: env?.value.getRootNode, ...cleanProps(localeProps), onValueChange: (details) => { emit?.("valueChange", details); emit?.("update:modelValue", details.value); localeProps.onValueChange?.(details); }, onValueComplete: (details) => { emit?.("valueComplete", details); localeProps.onValueComplete?.(details); }, onValueInvalid: (details) => { emit?.("valueInvalid", details); localeProps.onValueInvalid?.(details); } }; }); const service = useMachine(pinInput.machine, context); return computed(() => pinInput.connect(service, normalizeProps$1)); }; //#endregion export { usePinInput };