utils.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import warning from '../_util/warning';
  2. // These props make sure that the SVG behaviours like general text.
  3. // Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4
  4. export var svgBaseProps = {
  5. width: '1em',
  6. height: '1em',
  7. fill: 'currentColor',
  8. 'aria-hidden': 'true',
  9. focusable: 'false'
  10. };
  11. var fillTester = /-fill$/;
  12. var outlineTester = /-o$/;
  13. var twoToneTester = /-twotone$/;
  14. export function getThemeFromTypeName(type) {
  15. var result = null;
  16. if (fillTester.test(type)) {
  17. result = 'filled';
  18. } else if (outlineTester.test(type)) {
  19. result = 'outlined';
  20. } else if (twoToneTester.test(type)) {
  21. result = 'twoTone';
  22. }
  23. return result;
  24. }
  25. export function removeTypeTheme(type) {
  26. return type.replace(fillTester, '').replace(outlineTester, '').replace(twoToneTester, '');
  27. }
  28. export function withThemeSuffix(type, theme) {
  29. var result = type;
  30. if (theme === 'filled') {
  31. result += '-fill';
  32. } else if (theme === 'outlined') {
  33. result += '-o';
  34. } else if (theme === 'twoTone') {
  35. result += '-twotone';
  36. } else {
  37. warning(false, 'Icon', 'This icon \'' + type + '\' has unknown theme \'' + theme + '\'');
  38. }
  39. return result;
  40. }
  41. // For alias or compatibility
  42. export function alias(type) {
  43. var newType = type;
  44. switch (type) {
  45. case 'cross':
  46. newType = 'close';
  47. break;
  48. // https://github.com/ant-design/ant-design/issues/13007
  49. case 'interation':
  50. newType = 'interaction';
  51. break;
  52. // https://github.com/ant-design/ant-design/issues/16810
  53. case 'canlendar':
  54. newType = 'calendar';
  55. break;
  56. // https://github.com/ant-design/ant-design/issues/17448
  57. case 'colum-height':
  58. newType = 'column-height';
  59. break;
  60. default:
  61. }
  62. warning(newType === type, 'Icon', 'Icon \'' + type + '\' was a typo and is now deprecated, please use \'' + newType + '\' instead.');
  63. return newType;
  64. }