-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathfontAwesomeIcon.tsx
More file actions
46 lines (40 loc) · 1.89 KB
/
Copy pathfontAwesomeIcon.tsx
File metadata and controls
46 lines (40 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {IconName, IconPrefix} from '@fortawesome/fontawesome-svg-core';
import {FontAwesomeIcon as FontAwesomeIconOriginComponent} from '@fortawesome/react-fontawesome';
import mergeClassNames from 'classnames';
import React, {PureComponent} from 'react';
import {defaultProps} from './iconDefaultProps';
import {IconProps} from './icon';
import mapper from './mapper';
class FontAwesomeIcon extends PureComponent<IconProps> {
public static readonly defaultProps = defaultProps;
public render(): JSX.Element | null {
const {padded, theme, label, icon, className, color, ...rest} = this.props;
const iconClassName = icon;
const classNames = mergeClassNames(
theme!.icon,
iconClassName,
className,
{
[theme!['icon--paddedLeft']]: padded === 'left',
[theme!['icon--paddedRight']]: padded === 'right',
[theme!['icon--color-warn']]: color === 'warn',
[theme!['icon--color-error']]: color === 'error',
[theme!['icon--color-primaryBlue']]: color === 'primaryBlue',
[theme!['icon--color-contrastDark']]: color === 'contrastDark'
}
);
return <FontAwesomeIconOriginComponent icon={icon ? this.getIconProp(icon) as any : 'question'} aria-label={label} className={classNames} {...rest} />;
}
private readonly getIconProp = (icon: string): any => {
const mappedIcon = mapper(icon);
const iconArray = mappedIcon.split(' ');
if (iconArray.length > 1) {
const prefix = iconArray[0];
const processedIcon = iconArray[1].startsWith('fa-') ? iconArray[1].substr(3) : iconArray[1];
return [prefix as IconPrefix, processedIcon as IconName];
}
const prefix: IconPrefix = 'fas';
return [prefix, mappedIcon as IconName];
}
}
export default FontAwesomeIcon;