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
|
|
|
|
|
|
|
/**
|
2024-08-21 14:27:40 +08:00
|
|
|
* Check for element is native ellipsis
|
|
|
|
* ref:
|
|
|
|
* - https://github.com/ant-design/ant-design/issues/50143
|
|
|
|
* - https://github.com/ant-design/ant-design/issues/50414
|
2024-08-09 10:27:25 +08:00
|
|
|
*/
|
2024-08-21 14:27:40 +08:00
|
|
|
export function isEleEllipsis(ele: HTMLElement): boolean {
|
|
|
|
// Create a new div to get the size
|
|
|
|
const childDiv = document.createElement('em');
|
|
|
|
ele.appendChild(childDiv);
|
|
|
|
|
|
|
|
// For test case
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
childDiv.className = 'ant-typography-css-ellipsis-content-measure';
|
|
|
|
}
|
|
|
|
|
2024-08-09 10:27:25 +08:00
|
|
|
const rect = ele.getBoundingClientRect();
|
2024-08-21 14:27:40 +08:00
|
|
|
const childRect = childDiv.getBoundingClientRect();
|
2024-08-09 10:27:25 +08:00
|
|
|
|
2024-08-21 14:27:40 +08:00
|
|
|
// Reset
|
|
|
|
ele.removeChild(childDiv);
|
2024-08-09 10:27:25 +08:00
|
|
|
|
2024-08-21 14:27:40 +08:00
|
|
|
// Range checker
|
2024-08-27 22:08:04 +08:00
|
|
|
return (
|
|
|
|
// Horizontal out of range
|
|
|
|
rect.left > childRect.left ||
|
|
|
|
childRect.right > rect.right ||
|
|
|
|
// Vertical out of range
|
|
|
|
rect.top > childRect.top ||
|
|
|
|
childRect.bottom > rect.bottom
|
|
|
|
);
|
2024-08-09 10:27:25 +08:00
|
|
|
}
|
2024-08-27 22:08:04 +08:00
|
|
|
|
|
|
|
export const isValidText = (val: any): val is string | number =>
|
|
|
|
['string', 'number'].includes(typeof val);
|