mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-16 02:11:48 +08:00
48 lines
874 B
TypeScript
48 lines
874 B
TypeScript
import { unref } from 'vue'
|
|
import { buildProps } from '@element-plus/utils'
|
|
import { useTimeout } from '../use-timeout'
|
|
|
|
import type { ToRefs, ExtractPropTypes } from 'vue'
|
|
|
|
export const useDelayedToggleProps = buildProps({
|
|
showAfter: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
hideAfter: {
|
|
type: Number,
|
|
default: 200,
|
|
},
|
|
} as const)
|
|
|
|
export type UseDelayedToggleProps = {
|
|
open: () => void
|
|
close: () => void
|
|
} & ToRefs<ExtractPropTypes<typeof useDelayedToggleProps>>
|
|
|
|
export const useDelayedToggle = ({
|
|
showAfter,
|
|
hideAfter,
|
|
open,
|
|
close,
|
|
}: UseDelayedToggleProps) => {
|
|
const { registerTimeout } = useTimeout()
|
|
|
|
const onOpen = () => {
|
|
registerTimeout(() => {
|
|
open()
|
|
}, unref(showAfter))
|
|
}
|
|
|
|
const onClose = () => {
|
|
registerTimeout(() => {
|
|
close()
|
|
}, unref(hideAfter))
|
|
}
|
|
|
|
return {
|
|
onOpen,
|
|
onClose,
|
|
}
|
|
}
|