forked from folio-org/stripes-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIcon.js
77 lines (66 loc) · 1.78 KB
/
Icon.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import css from './Icon.css';
import icons from './icons';
/* eslint-disable react/prefer-stateless-function */
/* We write this as a class because other components apply and use a ref to it */
class Icon extends React.Component {
static propTypes = {
color: PropTypes.string,
icon: PropTypes.oneOf(Object.keys(icons)),
iconClassName: PropTypes.string,
iconRootClass: PropTypes.string,
id: PropTypes.string,
size: PropTypes.oneOf([
'small',
'medium',
'large',
]),
status: PropTypes.oneOf([
'error',
'warn',
'success',
]),
title: PropTypes.string,
}
static defaultProps = {
size: 'medium',
icon: 'default',
}
render() {
const { icon, color, title, iconClassName, id, size, status, iconRootClass } = this.props;
const getRootClass = classNames(
css.icon,
iconRootClass,
css[size],
// Icon is spinner (this is going to be deprecated later on)
{ [css.iconSpinner]: icon === 'spinner-ellipsis' },
// Icons that contains "left" or "right should flip on dir="rtl"
{ [css.flippable]: icon.match(/(right|left)/) },
);
const getSVGClass = classNames(
'stripes__icon',
iconClassName,
`icon-${icon}`,
css[status]
);
const style = color ? { fill: color } : {};
// Defaults to the default-icon
let IconSVG = icons.default;
if (typeof icons[icon] === 'function') {
IconSVG = icons[icon];
}
return (
<span
className={getRootClass}
tabIndex="-1"
title={title}
id={id}
>
<IconSVG style={style} className={getSVGClass} />
</span>
);
}
}
export default Icon;