index.mjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { unref } from 'vue';
  2. import { useTimeout } from '../use-timeout/index.mjs';
  3. import { buildProps } from '../../utils/vue/props/runtime.mjs';
  4. import { isNumber } from '../../utils/types.mjs';
  5. const useDelayedToggleProps = buildProps({
  6. showAfter: {
  7. type: Number,
  8. default: 0
  9. },
  10. hideAfter: {
  11. type: Number,
  12. default: 200
  13. },
  14. autoClose: {
  15. type: Number,
  16. default: 0
  17. }
  18. });
  19. const useDelayedToggle = ({
  20. showAfter,
  21. hideAfter,
  22. autoClose,
  23. open,
  24. close
  25. }) => {
  26. const { registerTimeout } = useTimeout();
  27. const {
  28. registerTimeout: registerTimeoutForAutoClose,
  29. cancelTimeout: cancelTimeoutForAutoClose
  30. } = useTimeout();
  31. const onOpen = (event) => {
  32. registerTimeout(() => {
  33. open(event);
  34. const _autoClose = unref(autoClose);
  35. if (isNumber(_autoClose) && _autoClose > 0) {
  36. registerTimeoutForAutoClose(() => {
  37. close(event);
  38. }, _autoClose);
  39. }
  40. }, unref(showAfter));
  41. };
  42. const onClose = (event) => {
  43. cancelTimeoutForAutoClose();
  44. registerTimeout(() => {
  45. close(event);
  46. }, unref(hideAfter));
  47. };
  48. return {
  49. onOpen,
  50. onClose
  51. };
  52. };
  53. export { useDelayedToggle, useDelayedToggleProps };
  54. //# sourceMappingURL=index.mjs.map