UNPKG

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