2019-01-12 03:33:27 +00:00
|
|
|
import warning from '../_util/warning';
|
2018-11-17 07:57:38 +00:00
|
|
|
|
|
|
|
// These props make sure that the SVG behaviours like general text.
|
|
|
|
// Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4
|
|
|
|
export const svgBaseProps = {
|
|
|
|
width: '1em',
|
|
|
|
height: '1em',
|
|
|
|
fill: 'currentColor',
|
|
|
|
'aria-hidden': 'true',
|
|
|
|
focusable: 'false',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-11-17 07:57:38 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const fillTester = /-fill$/;
|
|
|
|
const outlineTester = /-o$/;
|
|
|
|
const twoToneTester = /-twotone$/;
|
2018-11-17 07:57:38 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export function getThemeFromTypeName(type) {
|
|
|
|
let result = null;
|
2018-11-17 07:57:38 +00:00
|
|
|
if (fillTester.test(type)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
result = 'filled';
|
2018-11-17 07:57:38 +00:00
|
|
|
} else if (outlineTester.test(type)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
result = 'outlined';
|
2018-11-17 07:57:38 +00:00
|
|
|
} else if (twoToneTester.test(type)) {
|
2019-01-12 03:33:27 +00:00
|
|
|
result = 'twoTone';
|
2018-11-17 07:57:38 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return result;
|
2018-11-17 07:57:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export function removeTypeTheme(type) {
|
2018-11-17 07:57:38 +00:00
|
|
|
return type
|
|
|
|
.replace(fillTester, '')
|
|
|
|
.replace(outlineTester, '')
|
2019-01-12 03:33:27 +00:00
|
|
|
.replace(twoToneTester, '');
|
2018-11-17 07:57:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export function withThemeSuffix(type, theme) {
|
|
|
|
let result = type;
|
2018-11-17 07:57:38 +00:00
|
|
|
if (theme === 'filled') {
|
2019-01-12 03:33:27 +00:00
|
|
|
result += '-fill';
|
2018-11-17 07:57:38 +00:00
|
|
|
} else if (theme === 'outlined') {
|
2019-01-12 03:33:27 +00:00
|
|
|
result += '-o';
|
2018-11-17 07:57:38 +00:00
|
|
|
} else if (theme === 'twoTone') {
|
2019-01-12 03:33:27 +00:00
|
|
|
result += '-twotone';
|
2018-11-17 07:57:38 +00:00
|
|
|
} else {
|
2020-03-07 11:45:13 +00:00
|
|
|
warning(false, 'Icon', `This icon '${type}' has unknown theme '${theme}'`);
|
2018-11-17 07:57:38 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return result;
|
2018-11-17 07:57:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// For alias or compatibility
|
2019-01-12 03:33:27 +00:00
|
|
|
export function alias(type) {
|
2020-03-07 11:45:13 +00:00
|
|
|
let newType = type;
|
2018-11-17 07:57:38 +00:00
|
|
|
switch (type) {
|
|
|
|
case 'cross':
|
2020-03-07 11:45:13 +00:00
|
|
|
newType = 'close';
|
|
|
|
break;
|
|
|
|
// https://github.com/ant-design/ant-design/issues/13007
|
|
|
|
case 'interation':
|
|
|
|
newType = 'interaction';
|
|
|
|
break;
|
|
|
|
// https://github.com/ant-design/ant-design/issues/16810
|
|
|
|
case 'canlendar':
|
|
|
|
newType = 'calendar';
|
|
|
|
break;
|
|
|
|
// https://github.com/ant-design/ant-design/issues/17448
|
|
|
|
case 'colum-height':
|
|
|
|
newType = 'column-height';
|
|
|
|
break;
|
2018-11-17 07:57:38 +00:00
|
|
|
default:
|
|
|
|
}
|
2020-03-07 11:45:13 +00:00
|
|
|
warning(
|
|
|
|
newType === type,
|
|
|
|
'Icon',
|
|
|
|
`Icon '${type}' was a typo and is now deprecated, please use '${newType}' instead.`,
|
|
|
|
);
|
|
|
|
return newType;
|
2018-11-17 07:57:38 +00:00
|
|
|
}
|