-
Notifications
You must be signed in to change notification settings - Fork 8
/
timeu-wizard.html
379 lines (324 loc) · 11.4 KB
/
timeu-wizard.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../shadycss/apply-shim.html">
<link rel="import" href="../polymer/lib/utils/render-status.html">
<link rel="import" href="../polymer/lib/elements/dom-repeat.html">
<link rel="import" href="../polymer/lib/utils/async.html">
<link rel="import" href="../polymer/lib/mixins/gesture-event-listeners.html">
<!--
An element for displaying the progress of a wizard as a series of connected circles.
By default the step number is displayed inside the circle and if provided a label below.
The available steps are provided by either as an `array` of `Objects` or an `array` of `Strings`.
Simple example:
<timeu-wizard steps='["Step1","Step2","Step3"]' step="2"></timeu-wizard>
By providing an `array` of `Objects` users can provide custom contents for the circles.
Example with custom circle content:
<timeu-wizard steps='[{"label:Step1","content":"A"},{label:"Step2","content":"B"}]'></timeu-wizard>
It is also possible to display a vertical progress by adding the `vertical` attribute:
<timeu-wizard vertical steps='["Step1","Step2","Step3"]' step="2"></timeu-wizard>
### Styling
The following custom properties and mixins are also available for styling:
Custom property | Description | Default
----------------|-------------|----------
`--timeu-wizard-line-color` | The color of the line | `#dfdfdf`
`--timeu-wizard-line-size` | The thickness of the line | `1px`
`--timeu-wizard-circle-size` | The size of the circle | `40px`
`--timeu-wizard-filling-color` | The collor of the filling of the line | `#2db36f`
`--timeu-wizard-anim-speed` | The animation speed for the circles and lines | `0.5s`
`--timeu-wizard-active-color` | The color of finished steps and the current active step | `#2db36f`
`--timeu-wizard-label-font-size` | The font-size of the labels | `13px`
`--timeu-wizard-step-font-size` | The font-size of the steps inside of the circle | `25px`
`--timeu-wizard-circle-border-size` | The thickness of the circle border | `1px`
`--timeu-wizard` | Mixin applied to element host | {}
`--timeu-wizard-container` | Mixin applied to container div | {}
`--timeu-wizard-list` | Mixin applied to steps list | {}
`--timeu-wizard-list-item` | Mixin applied to each step | {}
`--timeu-wizard-list-item-active` | Mixin applied to each active step | {}
`--timeu-wizard-list-item-done` | Mixin applied to each done step | {}
`--timeu-wizard-list-item-icon` | Mixin applied to each step icon | {}
`--timeu-wizard-list-item-checkicon` | Mixin applied to each done step icon | {}
@group wizards
@element timeu-wizard
@demo demo/index.html
@hero hero.svg
-->
<dom-module id="timeu-wizard">
<template>
<style>
:host {
display: block;
box-sizing: border-box;
width:100%;
height:100%;
@apply --timeu-wizard ;
}
:host([horizotnal]) ul {
flex-direction: row;
}
:host([vertical]) ul {
flex-direction: column;
}
:host([vertical]) .line {
width: 1px;
top:0;
left: 50%;
height: calc(100% - var(--timeu-wizard-circle-size,40px));
}
ul {
display: flex;
justify-content: space-between;
padding:0;
margin:0;
@apply --timeu-wizard-list;
}
#line{
background-color:var(--timeu-wizard-line-color,#dfdfdf);
}
.line {
height: var(--timeu-wizard-line-size,1px);
position: absolute;
top: calc(var(--timeu-wizard-circle-size,40px)/2);
left: 0;
right: 0;
}
#filling {
background-color: var(--timeu-wizard-filling-color,#2db36f);
-webkit-transition: -webkit-transform var(--timeu-wizard-anim-speed,0.5s);
-moz-transition: -moz-transform var(--timeu-wizard-anim-speed,0.5s);
transition: transform var(--timeu-wizard-anim-speed,0.5s);
}
#filling {
-webkit-transform: scaleX(0);
-moz-transform: scaleX(0);
-ms-transform: scaleX(0);
-o-transform: scaleX(0);
transform: scaleX(0);
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-ms-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
:host([vertical]) #filling {
-webkit-transform: scaleY(0);
-moz-transform: scaleY(0);
-ms-transform: scaleY(0);
-o-transform: scaleY(0);
transform: scaleY(0);
-webkit-transform-origin: top center;
-moz-transform-origin: top center;
-ms-transform-origin: top center;
-o-transform-origin: top center;
transform-origin: top center;
}
#container {
width: 100%;
height:100%;
position:relative;
@apply --timeu-wizard-container;
}
#wizard {
counter-reset: step;
height:100%;
width:100%;
}
#wizard li {
list-style-type:none;
position: relative;
text-align: center;
color: var(--timeu-wizard-filling-color,#dfdfdf);
@apply --timeu-wizard-list-item;
}
#wizard li[data-content]:before {
content: attr(data-content);
}
#wizard li:before {
content: counter(step);
counter-increment: step;
width: var(--timeu-wizard-circle-size,40px);
height: var(--timeu-wizard-circle-size,40px);
line-height: var(--timeu-wizard-circle-size,40px);
border: var(--timeu-wizard-circle-border-size,1px) solid var(--timeu-wizard-filling-color,#dfdfdf);
display: block;
text-align: center;
font-family:var(--timeu-wizard-step-font-family);
margin: 0 auto 5px auto;
border-radius: 50%;
background-color: white;
-webkit-transition: background-color var(--timeu-wizard-anim-speed,0.5s), border-color var(--timeu-wizard-anim-speed,0.5s);;
-moz-transition: background-color var(--timeu-wizard-anim-speed,0.5s), border-color var(--timeu-wizard-anim-speed,0.5s);
transition: background-colorvar(--timeu-wizard-anim-speed,0.5s), border-color var(--timeu-wizard-anim-speed,0.5s);
font-size:var(--timeu-wizard-step-font-size,25px);
@apply --timeu-wizard-list-item-icon;
}
#wizard li.active, #wizard li.done {
color: var(--timeu-wizard-active-color,#2db36f);
@apply --timeu-wizard-list-item-active;
}
#wizard li.done {
@apply --timeu-wizard-list-item-done;
}
#wizard li.done:before {
content:'';
}
#wizard li.active:before, #wizard li.done:before{
border-color: var(--timeu-wizard-active-color,#2db36f) !important;
}
#wizard li.active:before {
background-color: var(--timeu-wizard-active-color, #2db36f);
color: white;
}
.checkicon {
opacity:0;
height: var(--timeu-wizard-circle-size,40px);
width: var(--timeu-wizard-circle-size,40px);
position: absolute;
fill: var(--timeu-wizard-active-color,#2db36f);
top: 0px;
left: calc(50% - var(--timeu-wizard-circle-size,40px)/2);
transition: all var(--timeu-wizard-anim-speed,0.5s);
-webkit-transition: all var(--timeu-wizard-anim-speed,0.5s);
@apply --timeu-wizard-list-item-checkicon;
}
#wizard li.done .checkicon {
opacity:1;
}
.label {
font-size: var(--timeu-wizard-label-font-size,13px);
}
</style>
<div id="container">
<span id="line" class="line"></span>
<span id="filling" class="line" style$="transform: scale({{_calculateFilling(steps,step,vertical)}});"></span>
<ul id="wizard">
<template is="dom-repeat" items="{{steps}}" >
<li class$="{{_computeClass(index,item,step)}}" data-content$="{{item.content}}" on-tap="_handleItemTap">
<div class="checkicon">
<svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" style="pointer-events: none; display: block; width: 100%; height: 100%;">
<g>
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path>
</g>
</svg>
</div>
<span class="label">{{_getLabel(item)}}</span>
</li>
</template>
</ul>
</div>
</template>
<script>
class TimeuWizard extends Polymer.GestureEventListeners(Polymer.Element) {
static get is() { return 'timeu-wizard'; }
static get properties() {
return {
/**
* Fired when a step item is tapped.
*
* @event timeu-wizard-item-tap
*/
/**
* `step` indicates the current step in the wizard
*/
step: {
type: Number,
notify: true,
value: 1,
observer: '_validateStep'
},
/**
* Specifiies the available steps.
*
* @type [string]
*/
steps: {
type: Array,
value: function() {
return [];
}
},
/**
* If set to true, a vertical progress wizard will be displayed.
*
* @type [string]
*/
vertical: {
type: Boolean,
value: false,
reflectToAttribute: true
}
}
}
// Element Lifecycle
connectedCallback() {
super.connectedCallback();
Polymer.RenderStatus.beforeNextRender(this, function() {
this._width = this.getBoundingClientRect().width;
});
}
// Element Behavior
/**
* Increment the current step
*
* Use this function for moving to the next step in the wizard
*/
increment() {
if (this.step < this.steps.length) {
this.step++;
}
}
/**
* Decrement the current step
*
* Use this function for moving to the previous step in the wizard
*/
decrement() {
if (this.step > 1) {
this.step--;
}
}
_validateStep(newValue,oldValue) {
if (this.steps === undefined) {
return;
}
if (newValue < 1 || newValue === undefined || newValue > this.steps.length) {
Polymer.Async.microTask.run(() => {
this.step = oldValue
});
}
}
_getLabel(item) {
if (item !== null && typeof item === 'object' && item.label !== undefined) {
return item.label;
}
return item;
}
_computeClass(index, item, step) {
if ((index+1) < step) {
return "done";
}
else if (index+1 == step) {
return "active";
}
return "";
}
_caclulateRatio(steps, step) {
if (steps === undefined || step === 1) {
return 0;
}
else if (step === steps.length) {
return 1;
}
return (step-1)/(steps.length-1);
}
_calculateFilling(steps, step, vertical) {
var ratio = this._caclulateRatio(steps,step);
var scaleX = (vertical ? 1 : ratio);
var scaleY = (vertical ? ratio : 1);
return scaleX+","+scaleY;
}
_handleItemTap(e) {
this.dispatchEvent(new CustomEvent('timeu-wizard-item-tap', { bubbles: true, composed: true, detail: {model: e.model, target:e.target} }));
}
}
window.customElements.define(TimeuWizard.is, TimeuWizard);
</script>
</dom-module>