ant-design-vue/components/icon/utils.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

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 {
2019-01-12 03:33:27 +00:00
warning(false, `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) {
2018-11-17 07:57:38 +00:00
switch (type) {
case 'cross':
2019-01-12 03:33:27 +00:00
return 'close';
2018-11-17 07:57:38 +00:00
default:
}
2019-01-12 03:33:27 +00:00
return type;
2018-11-17 07:57:38 +00:00
}