-
Notifications
You must be signed in to change notification settings - Fork 0
/
Statistic.jsx
114 lines (109 loc) · 2.7 KB
/
Statistic.jsx
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { FontAwesomeIcon as Icon } from '@fortawesome/react-fontawesome';
import setTheme from '../../utilities/setTheme';
const Statistic = ({
className,
horizontal,
icon,
iconColor,
value,
label,
size,
theme,
themeVariant,
topLabel,
...others
}) => {
// eslint-disable-next-line no-restricted-globals
const isNumber = !isNaN(
value.toString().replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, ''),
);
return (
<div
className={classnames('atomikui-statistic', className, {
'atomikui-statistic--top-label': topLabel && !horizontal,
'atomikui-statistic--horizontal': horizontal,
[setTheme('atomikui-statistic', theme, themeVariant)]: theme,
})}
{...others}
>
<div className="atomikui-statistic__hd">
{icon && (
<span className="atomikui-statistic__icon">
<Icon icon={icon} size="3x" color={iconColor} />
</span>
)}
<span
className={classnames('atomikui-statistic__value', {
'atomikui-statistic__value--number': isNumber,
[`atomikui-statistic__value--${size}`]: size,
})}
>
{value}
</span>
</div>
<div className="atomikui-statistic__ft">{label}</div>
</div>
);
};
Statistic.propTypes = {
/** Adds custom component CSS classes */
className: PropTypes.string,
/** Sets layout as horizontal */
horizontal: PropTypes.bool,
/** Icon to be displayed next to statistic */
// eslint-disable-next-line react/forbid-prop-types
icon: PropTypes.object,
/** Color of the icon */
iconColor: PropTypes.string,
/** Label for statistic value */
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/** Postions label on top */
topLabel: PropTypes.bool,
/** Sets the size of the value text */
size: PropTypes.oneOf(['sm', 'md', 'lg']),
/** Specifies the color variation. */
theme: PropTypes.oneOf([
'red',
'pink',
'purple',
'deep-purple',
'indigo',
'blue',
'sky-blue',
'cyan',
'teal',
'green',
'light-green',
'lime',
'yellow',
'light-orange',
'orange',
'deep-orange',
'amber',
'brown',
'gray',
'blue-gray',
'black',
'white',
]),
/** The theme color variant */
themeVariant: PropTypes.oneOf(['light']),
/** Statistic value */
value: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
};
Statistic.defaultProps = {
className: '',
horizontal: false,
icon: null,
iconColor: '#222',
label: '',
size: null,
theme: null,
themeVariant: null,
topLabel: false,
value: '',
};
export default Statistic;