2024-06-22 21:59:12 +08:00
|
|
|
export function toList<T>(val: T | T[]): T[] {
|
2024-02-27 16:56:24 +08:00
|
|
|
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);
|
|
|
|
}
|
2024-08-09 10:27:25 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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];
|
|
|
|
}
|