2018-08-30 22:53:24 +08:00
|
|
|
import { ThemeType } from './index';
|
|
|
|
import warning from '../_util/warning';
|
|
|
|
|
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 = {
|
|
|
|
width: '1em',
|
|
|
|
height: '1em',
|
|
|
|
fill: 'currentColor',
|
|
|
|
['aria-hidden']: 'true',
|
|
|
|
};
|
2018-08-30 22:53:24 +08:00
|
|
|
|
|
|
|
const fillTester = /-fill$/;
|
|
|
|
const outlineTester = /-o$/;
|
|
|
|
const twoToneTester = /-twotone$/;
|
|
|
|
|
|
|
|
export function getThemeFromTypeName(type: string): ThemeType | null {
|
|
|
|
let result: ThemeType | null = null;
|
|
|
|
if (fillTester.test(type)) {
|
2018-08-31 10:02:55 +08:00
|
|
|
result = 'filled';
|
2018-08-30 22:53:24 +08:00
|
|
|
} else if (outlineTester.test(type)) {
|
2018-08-31 10:02:55 +08:00
|
|
|
result = 'outlined';
|
2018-08-30 22:53:24 +08:00
|
|
|
} else if (twoToneTester.test(type)) {
|
2018-08-31 11:14:51 +08:00
|
|
|
result = 'twoTone';
|
2018-08-30 22:53:24 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-02 19:48:57 +08:00
|
|
|
export function removeTypeTheme(type: string) {
|
|
|
|
return type.replace(fillTester, '').replace(outlineTester, '').replace(twoToneTester, '');
|
|
|
|
}
|
|
|
|
|
2018-08-30 22:53:24 +08:00
|
|
|
export function withThemeSuffix(type: string, theme: ThemeType) {
|
|
|
|
let result = type;
|
2018-09-02 19:48:57 +08:00
|
|
|
if (theme === 'filled') {
|
|
|
|
result += '-fill';
|
|
|
|
} else if (theme === 'outlined') {
|
|
|
|
result += '-o';
|
|
|
|
} else if (theme === 'twoTone') {
|
|
|
|
result += '-twotone';
|
|
|
|
} else {
|
|
|
|
warning(false, `This icon '${type}' has unknown theme '${theme}'`);
|
2018-08-30 22:53:24 +08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|