mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-16 02:11:48 +08:00
dd19cae2bc
* refactor(components): popper composables - Refactor popper composables * updates * updates for tooltip * Updates for popper. TODO: fix controlled tooltip animation * Fix controlled mode popper animation issue * Add new feature for customizing tooltip theme * Fix popover and popconfirm error * - Add Collection component for wrapping a collection of component - Add FocusTrap component for trap focus for popups - Add RovingFocus component for roving focus component type - Adjust dropdown component based on these newly added components - Add popper-trigger component for placing the trigger - TODO: Finish current dropdown component, and all component's tests plus documents * Refactor popper * Complete organizing popper * Almost finish dropdown * Update popper tests * update only-child test * Finish focus trap component test * Finish tooltip content test * Finish tooltip trigger tests * Finish tooltip tests * finish tests for Collection and RovingFocusGroup * Fix test cases for timeselect & select & popover * Fix popover, popconfirm, menu bug and test cases * Fix select-v2 test error caused by updating popper * Fix date-picker test issue for updating popper * fix test cases * Fix eslint * Rebase dev & fix tests * Remove unused code
61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
import { nextTick, watch, unref } from 'vue'
|
|
|
|
import type { Ref } from 'vue'
|
|
|
|
export type UseDelayedRenderProps = {
|
|
indicator: Ref<boolean>
|
|
intermediateIndicator: Ref<boolean>
|
|
shouldSetIntermediate?: (step: 'show' | 'hide') => boolean
|
|
beforeShow?: () => void
|
|
beforeHide?: () => void
|
|
afterShow?: () => void
|
|
afterHide?: () => void
|
|
}
|
|
|
|
export const useDelayedRender = ({
|
|
indicator,
|
|
intermediateIndicator,
|
|
shouldSetIntermediate = () => true,
|
|
beforeShow,
|
|
afterShow,
|
|
afterHide,
|
|
beforeHide,
|
|
}: UseDelayedRenderProps) => {
|
|
watch(
|
|
() => unref(indicator),
|
|
(val) => {
|
|
if (val) {
|
|
beforeShow?.()
|
|
nextTick(() => {
|
|
if (!unref(indicator)) return
|
|
if (shouldSetIntermediate('show')) {
|
|
intermediateIndicator.value = true
|
|
}
|
|
})
|
|
} else {
|
|
beforeHide?.()
|
|
nextTick(() => {
|
|
if (unref(indicator)) return
|
|
|
|
if (shouldSetIntermediate('hide')) {
|
|
intermediateIndicator.value = false
|
|
}
|
|
})
|
|
}
|
|
}
|
|
)
|
|
|
|
// because we don't always set the value ourselves, so that we
|
|
// simply watch the value's state, then invoke the corresponding hook.
|
|
watch(
|
|
() => intermediateIndicator.value,
|
|
(val) => {
|
|
if (val) {
|
|
afterShow?.()
|
|
} else {
|
|
afterHide?.()
|
|
}
|
|
}
|
|
)
|
|
}
|