@@ -57,54 +57,52 @@ if (languages.default?.default["en"]?.weekdays) {
57
57
<div
58
58
class="cds--date-picker"
59
59
[ngClass]="{
60
- 'cds--date-picker--range' : range,
61
- 'cds--date-picker--single' : !range,
60
+ 'cds--date-picker--simple' : datePickerType === 'simple',
61
+ 'cds--date-picker--range' : datePickerType === 'range',
62
+ 'cds--date-picker--single' : datePickerType === 'single',
62
63
'cds--date-picker--light' : theme === 'light',
63
64
'cds--skeleton' : skeleton
64
65
}">
65
- <div class="cds--date-picker-container">
66
- <cds-date-picker-input
67
- #input
68
- [label]="label"
69
- [placeholder]="placeholder"
70
- [pattern]="inputPattern"
71
- [id]="id + '-input'"
72
- [size]="size"
73
- [type]="(range ? 'range' : 'single')"
74
- [hasIcon]="(range ? false : true)"
75
- [disabled]="disabled"
76
- [invalid]="invalid"
77
- [invalidText]="invalidText"
78
- [warn]="warn"
79
- [warnText]="warnText"
80
- [skeleton]="skeleton"
81
- [helperText]="helperText"
82
- (valueChange)="onValueChange($event)"
83
- (click)="openCalendar(input)">
84
- </cds-date-picker-input>
85
- </div>
86
-
87
- <div *ngIf="range" class="cds--date-picker-container">
88
- <cds-date-picker-input
89
- #rangeInput
90
- [label]="rangeLabel"
91
- [placeholder]="placeholder"
92
- [pattern]="inputPattern"
93
- [id]="id + '-rangeInput'"
94
- [size]="size"
95
- [type]="(range ? 'range' : 'single')"
96
- [hasIcon]="(range ? true : null)"
97
- [disabled]="disabled"
98
- [invalid]="rangeInvalid"
99
- [invalidText]="rangeInvalidText"
100
- [warn]="rangeWarn"
101
- [warnText]="rangeWarnText"
102
- [skeleton]="skeleton"
103
- [helperText]="rangeHelperText"
104
- (valueChange)="onRangeValueChange($event)"
105
- (click)="openCalendar(rangeInput)">
106
- </cds-date-picker-input>
107
- </div>
66
+ <cds-date-picker-input
67
+ #input
68
+ [label]="label"
69
+ [placeholder]="placeholder"
70
+ [pattern]="inputPattern"
71
+ [id]="id + '-input'"
72
+ [size]="size"
73
+ [type]="datePickerType"
74
+ [hasIcon]="datePickerType !== 'simple'"
75
+ [disabled]="disabled"
76
+ [invalid]="invalid"
77
+ [invalidText]="invalidText"
78
+ [warn]="warn"
79
+ [warnText]="warnText"
80
+ [skeleton]="skeleton"
81
+ [helperText]="helperText"
82
+ (valueChange)="onValueChange($event)"
83
+ (click)="openCalendar(input)">
84
+ </cds-date-picker-input>
85
+
86
+ <cds-date-picker-input
87
+ *ngIf="datePickerType === 'range'"
88
+ #rangeInput
89
+ [label]="rangeLabel"
90
+ [placeholder]="placeholder"
91
+ [pattern]="inputPattern"
92
+ [id]="id + '-rangeInput'"
93
+ [size]="size"
94
+ [type]="(range ? 'range' : 'single')"
95
+ [hasIcon]="(range ? true : null)"
96
+ [disabled]="disabled"
97
+ [invalid]="rangeInvalid"
98
+ [invalidText]="rangeInvalidText"
99
+ [warn]="rangeWarn"
100
+ [warnText]="rangeWarnText"
101
+ [skeleton]="skeleton"
102
+ [helperText]="rangeHelperText"
103
+ (valueChange)="onRangeValueChange($event)"
104
+ (click)="openCalendar(rangeInput)">
105
+ </cds-date-picker-input>
108
106
</div>
109
107
</div>
110
108
` ,
@@ -125,10 +123,7 @@ export class DatePicker implements
125
123
AfterViewInit {
126
124
private static datePickerCount = 0 ;
127
125
128
- /**
129
- * Select calendar range mode
130
- */
131
- @Input ( ) range = false ;
126
+ @Input ( ) datePickerType : "simple" | "single" | "range" = "simple" ;
132
127
133
128
/**
134
129
* Format of date
@@ -199,7 +194,7 @@ export class DatePicker implements
199
194
*/
200
195
@Input ( ) warnText : string | TemplateRef < any > ;
201
196
202
- @Input ( ) size : "sm" | "md" | "lg" = "md " ;
197
+ @Input ( ) size : "sm" | "md" | "lg" = "sm " ;
203
198
/**
204
199
* Set to `true` to display the invalid state for the second datepicker input.
205
200
*/
@@ -227,11 +222,11 @@ export class DatePicker implements
227
222
}
228
223
get flatpickrOptions ( ) {
229
224
const plugins = [ ...this . plugins , carbonFlatpickrMonthSelectPlugin ] ;
230
- if ( this . range ) {
225
+ if ( this . datePickerType === " range" ) {
231
226
plugins . push ( rangePlugin ( { input : `#${ this . id } -rangeInput` , position : "left" } ) ) ;
232
227
}
233
228
return Object . assign ( { } , this . _flatpickrOptions , this . flatpickrBaseOptions , {
234
- mode : this . range ? "range" : "single" ,
229
+ mode : this . datePickerType === " range" ? "range" : "single" ,
235
230
plugins,
236
231
dateFormat : this . dateFormat ,
237
232
locale : languages . default ?. default [ this . language ] || languages . default [ this . language ]
@@ -267,7 +262,7 @@ export class DatePicker implements
267
262
onClose : ( date ) => {
268
263
// This makes sure that the `flatpickrInstance selectedDates` are in sync with the values of
269
264
// the inputs when the calendar closes.
270
- if ( this . range && this . flatpickrInstance ) {
265
+ if ( this . datePickerType === " range" && this . flatpickrInstance ) {
271
266
if ( this . flatpickrInstance . selectedDates . length !== 2 ) {
272
267
// we could `this.flatpickrInstance.clear()` but it insists on opening the second picker
273
268
// in some cases, so instead we do this
@@ -354,7 +349,7 @@ export class DatePicker implements
354
349
onFocus ( ) {
355
350
// Updates the month manually when calendar mode is range because month
356
351
// will not update properly without manually updating them on focus.
357
- if ( this . range ) {
352
+ if ( this . datePickerType === " range" ) {
358
353
if ( this . rangeInput . input . nativeElement === document . activeElement && this . flatpickrInstance . selectedDates [ 1 ] ) {
359
354
const currentMonth = this . flatpickrInstance . selectedDates [ 1 ] . getMonth ( ) ;
360
355
this . flatpickrInstance . changeMonth ( currentMonth , false ) ;
@@ -420,7 +415,7 @@ export class DatePicker implements
420
415
onValueChange ( event : string ) {
421
416
if ( this . isFlatpickrLoaded ( ) ) {
422
417
const date = this . flatpickrInstance . parseDate ( event , this . dateFormat ) ;
423
- if ( this . range ) {
418
+ if ( this . datePickerType === " range" ) {
424
419
this . setDateValues ( [ date , this . flatpickrInstance . selectedDates [ 1 ] ] ) ;
425
420
} else {
426
421
this . setDateValues ( [ date ] ) ;
@@ -444,7 +439,7 @@ export class DatePicker implements
444
439
* Handles opening the calendar "properly" when the calendar icon is clicked.
445
440
*/
446
441
openCalendar ( datepickerInput : DatePickerInput ) {
447
- if ( this . range ) {
442
+ if ( this . datePickerType === " range" ) {
448
443
datepickerInput . input . nativeElement . click ( ) ;
449
444
450
445
// If the first input's calendar icon is clicked when calendar is in range mode, then
@@ -652,7 +647,7 @@ export class DatePicker implements
652
647
// In range mode, if a date is selected from the first calendar that is from the previous month,
653
648
// the month will not be updated on the calendar until the calendar is re-opened.
654
649
// This will make sure the calendar is updated with the correct month.
655
- if ( this . range && this . flatpickrInstance . selectedDates [ 0 ] ) {
650
+ if ( this . datePickerType === " range" && this . flatpickrInstance . selectedDates [ 0 ] ) {
656
651
const currentMonth = this . flatpickrInstance . selectedDates [ 0 ] . getMonth ( ) ;
657
652
658
653
// `flatpickrInstance.changeMonth` removes the focus on the selected date element and will
0 commit comments