tangjinzhou
2 months ago
3 changed files with 16 additions and 7 deletions
@ -1,21 +1,25 @@
|
||||
import type { ComponentInternalInstance, ComputedRef, Ref } from 'vue'; |
||||
import type { ComputedRef, Ref } from 'vue'; |
||||
import { onBeforeUnmount, getCurrentInstance } from 'vue'; |
||||
import { findDOMNode } from '../props-util'; |
||||
import showWaveEffect from './WaveEffect'; |
||||
|
||||
export default function useWave( |
||||
instance: ComponentInternalInstance | null, |
||||
className: Ref<string>, |
||||
wave?: ComputedRef<{ disabled?: boolean }>, |
||||
): VoidFunction { |
||||
const instance = getCurrentInstance(); |
||||
let stopWave: () => void; |
||||
function showWave() { |
||||
const node = findDOMNode(instance); |
||||
|
||||
stopWave?.(); |
||||
if (wave?.value?.disabled || !node) { |
||||
return; |
||||
} |
||||
|
||||
showWaveEffect(node, className.value); |
||||
stopWave = showWaveEffect(node, className.value); |
||||
} |
||||
onBeforeUnmount(() => { |
||||
stopWave?.(); |
||||
}); |
||||
|
||||
return showWave; |
||||
} |
||||
|
Loading…
Reference in new issue