mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 13:39:40 +08:00
25 lines
930 B
TypeScript
25 lines
930 B
TypeScript
import type { ComponentPublicInstance } from 'vue';
|
|
import type { MaybeComputedRef, MaybeRef } from './types';
|
|
import { resolveUnref } from './resolveUnref';
|
|
|
|
export type VueInstance = ComponentPublicInstance;
|
|
export type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>;
|
|
export type MaybeComputedElementRef<T extends MaybeElement = MaybeElement> = MaybeComputedRef<T>;
|
|
export type MaybeElement = HTMLElement | SVGElement | VueInstance | undefined | null;
|
|
|
|
export type UnRefElementReturn<T extends MaybeElement = MaybeElement> = T extends VueInstance
|
|
? Exclude<MaybeElement, VueInstance>
|
|
: T | undefined;
|
|
|
|
/**
|
|
* Get the dom element of a ref of element or Vue component instance
|
|
*
|
|
* @param elRef
|
|
*/
|
|
export function unrefElement<T extends MaybeElement>(
|
|
elRef: MaybeComputedElementRef<T>,
|
|
): UnRefElementReturn<T> {
|
|
const plain = resolveUnref(elRef);
|
|
return (plain as VueInstance)?.$el ?? plain;
|
|
}
|