2022-01-04 09:15:15 +08:00
|
|
|
import { unref } from 'vue'
|
2022-02-11 11:03:15 +08:00
|
|
|
import { buildProps } from '@element-plus/utils'
|
2022-01-04 09:15:15 +08:00
|
|
|
import { useTimeout } from '../use-timeout'
|
|
|
|
|
2022-03-25 15:35:56 +08:00
|
|
|
import type { ExtractPropTypes, ToRefs } from 'vue'
|
2022-01-04 09:15:15 +08:00
|
|
|
|
|
|
|
export const useDelayedToggleProps = buildProps({
|
|
|
|
showAfter: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
|
|
|
},
|
|
|
|
hideAfter: {
|
|
|
|
type: Number,
|
|
|
|
default: 200,
|
|
|
|
},
|
2022-02-11 11:40:50 +08:00
|
|
|
} as const)
|
2022-01-04 09:15:15 +08:00
|
|
|
|
|
|
|
export type UseDelayedToggleProps = {
|
2022-05-10 21:51:17 +08:00
|
|
|
open: (event?: Event) => void
|
|
|
|
close: (event?: Event) => void
|
2022-01-04 09:15:15 +08:00
|
|
|
} & ToRefs<ExtractPropTypes<typeof useDelayedToggleProps>>
|
|
|
|
|
|
|
|
export const useDelayedToggle = ({
|
|
|
|
showAfter,
|
|
|
|
hideAfter,
|
|
|
|
open,
|
|
|
|
close,
|
|
|
|
}: UseDelayedToggleProps) => {
|
|
|
|
const { registerTimeout } = useTimeout()
|
|
|
|
|
2022-05-10 21:51:17 +08:00
|
|
|
const onOpen = (event?: Event) => {
|
2022-01-04 09:15:15 +08:00
|
|
|
registerTimeout(() => {
|
2022-05-10 21:51:17 +08:00
|
|
|
open(event)
|
2022-01-04 09:15:15 +08:00
|
|
|
}, unref(showAfter))
|
|
|
|
}
|
|
|
|
|
2022-05-10 21:51:17 +08:00
|
|
|
const onClose = (event?: Event) => {
|
2022-01-04 09:15:15 +08:00
|
|
|
registerTimeout(() => {
|
2022-05-10 21:51:17 +08:00
|
|
|
close(event)
|
2022-01-04 09:15:15 +08:00
|
|
|
}, unref(hideAfter))
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
onOpen,
|
|
|
|
onClose,
|
|
|
|
}
|
|
|
|
}
|