UNPKG

@ark-ui/vue

Version:

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

30 lines (27 loc) 1.08 kB
import * as clipboard from '@zag-js/clipboard'; 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 { cleanProps } from '../../utils/clean-props.js'; const useClipboard = (props = {}, emit) => { const id = useId(); const env = useEnvironmentContext(DEFAULT_ENVIRONMENT); const context = computed(() => { const localeProps = toValue(props); return { id, getRootNode: env?.value.getRootNode, value: localeProps.modelValue, onStatusChange: (details) => emit?.("statusChange", details), ...cleanProps(localeProps), onValueChange(details) { emit?.("valueChange", details); emit?.("update:modelValue", details.value); localeProps.onValueChange?.(details); } }; }); const service = useMachine(clipboard.machine, context); return computed(() => clipboard.connect(service, normalizeProps)); }; export { useClipboard };