You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

6 years ago
import { ThemeType } from './index';
import warning from '../_util/warning';
6 years ago
// 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 = {
6 years ago
width: '1em',
height: '1em',
fill: 'currentColor',
['aria-hidden']: 'true',
focusable: 'false',
6 years ago
};
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)) {
6 years ago
result = 'filled';
} else if (outlineTester.test(type)) {
6 years ago
result = 'outlined';
} else if (twoToneTester.test(type)) {
6 years ago
result = 'twoTone';
}
return result;
}
export function removeTypeTheme(type: string) {
return type
6 years ago
.replace(fillTester, '')
.replace(outlineTester, '')
.replace(twoToneTester, '');
}
export function withThemeSuffix(type: string, theme: ThemeType) {
let result = type;
6 years ago
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}'`);
}
return result;
}
// For alias or compatibility
export function alias(type: string) {
switch (type) {
case 'cross':
return 'close';
default:
}
return type;
}