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.

1 line
3.0 KiB

{"version":3,"file":"index.js","sources":["../../../../../packages/hooks/use-delayed-toggle/index.ts"],"sourcesContent":["import { unref } from 'vue'\nimport { buildProps, isNumber } from '@element-plus/utils'\nimport { useTimeout } from '../use-timeout'\n\nimport type { ExtractPropTypes, ToRefs } from 'vue'\n\nexport const useDelayedToggleProps = buildProps({\n /**\n * @description delay of appearance, in millisecond\n */\n showAfter: {\n type: Number,\n default: 0,\n },\n /**\n * @description delay of disappear, in millisecond\n */\n hideAfter: {\n type: Number,\n default: 200,\n },\n /**\n * @description disappear automatically, in millisecond\n */\n autoClose: {\n type: Number,\n default: 0,\n },\n} as const)\n\nexport type UseDelayedToggleProps = {\n open: (event?: Event) => void\n close: (event?: Event) => void\n} & ToRefs<ExtractPropTypes<typeof useDelayedToggleProps>>\n\nexport const useDelayedToggle = ({\n showAfter,\n hideAfter,\n autoClose,\n open,\n close,\n}: UseDelayedToggleProps) => {\n const { registerTimeout } = useTimeout()\n const {\n registerTimeout: registerTimeoutForAutoClose,\n cancelTimeout: cancelTimeoutForAutoClose,\n } = useTimeout()\n\n const onOpen = (event?: Event) => {\n registerTimeout(() => {\n open(event)\n\n const _autoClose = unref(autoClose)\n if (isNumber(_autoClose) && _autoClose > 0) {\n registerTimeoutForAutoClose(() => {\n close(event)\n }, _autoClose)\n }\n }, unref(showAfter))\n }\n\n const onClose = (event?: Event) => {\n cancelTimeoutForAutoClose()\n\n registerTimeout(() => {\n close(event)\n }, unref(hideAfter))\n }\n\n return {\n onOpen,\n onClose,\n }\n}\n"],"names":["buildProps","useTimeout","unref","isNumber"],"mappings":";;;;;;;;;;AAGY,MAAC,qBAAqB,GAAGA,kBAAU,CAAC;AAChD,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EAAE,MAAM;AAChB,IAAI,OAAO,EAAE,CAAC;AACd,GAAG;AACH,EAAE,SAAS,EAAE;AACb,IAAI,IAAI,EA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