-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathstepper-base.ts
287 lines (257 loc) · 9.09 KB
/
stepper-base.ts
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
import { Component, INotifyPropertyChanged, NotifyPropertyChanges, Property, ChildProperty, Collection, Event, EmitType, isNullOrUndefined } from '@syncfusion/ej2-base';
import { StepperBaseModel, StepModel } from './stepper-base-model';
const PROGRESSVALUE: string = '--progress-value';
const PROGRESSPOS: string = '--progress-position';
const VERTICALSTEP: string = 'e-vertical';
const HORIZSTEP: string = 'e-horizontal';
const ITEMLIST: string = 'e-stepper-steps';
/**
* Defines the status of the step.
*/
export enum StepStatus {
/**
* Shows the status of the step is not started.
*/
NotStarted = 'NotStarted',
/**
* Shows the step is in progress.
*/
InProgress = 'InProgress',
/**
* Shows the status of the step is completed.
*/
Completed = 'Completed'
}
/**
* Specifies the steps of the Stepper.
*/
export class Step extends ChildProperty<Step> {
/**
* Defines the CSS class to customize the step appearance.
*
* @default ''
*/
@Property('')
public cssClass: string;
/**
* Defines whether a step is enabled or disabled.
*
* @default false
*/
@Property(false)
public disabled: boolean;
/**
* Defines the icon content of the step.
*
* @default ''
*/
@Property('')
public iconCss: string;
/**
* Defines the state whether it is valid completion or not.
*
* @aspType bool?
* @default null
*/
@Property(null)
public isValid: boolean;
/**
* Defines the label content of the step.
*
* @default ''
*/
@Property('')
public label: string;
/**
* Defines whether the step is optionally to skip completion or not.
*
* @default false
*/
@Property(false)
public optional: boolean;
/**
* Defines the status of the step.
* The possible values are
* * NotStarted
* * InProgress
* * Completed
*
* @isenumeration true
* @default StepStatus.NotStarted
* @asptype StepStatus
*/
@Property(StepStatus.NotStarted)
public status: string | StepStatus;
/**
* Defines the text content of the step.
*
* @default ''
*/
@Property('')
public text: string;
}
/**
* Defines the orientation type of the Stepper.
*/
export enum StepperOrientation {
/**
* Steps are displayed horizontally.
*/
Horizontal = 'Horizontal',
/**
* Steps are displayed vertically.
*/
Vertical = 'Vertical'
}
/**
* StepperBase component act as base class to the stepper component.
*/
@NotifyPropertyChanges
export class StepperBase extends Component<HTMLElement> implements INotifyPropertyChanged {
/**
* Defines the list of steps.
*
* @default []
*/
@Collection<StepModel[]>([], Step)
public steps: StepModel[];
/**
* Defines the CSS class to customize the Stepper appearance.
*
* @default ''
*/
@Property('')
public cssClass: string;
/**
* Defines whether the read-only mode is enabled for a Stepper control, which means that the user will not be able to interact with it.
*
* @default false
*/
@Property(false)
public readOnly: boolean;
/**
* Defines the orientation type of the Stepper.
*
* The possible values are:
* * Horizontal
* * vertical
*
* @isenumeration true
* @default StepperOrientation.Horizontal
* @asptype StepperOrientation
*/
@Property(StepperOrientation.Horizontal)
public orientation: string | StepperOrientation;
/**
* Event callback that is raised after rendering the stepper.
*
* @event created
*/
@Event()
public created: EmitType<Event>;
/* protected variables */
protected progressStep: HTMLElement;
protected progressbar : HTMLElement;
protected progressBarPosition: number;
/**
* * Constructor for Base class
*
* @param {StepperBaseModel} options - Specifies the Base model.
* @param {string | HTMLElement} element - Specifies the element to render as component.
* @private
*/
public constructor(options?: StepperBaseModel, element?: string | HTMLElement) {
super(options, element);
}
/**
* This method is abstract member of the Component<HTMLElement>.
*
* @private
* @returns {void}
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
protected preRender(): void {
}
/**
* This method is abstract member of the Component<HTMLElement>.
*
* @private
* @returns {string} - It returns the current module name.
*/
public getModuleName(): string {
return 'stepperBase';
}
/**
* This method is abstract member of the Component<HTMLElement>.
*
* @private
* @returns {string} - It returns the persisted data.
*/
protected getPersistData(): string {
return this.addOnPersist([]);
}
/**
* This method is abstract member of the Component<HTMLElement>.
*
* @private
* @returns {void}
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
protected render(): void {
}
protected updateOrientaion(wrapper: HTMLElement): void {
if (wrapper.classList.contains(HORIZSTEP) || wrapper.classList.contains(VERTICALSTEP)) {
wrapper.classList.remove(HORIZSTEP, VERTICALSTEP);
}
if (!(isNullOrUndefined(this.orientation))) {
wrapper.classList.add('e-' + this.orientation.toLocaleLowerCase());
}
}
protected renderProgressBar(wrapper: HTMLElement): void {
this.progressStep = this.createElement('div', { className: 'e-stepper-progressbar' });
this.progressbar = this.createElement('div', { className: 'e-progressbar-value' });
const beforeLabel: HTMLElement = (wrapper.querySelector('li').querySelector('.e-step-label-container'));
this.progressStep.appendChild(this.progressbar);
wrapper.prepend(this.progressStep);
this.progressbar.style.setProperty(PROGRESSVALUE, (0) + '%');
if (wrapper.classList.contains(VERTICALSTEP)) {
if (wrapper.classList.contains('e-label-bottom') || wrapper.classList.contains('e-label-top')) {
const stepsContainer: HTMLElement = (wrapper.querySelector('.' + ITEMLIST));
this.progressStep.style.setProperty(PROGRESSPOS, (stepsContainer.offsetWidth / 2) + 'px');
}
else { this.progressStep.style.setProperty(PROGRESSPOS, ((this.progressBarPosition / 2) - 1) + 'px'); }
}
if (beforeLabel && (beforeLabel.classList.contains('e-label-before'))) { this.progressStep.style.setProperty(PROGRESSPOS, (((this.progressBarPosition) - 1)) + 5 + 'px'); }
if (wrapper.classList.contains(HORIZSTEP)) { this.setProgressPosition(wrapper); }
}
protected setProgressPosition(wrapper: HTMLElement, isResize?: boolean): void {
const stepItemContainer: HTMLElement = (wrapper.querySelector('.e-step-container'));
const stepItemEle: HTMLElement = (stepItemContainer.firstElementChild as HTMLElement);
if (isResize !== true) {
let topPos: number = 0;
if (wrapper.classList.contains('e-label-before')) { topPos = ((stepItemContainer.offsetParent as HTMLElement).offsetHeight - (stepItemEle.offsetHeight / 2) - 1); }
else { topPos = (stepItemEle.offsetHeight / 2); }
this.progressStep.style.setProperty('--progress-top-position', topPos + 'px');
}
const lastEle: HTMLElement = wrapper.querySelector('.' + ITEMLIST).lastChild.firstChild as HTMLElement;
if (wrapper.classList.contains('e-rtl')) {
const leftPost: number = ((stepItemEle.offsetLeft + stepItemEle.offsetWidth) - (wrapper.querySelector('.' + ITEMLIST) as HTMLElement).offsetWidth);
this.progressStep.style.setProperty('--progress-left-position', Math.abs(leftPost) + 'px');
this.progressStep.style.setProperty('--progress-bar-width', Math.abs(lastEle.offsetLeft - stepItemEle.offsetLeft) + 'px');
} else {
this.progressStep.style.setProperty('--progress-left-position', (stepItemEle.offsetLeft + 1) + 'px');
this.progressStep.style.setProperty('--progress-bar-width', ((lastEle.offsetWidth + lastEle.offsetLeft - 2) - (stepItemEle.offsetLeft + 2)) + 'px');
}
}
/**
* This method is abstract member of the Component<HTMLElement>.
*
* @param {StepperBaseModel} newProp - Specifies new properties
* @param {StepperBaseModel} oldProp - Specifies old properties
* @private
* @returns {void}
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
public onPropertyChanged(newProp: StepperBaseModel, oldProp: StepperBaseModel): void {
}
}