@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
54 lines (47 loc) • 1.61 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const timer = require('@zag-js/timer');
const vue$1 = require('@zag-js/vue');
const vue = require('vue');
const useEnvironmentContext = require('../../providers/environment/use-environment-context.cjs');
const cleanProps = require('../../utils/clean-props.cjs');
function _interopNamespaceDefault(e) {
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
if (e) {
for (const k in e) {
if (k !== 'default') {
const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: () => e[k]
});
}
}
}
n.default = e;
return Object.freeze(n);
}
const timer__namespace = /*#__PURE__*/_interopNamespaceDefault(timer);
const useTimer = (props, emit) => {
const id = vue.useId();
const env = useEnvironmentContext.useEnvironmentContext(useEnvironmentContext.DEFAULT_ENVIRONMENT);
const context = vue.computed(() => {
const localProps = vue.toValue(props);
return {
id,
getRootNode: env?.value.getRootNode,
...cleanProps.cleanProps(localProps),
onComplete: () => {
emit?.("complete");
localProps.onComplete?.();
},
onTick: (details) => {
emit?.("tick", details);
localProps.onTick?.(details);
}
};
});
const service = vue$1.useMachine(timer__namespace.machine, context);
return vue.computed(() => timer__namespace.connect(service, vue$1.normalizeProps));
};
exports.useTimer = useTimer;