2022-05-10 15:43:29 +08:00
|
|
|
import warning from '../../../../components/_util/warning';
|
2018-08-30 22:53:24 +08:00
|
|
|
|
2018-08-15 17:21:02 +08: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 = {
|
2018-12-07 16:17:45 +08:00
|
|
|
width: '1em',
|
|
|
|
height: '1em',
|
|
|
|
fill: 'currentColor',
|
2019-08-13 14:07:17 +08:00
|
|
|
'aria-hidden': true,
|
2018-12-07 16:17:45 +08:00
|
|
|
focusable: 'false',
|
2018-08-15 17:21:02 +08:00
|
|
|
};
|
2018-08-30 22:53:24 +08:00
|
|
|
|
|
|
|
const fillTester = /-fill$/;
|
|
|
|
const outlineTester = /-o$/;
|
|
|
|
const twoToneTester = /-twotone$/;
|
|
|
|
|
2022-08-05 13:45:46 +08:00
|
|
|
export function getThemeFromTypeName(type: string) {
|
|
|
|
let result: string | null = null;
|
2018-08-30 22:53:24 +08:00
|
|
|
if (fillTester.test(type)) {
|
2018-12-07 16:17:45 +08:00
|
|
|
result = 'filled';
|
2018-08-30 22:53:24 +08:00
|
|
|
} else if (outlineTester.test(type)) {
|
2018-12-07 16:17:45 +08:00
|
|
|
result = 'outlined';
|
2018-08-30 22:53:24 +08:00
|
|
|
} else if (twoToneTester.test(type)) {
|
2018-12-07 16:17:45 +08:00
|
|
|
result = 'twoTone';
|
2018-08-30 22:53:24 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-08-05 13:45:46 +08:00
|
|
|
export function removeTypeTheme(type: string): string {
|
2020-05-14 15:57:04 +08:00
|
|
|
return type.replace(fillTester, '').replace(outlineTester, '').replace(twoToneTester, '');
|
2018-09-02 19:48:57 +08:00
|
|
|
}
|
|
|
|
|
2022-08-05 13:45:46 +08:00
|
|
|
export function withThemeSuffix(type: string, theme: string): string {
|
|
|
|
let result: string = type;
|
2018-12-07 16:17:45 +08:00
|
|
|
if (theme === 'filled') {
|
|
|
|
result += '-fill';
|
|
|
|
} else if (theme === 'outlined') {
|
|
|
|
result += '-o';
|
|
|
|
} else if (theme === 'twoTone') {
|
|
|
|
result += '-twotone';
|
2018-09-02 19:48:57 +08:00
|
|
|
} else {
|
2019-02-27 15:32:29 +08:00
|
|
|
warning(false, 'Icon', `This icon '${type}' has unknown theme '${theme}'`);
|
2018-08-30 22:53:24 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|