element-plus/packages/hooks/use-events/index.ts
jeremywu d0b37cdf5f
Feat/implementing trigger for popper (#214)
* feat/implementing-trigger-for-popper
- Implementing trigger for popper
- Refactors against click-outside

* feat(popper): implemented trigger for popper
2020-08-28 10:47:02 +08:00

25 lines
484 B
TypeScript

import { watch } from 'vue'
import { on, off } from '@element-plus/utils/dom'
import type { Ref } from 'vue'
export type Event = {
name: string
handler: (...args: any[]) => any
}
export default (el: Ref<HTMLElement>, events: Event[]) => {
watch(el, val => {
if (val) {
events.map(({ name, handler }) => {
on(el.value, name, handler)
})
} else {
events.map(({ name, handler }) => {
off(el.value, name, handler)
})
}
})
}