ant-design/components/typography/Base/util.ts
二货爱吃白萝卜 09264eb1d1
fix: Typography ellipsis (#50315)
* fix: get P

* test: add test case
2024-08-09 10:27:25 +08:00

33 lines
915 B
TypeScript

export function toList<T>(val: T | T[]): T[] {
if (val === false) {
return [false, false] as T[];
}
return Array.isArray(val) ? val : [val];
}
export function getNode(dom: React.ReactNode, defaultNode: React.ReactNode, needDom?: boolean) {
if (dom === true || dom === undefined) {
return defaultNode;
}
return dom || (needDom && defaultNode);
}
/**
* Get React of element with precision.
* ref: https://github.com/ant-design/ant-design/issues/50143
*/
export function getEleSize(ele: HTMLElement): [width: number, height: number] {
const rect = ele.getBoundingClientRect();
const { offsetWidth, offsetHeight } = ele;
let returnWidth = offsetWidth;
let returnHeight = offsetHeight;
if (Math.abs(offsetWidth - rect.width) < 1 && Math.abs(offsetHeight - rect.height) < 1) {
returnWidth = rect.width;
returnHeight = rect.height;
}
return [returnWidth, returnHeight];
}