util.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. export function toList(val) {
  2. if (val === false) {
  3. return [false, false];
  4. }
  5. return Array.isArray(val) ? val : [val];
  6. }
  7. export function getNode(dom, defaultNode, needDom) {
  8. if (dom === true || dom === undefined) {
  9. return defaultNode;
  10. }
  11. return dom || needDom && defaultNode;
  12. }
  13. /**
  14. * Check for element is native ellipsis
  15. * ref:
  16. * - https://github.com/ant-design/ant-design/issues/50143
  17. * - https://github.com/ant-design/ant-design/issues/50414
  18. */
  19. export function isEleEllipsis(ele) {
  20. // Create a new div to get the size
  21. const childDiv = document.createElement('em');
  22. ele.appendChild(childDiv);
  23. // For test case
  24. if (process.env.NODE_ENV !== 'production') {
  25. childDiv.className = 'ant-typography-css-ellipsis-content-measure';
  26. }
  27. const rect = ele.getBoundingClientRect();
  28. const childRect = childDiv.getBoundingClientRect();
  29. // Reset
  30. ele.removeChild(childDiv);
  31. // Range checker
  32. return (
  33. // Horizontal out of range
  34. rect.left > childRect.left || childRect.right > rect.right ||
  35. // Vertical out of range
  36. rect.top > childRect.top || childRect.bottom > rect.bottom
  37. );
  38. }
  39. export const isValidText = val => ['string', 'number'].includes(typeof val);