-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathdate-range.sample.ts
More file actions
283 lines (265 loc) · 9.75 KB
/
date-range.sample.ts
File metadata and controls
283 lines (265 loc) · 9.75 KB
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
import { Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ViewChild } from '@angular/core';
import { JsonPipe } from '@angular/common';
import { UntypedFormGroup, UntypedFormBuilder, Validators, UntypedFormControl, ValidatorFn, AbstractControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DateRange, IgxButtonDirective, IgxDateRangePickerComponent, IgxDateTimeEditorDirective, IgxInputDirective, IgxLabelDirective, IgxRadioComponent, IgxRippleDirective, IGX_INPUT_GROUP_TYPE, IChangeCheckboxEventArgs, IGX_DATE_RANGE_PICKER_DIRECTIVES, IgxIconComponent, IgSizeDirective, CustomDateRange, CalendarDay, DateRangeType } from 'igniteui-angular';
import { defineComponents, IgcButtonComponent, IgcDateRangePickerComponent, IgcDateTimeInputComponent, IgcIconComponent } from 'igniteui-webcomponents';
import { Properties, PropertyChangeService, PropertyPanelConfig } from '../properties-panel/property-change.service';
defineComponents(IgcDateRangePickerComponent, IgcButtonComponent, IgcIconComponent, IgcDateTimeInputComponent);
@Component({
selector: 'app-date-range',
templateUrl: './date-range.sample.html',
styleUrls: ['./date-range.sample.scss'],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
{
provide: IGX_INPUT_GROUP_TYPE,
useValue: 'border'
}
],
imports: [
IgxButtonDirective,
IgxRippleDirective,
FormsModule,
IgxLabelDirective,
IgxRadioComponent,
ReactiveFormsModule,
JsonPipe,
IGX_DATE_RANGE_PICKER_DIRECTIVES,
IgxInputDirective,
IgxDateTimeEditorDirective,
IgxIconComponent,
IgSizeDirective
]
})
export class DateRangeSampleComponent {
@ViewChild('dr1', { static: true })
private dateRangePicker: IgxDateRangePickerComponent;
public range: DateRange = { start: new Date('2000,10,1'), end: new Date('2000,10,20') };
public range1: DateRange = { start: new Date(), end: new Date(new Date().setDate(new Date().getDate() + 5)) };
public range2: DateRange;
public range3: DateRange = { start: new Date(), end: new Date(new Date().setDate(new Date().getDate() + 5)) };
public range4: DateRange;
public range5: DateRange = { start: new Date(), end: new Date(new Date().setDate(new Date().getDate() + 5)) };
public range6Start = null;
public range6End = null;
public range6: DateRange = { start: this.range6Start, end: this.range6End };
public minDate: Date = new Date(new Date().setDate(new Date().getDate() - 20));
public maxDate: Date = new Date(new Date().setDate(new Date().getDate() + 25));
public today = CalendarDay.today;
public previousThreeMonthsStart = new Date(
this.today.native.getFullYear(),
this.today.native.getMonth() - 3,
1
);
public previousThreeMonthsEnd = new Date(
this.today.native.getFullYear(),
this.today.native.getMonth(),
0
);
public nextThreeMonthsStart = new Date(
this.today.native.getFullYear(),
this.today.native.getMonth() + 1,
1
);
public nextThreeMonthsEnd = new Date(
this.today.native.getFullYear(),
this.today.native.getMonth() + 4,
0
);
public customRanges : CustomDateRange[] = [
{ label:"Next three months", dateRange: {start: this.nextThreeMonthsStart, end: this.nextThreeMonthsEnd} },
{ label:"Previous three months", dateRange: {start: this.previousThreeMonthsStart, end: this.previousThreeMonthsEnd} },
]
public reactiveForm: UntypedFormGroup;
public DateRangeType = DateRangeType;
public updateOnOptions: string[] = ['change', 'blur', 'submit'];
public updateOn = 'blur';
public specialDates = [{
type: DateRangeType.Between, dateRange: [
new Date(new Date().getFullYear(), new Date().getMonth(), 3),
new Date(new Date().getFullYear(), new Date().getMonth(), 8)
]
}];
public disabledDates = [{
type: DateRangeType.Between, dateRange: [
new Date(new Date().getFullYear(), new Date().getMonth(), 20),
new Date(new Date().getFullYear(), new Date().getMonth(), 25)
]
}];
public panelConfig: PropertyPanelConfig = {
size: {
control: {
type: 'button-group',
options: ['small', 'medium', 'large'],
defaultValue: 'medium',
}
},
mode: {
control: {
type: 'button-group',
options: ['dropdown', 'dialog'],
defaultValue: 'dropdown'
}
},
value: {
control: {
type: 'date-range',
defaultValue: this.range3
}
},
minValue: {
label: 'Min Value',
control: {
type: 'date',
defaultValue: this.minDate
}
},
maxValue: {
label: 'Max Value',
control: {
type: 'date',
defaultValue: this.maxDate
}
},
required: {
control: {
type: 'boolean',
defaultValue: false
}
},
disabled: {
control: {
type: 'boolean',
defaultValue: false
}
},
placeholder: {
control: {
type: 'text',
defaultValue: 'MM/dd/yyyy'
}
},
hint: {
label: 'Hint Text',
control: {
type: 'text'
}
},
displayFormat: {
label: 'Display Format',
control: {
type: 'text'
}
},
inputFormat: {
label: 'Input Format',
control: {
type: 'text'
}
},
hideHeader: {
label: 'Hide Header (for dialog mode)',
control: {
type: 'boolean',
defaultValue: false
}
},
orientation: {
label: 'Orientation',
control: {
type: 'button-group',
options: ['horizontal', 'vertical'],
defaultValue: 'horizontal'
}
},
headerOrientation: {
label: 'Header Orientation (dialog mode)',
control: {
type: 'button-group',
options: ['horizontal', 'vertical'],
defaultValue: 'horizontal'
}
},
headerTemplate: {
label: 'Show Header Template (dialog)',
control: {
type: 'boolean',
defaultValue: false
}
},
calendarTitle: {
label: 'Show Calendar Title (dialog)',
control: {
type: 'boolean',
defaultValue: false
}
},
separator: {
label: 'Separator text',
control: {
type: 'text',
defaultValue: 'to'
}
},
visibleMonths: {
label: 'Visible Months',
control: {
type: 'number',
defaultValue: 2,
}
},
};
public properties: Properties;
constructor(
fb: UntypedFormBuilder,
private propertyChangeService: PropertyChangeService,
private destroyRef: DestroyRef
) {
const today = new Date();
const in5days = new Date();
in5days.setDate(today.getDate() + 5);
const r1: DateRange = { start: new Date(today.getTime()), end: new Date(in5days.getTime()) };
const r2: DateRange = { start: new Date(today.getTime()), end: new Date(in5days.getTime()) };
this.reactiveForm = fb.group({
dp1: [r1, { validators: Validators.required, updateOn: this.updateOn }],
dp2: ['', { validators: Validators.required, updateOn: this.updateOn }],
dp3: [r2, { validators: [Validators.required, minDateValidator(this.minDate)] }],
dp4: ['', { validators: Validators.required, updateOn: this.updateOn }],
start5: [r2.start, { validators: Validators.required, updateOn: this.updateOn }],
end5: [r2.end, { validators: Validators.required, updateOn: this.updateOn }],
start6: ['', { validators: Validators.required, updateOn: this.updateOn }],
end6: ['', { validators: Validators.required, updateOn: this.updateOn }],
});
this.propertyChangeService.setPanelConfig(this.panelConfig);
const propertyChange =
this.propertyChangeService.propertyChanges.subscribe(
(properties) => {
this.properties = properties;
}
);
this.destroyRef.onDestroy(() => propertyChange.unsubscribe());
}
public updateOnChange(e: IChangeCheckboxEventArgs) {
Object.keys(this.reactiveForm.controls).forEach(name => {
const control = this.reactiveForm.controls[name];
const value = control.value;
const newControl = new UntypedFormControl(
value,
{ updateOn: e.value, validators: Validators.required }
);
this.reactiveForm.setControl(name, newControl);
});
}
public changeLocale(locale: string) {
this.dateRangePicker.locale = locale;
}
public changeWeekStart(value: number) {
this.dateRangePicker.weekStart = value;
}
}
const minDateValidator = (minValue: Date): ValidatorFn => (control: AbstractControl): { [key: string]: any } | null => {
if (control.value && (control.value.start as Date).getTime() < minValue.getTime()) {
return { minValue: true };
}
return null;
};