-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
StepLabel.js
162 lines (145 loc) · 3.32 KB
/
StepLabel.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import React from 'react';
import PropTypes from 'prop-types';
import CheckCircle from '../svg-icons/action/check-circle';
import SvgIcon from '../SvgIcon';
const getStyles = ({active, completed, disabled}, {muiTheme, stepper}) => {
const {
textColor,
disabledTextColor,
iconColor,
inactiveIconColor,
} = muiTheme.stepper;
const {baseTheme} = muiTheme;
const {orientation} = stepper;
const styles = {
root: {
height: orientation === 'horizontal' ? 72 : 64,
color: textColor,
display: 'flex',
alignItems: 'center',
fontFamily: baseTheme.fontFamily,
fontSize: 14,
paddingLeft: 14,
paddingRight: 14,
},
icon: {
color: iconColor,
display: 'block',
fontSize: 24,
width: 24,
height: 24,
},
iconContainer: {
paddingRight: 8,
},
};
if (active) {
styles.root.fontWeight = 500;
}
if (!completed && !active) {
styles.icon.color = inactiveIconColor;
}
if (disabled) {
styles.icon.color = inactiveIconColor;
styles.root.color = disabledTextColor;
styles.root.cursor = 'default';
}
return styles;
};
const renderIcon = (completed, icon, styles) => {
const iconType = typeof icon;
if (iconType === 'number' || iconType === 'string') {
if (completed) {
return (
<CheckCircle
color={styles.icon.color}
style={styles.icon}
/>
);
}
return (
<SvgIcon color={styles.icon.color} style={styles.icon}>
<circle cx="12" cy="12" r="10" />
<text
x="12"
y="16"
textAnchor="middle"
fontSize="12"
fill="#fff"
>
{icon}
</text>
</SvgIcon>
);
}
return icon;
};
const StepLabel = (props, context) => {
const {
active, // eslint-disable-line no-unused-vars
children,
completed,
icon: userIcon,
iconContainerStyle,
last, // eslint-disable-line no-unused-vars
style,
...other
} = props;
const {prepareStyles} = context.muiTheme;
const styles = getStyles(props, context);
const icon = renderIcon(completed, userIcon, styles);
return (
<span style={prepareStyles(Object.assign(styles.root, style))} {...other}>
{icon && (
<span style={prepareStyles(Object.assign(styles.iconContainer, iconContainerStyle))}>
{icon}
</span>
)}
{children}
</span>
);
};
StepLabel.muiName = 'StepLabel';
StepLabel.propTypes = {
/**
* Sets active styling. Overrides disabled coloring.
*/
active: PropTypes.bool,
/**
* The label text node
*/
children: PropTypes.node,
/**
* Sets completed styling. Overrides disabled coloring.
*/
completed: PropTypes.bool,
/**
* Sets disabled styling.
*/
disabled: PropTypes.bool,
/**
* The icon displayed by the step label.
*/
icon: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.number,
]),
/**
* Override the inline-styles of the icon container element.
*/
iconContainerStyle: PropTypes.object,
/**
* @ignore
*/
last: PropTypes.bool,
/**
* Override the inline-style of the root element.
*/
style: PropTypes.object,
};
StepLabel.contextTypes = {
muiTheme: PropTypes.object.isRequired,
stepper: PropTypes.object,
};
export default StepLabel;