index.js 1.4 KB

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