@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
23 lines (20 loc) • 692 B
JavaScript
import * as toggle from '@zag-js/toggle';
import { useMachine, normalizeProps } from '@zag-js/vue';
import { computed, toValue } from 'vue';
import { cleanProps } from '../../utils/clean-props.js';
function useToggle(props, emit) {
const machineProps = computed(() => {
const localProps = toValue(props);
return {
...cleanProps(localProps),
onPressedChange: (value) => {
emit?.("pressedChange", value);
emit?.("update:pressed", value);
localProps.onPressedChange?.(value);
}
};
});
const service = useMachine(toggle.machine, machineProps);
return computed(() => toggle.connect(service, normalizeProps));
}
export { useToggle };