element-plus/packages/utils/vue/refs.ts
JeremyWuuuuu 9919e0a867
feat(components): [tooltip-v2] add new component (#6838)
* feat(components): [tooltip-v2] add new component

- Init component

* Implement trigger and only child

* Fix typing issue
2022-03-26 13:33:24 +08:00

22 lines
545 B
TypeScript

import { isFunction } from '@element-plus/utils'
import type { ComponentPublicInstance, Ref } from 'vue'
export type RefSetter = (
el: Element | ComponentPublicInstance | undefined
) => void
export const composeRefs = (
...refs: (Ref<HTMLElement | undefined> | RefSetter)[]
) => {
return (el: Element | ComponentPublicInstance | null) => {
refs.forEach((ref) => {
if (isFunction(ref)) {
ref(el as Element | ComponentPublicInstance)
} else {
ref.value = el as HTMLElement | undefined
}
})
}
}