-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtz-wizard-stepper.html
313 lines (275 loc) · 10.4 KB
/
mtz-wizard-stepper.html
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../iron-icons/editor-icons.html">
<link rel="import" href="../paper-ripple/paper-ripple.html">
<link rel="import" href="mtz-wizard-stepper-behavior.html">
<!--
`mtz-wizard-stepper`
A basic implementation of the `mtz.WizardStepperBehavior` for navigating an `mtz-wizard` element.
Custom property | Description | Default
----------------|-------------|----------
`--mtz-wizard-stepper` | Mixin applied to the host | `{}`
`--mtz-wizard-stepper__step-wrapper` | Mixin applied to the step wrapper | `{}`
`--mtz-wizard-stepper__step-line` | Mixin applied to the step line | `{}`
`--mtz-wizard-stepper__step-line--color` | Step line color | Grey 400
`--mtz-wizard-stepper__first-step-badge` | Mixin applied to the first step badge | `{}`
`--mtz-wizard-stepper__last-step-label` | Mixin applied to the last step label | `{}`
`--mtz-wizard-stepper__step` | Mixin applied to the step | `{}`
`--mtz-wizard-stepper__step-hover` | Mixin applied to the step during hover | `{}`
`--mtz-wizard-stepper__step-hover--background-color` | step hover background color | 6% Black
`--mtz-wizard-stepper__step-disabled` | Mixin applied to disabled steps | `{}`
`--mtz-wizard-stepper__active-badge` | Mixin applied to the active & completed badges | `{}`
`--mtz-wizard-stepper__valid-icons` | Mixin applied to the valid icons | `{}`
`--mtz-wizard-stepper__badge-wrapper` | Mixin applied to the badge wrapper | `{}`
`--mtz-wizard-stepper__badge-sizer` | Mixin applied to the badge and badge-wrapper | `{}`
`--mtz-wizard-stepper__badge` | Mixin applied to the badge | `{}`
`--mtz-wizard-stepper__badge--background-color` | Badge background color | 38% Black
`--mtz-wizard-stepper__badge-positioning` | Mixin applied to the badge icon and counter | `{}`
`--mtz-wizard-stepper__badge-counter` | Mixin applied to the badge counter | `{}`
`--mtz-wizard-stepper__invalid-badge` | Mixin applied to invalid badges | `{}`
`--mtz-wizard-stepper__label-wrapper` | Mixin applied to the label-wrapper | `{}`
`--mtz-wizard-stepper__label` | Mixin applied to the label | `{}`
`--mtz-wizard-stepper__label--color` | Label color | 38% Black
`--mtz-wizard-stepper__label-overflow` | Mixin applied to the label text overflow | `{}`
`--mtz-wizard-stepper__optional-label` | Mixin applied to the optional label | `{}`
`--mtz-wizard-stepper__optional-label--color` | Optional label color | 54% Black
`--mtz-wizard-stepper__active-label` | Mixin applied to the active label | `{}`
`--mtz-wizard-stepper__active-label--color` | Active label color | 87% Black
`--mtz-wizard-stepper__invalid-step-content` | Mixin applied to the invalid step's content | `{}`
@demo demo/index.html
-->
<dom-module id="mtz-wizard-stepper">
<template>
<style>
:host {
display: flex;
font-size: 14px;
counter-reset: step;
@apply --mtz-wizard-stepper;
}
/* Used for controling text-overflow */
.step-wrapper {
flex: 1;
overflow: hidden;
counter-increment: step;
@apply --mtz-wizard-stepper__step-wrapper;
}
/* Adds line between steps */
.step-wrapper:not(:first-of-type) > .step::before,
.step-wrapper:not(:last-of-type) > .step::after {
content: '';
height: 1px;
flex: 1;
min-width: 16px;
background-color: var(--mtz-wizard-stepper__step-line--color, #BDBDBD); /* Grey 400 */
@apply --mtz-wizard-stepper__step-line;
}
/* Overrides first and last step margin */
.step-wrapper:first-of-type .badge-wrapper {
margin-left: 24px;
@apply --mtz-wizard-stepper__first-step-badge;
}
.step-wrapper:last-of-type .label-wrapper {
margin-right: 24px;
@apply --mtz-wizard-stepper__last-step-label;
}
/* Aligns the step information */
.step {
position: relative;
display: flex;
flex: 1;
align-items: center;
height: 72px;
cursor: pointer;
@apply --mtz-wizard-stepper__step;
}
/* Hover for non-disabled steps */
.step:not([disabled]):hover {
background-color: var(--mtz-wizard-stepper__step-hover--background-color, rgba(0,0,0,0.06)); /* 6% Black */
@apply --mtz-wizard-stepper__step-hover;
}
/* Prevents clicking on steps */
.step[disabled] {
pointer-events: none;
z-index: 1;
cursor: not-allowed;
@apply --mtz-wizard-stepper__step-disabled;
}
/* Active/Completed Step */
.step[active] .badge,
.step[completed] .badge {
background-color: var(--primary-color, #2196F3); /* Blue 500 */
@apply --mtz-wizard-stepper__active-badge;
}
/* Make icons smaller except invalid */
.step:not([invalid]) iron-icon {
--iron-icon-height: 16px;
--iron-icon-width: 16px;
@apply --mtz-wizard-stepper__valid-icons;
}
/* Positions badge and badge content */
.badge-wrapper {
position: relative;
margin-right: 8px;
margin-left: 8px;
font-size: 12px;
color: var(--mtz-wizard-stepper__badge-wrapper--color, #FFF);
@apply --mtz-wizard-stepper__badge-wrapper;
}
.badge-wrapper,
.badge {
height: 24px;
width: 24px;
@apply --mtz-wizard-stepper__badge-sizer;
}
.badge {
background-color: var(--mtz-wizard-stepper__badge--background-color, rgba(0,0,0,0.38)); /* 38% Black */
border-radius: 50%;
@apply --mtz-wizard-stepper__badge;
}
/* Position icon and counter over badge */
.badge-wrapper::before,
.badge-wrapper > iron-icon {
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 0;
left: 0;
text-align: center;
@apply --mtz-wizard-stepper__badge-positioning;
}
/* Apply counter to step badge */
.step:not([completed]) > .badge-wrapper::before {
content: counter(step);
@apply --mtz-wizard-stepper__badge-counter;
}
/* Badge should not display for invalid steps */
.step[invalid] .badge {
display: none;
@apply --mtz-wizard-stepper__invalid-badge;
}
.label-wrapper {
display: flex;
flex-direction: column;
margin-right: 8px;
overflow: hidden;
@apply --mtz-wizard-stepper__label-wrapper;
}
.label {
font-size: 14px;
color: var(--mtz-wizard-stepper__label--color, rgba(0,0,0,0.38)); /* 38% Black */
@apply --mtz-wizard-stepper__label;
}
/* Ellipsis long text */
.label,
.optional {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
@apply --mtz-wizard-stepper__label-overflow;
}
.label + .optional {
font-size: 12px;
color: var(--mtz-wizard-stepper__optional-label--color, rgba(0,0,0,0.54)); /* 54% Black */
@apply --mtz-wizard-stepper__optional-label;
}
/* Selected step */
.step[active] .label {
font-weight: 500; /* Medium */
color: var(--mtz-wizard-stepper__active-label--color, rgba(0,0,0,0.87)); /* 87% Black */
@apply --mtz-wizard-stepper__active-label;
}
/* Apply invalid state */
.step[invalid] .label,
.step[invalid] .optional,
.step[invalid] iron-icon {
color: var(--error-color, #F44336); /* Red 500 */
@apply --mtz-wizard-stepper__invalid-step-content;
}
/* Override browser specificity */
[hidden],
:host([hidden]) {
display: none !important;
}
</style>
<template is="dom-repeat" items="[[__steps]]" as="step">
<div class="step-wrapper">
<div class="step"
active$="[[step.active]]"
dirty$="[[step.dirty]]"
invalid$="[[step.invalid]]"
optional$="[[step.optional]]"
editable$="[[step.editable]]"
disabled$="[[__preventSkipping(linear, selectedIndex, index)]]"
on-click="selectStep">
<div class="badge-wrapper">
<iron-icon
icon="[[_getStepIcon(step.active, step.invalid, step.editable, step.completed)]]"
hidden="[[!_getStepIcon(step.active, step.invalid, step.editable, step.completed)]]"
></iron-icon>
<div class="badge"></div>
</div>
<div class="label-wrapper">
<span class="label">[[localize(step.label)]]</span>
<span class="optional">[[_getSubText(step.invalid, step.optional, step.errorMessage)]]</span>
</div>
<paper-ripple></paper-ripple>
</div>
</div>
</template>
</template>
<script>
Polymer({
is: 'mtz-wizard-stepper',
behaviors: [mtz.WizardStepperBehavior],
properties: {
linear: Boolean,
vertical: Boolean, // TODO: implement
alternative: Boolean, // TODO: implement
},
/**
* Determine the icon based on the state of the step
*
* @param {Boolean} active
* @param {Boolean} invalid
* @param {Boolean} editable
* @param {Boolean} completed
* @return {String}
* @protected
*/
_getStepIcon(active, invalid, editable, completed) {
return invalid ? 'icons:report-problem' :
(active || !completed) ? '' :
editable ? 'editor:mode-edit' :
'icons:done';
},
/**
* Determine the subtext of the step
*
* @param {Boolean} invalid
* @param {Boolean} optional - Shows an invalid message if true
* @param {String} [errorMessage=''] - Used for subtext if the step is invalid
* @return {String}
* @protected
*/
_getSubText(invalid, optional, errorMessage = '') {
return invalid && errorMessage ? this.localize(errorMessage) :
optional ? this.localize('OPTIONAL') :
undefined;
},
/**
* Prevents non-linear movement on a linear stepper
*
* @param {Boolean} linear
* @param {Number} selectedIndex
* @param {Number} index - current index
* @return {Boolean}
* @private
*/
__preventSkipping(linear, selectedIndex, index) {
return linear && (index !== selectedIndex);
},
});
</script>
</dom-module>