You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

import { unref } from 'vue';
import '../../utils/index.mjs';
import { useTimeout } from '../use-timeout/index.mjs';
import { buildProps } from '../../utils/vue/props/runtime.mjs';
import { isNumber } from '../../utils/types.mjs';
const useDelayedToggleProps = buildProps({
showAfter: {
type: Number,
default: 0
},
hideAfter: {
type: Number,
default: 200
},
autoClose: {
type: Number,
default: 0
}
});
const useDelayedToggle = ({
showAfter,
hideAfter,
autoClose,
open,
close
}) => {
const { registerTimeout } = useTimeout();
const {
registerTimeout: registerTimeoutForAutoClose,
cancelTimeout: cancelTimeoutForAutoClose
} = useTimeout();
const onOpen = (event) => {
registerTimeout(() => {
open(event);
const _autoClose = unref(autoClose);
if (isNumber(_autoClose) && _autoClose > 0) {
registerTimeoutForAutoClose(() => {
close(event);
}, _autoClose);
}
}, unref(showAfter));
};
const onClose = (event) => {
cancelTimeoutForAutoClose();
registerTimeout(() => {
close(event);
}, unref(hideAfter));
};
return {
onOpen,
onClose
};
};
export { useDelayedToggle, useDelayedToggleProps };
//# sourceMappingURL=index.mjs.map