utils.js 2.3 KB

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