@@ -58,54 +58,50 @@ if (languages.default?.default["en"]?.weekdays) {
5858 <div
5959 class="cds--date-picker"
6060 [ngClass]="{
61- 'cds--date-picker--range' : range,
62- 'cds--date-picker--single' : !range,
61+ 'cds--date-picker--simple' : datePickerType === 'simple',
62+ 'cds--date-picker--range' : datePickerType === 'range',
63+ 'cds--date-picker--single' : datePickerType === 'single',
6364 'cds--date-picker--light' : theme === 'light',
6465 'cds--skeleton' : skeleton
6566 }">
66- <div class="cds--date-picker-container">
67- <cds-date-picker-input
68- #input
69- [label]="label"
70- [placeholder]="placeholder"
71- [pattern]="inputPattern"
72- [id]="id + '-input'"
73- [size]="size"
74- [type]="(range ? 'range' : 'single')"
75- [hasIcon]="(range ? false : true)"
76- [disabled]="disabled"
77- [invalid]="invalid"
78- [invalidText]="invalidText"
79- [warn]="warn"
80- [warnText]="warnText"
81- [skeleton]="skeleton"
82- [helperText]="helperText"
83- (valueChange)="onValueChange($event)"
84- (click)="openCalendar(input)">
85- </cds-date-picker-input>
86- </div>
87-
88- <div *ngIf="range" class="cds--date-picker-container">
89- <cds-date-picker-input
90- #rangeInput
91- [label]="rangeLabel"
92- [placeholder]="placeholder"
93- [pattern]="inputPattern"
94- [id]="id + '-rangeInput'"
95- [size]="size"
96- [type]="(range ? 'range' : 'single')"
97- [hasIcon]="(range ? true : null)"
98- [disabled]="disabled"
99- [invalid]="rangeInvalid"
100- [invalidText]="rangeInvalidText"
101- [warn]="rangeWarn"
102- [warnText]="rangeWarnText"
103- [skeleton]="skeleton"
104- [helperText]="rangeHelperText"
105- (valueChange)="onRangeValueChange($event)"
106- (click)="openCalendar(rangeInput)">
107- </cds-date-picker-input>
108- </div>
67+ <cds-date-picker-input
68+ #input
69+ [label]="label"
70+ [placeholder]="placeholder"
71+ [pattern]="inputPattern"
72+ [id]="id + '-input'"
73+ [size]="size"
74+ [type]="datePickerType"
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"
95+ [disabled]="disabled"
96+ [invalid]="rangeInvalid"
97+ [invalidText]="rangeInvalidText"
98+ [warn]="rangeWarn"
99+ [warnText]="rangeWarnText"
100+ [skeleton]="skeleton"
101+ [helperText]="rangeHelperText"
102+ (valueChange)="onRangeValueChange($event)"
103+ (click)="openCalendar(rangeInput)">
104+ </cds-date-picker-input>
109105 </div>
110106 </div>
111107 ` ,
@@ -126,10 +122,7 @@ export class DatePicker implements
126122 AfterViewInit {
127123 private static datePickerCount = 0 ;
128124
129- /**
130- * Select calendar range mode
131- */
132- @Input ( ) range = false ;
125+ @Input ( ) datePickerType : "simple" | "single" | "range" = "simple" ;
133126
134127 /**
135128 * Format of date
@@ -228,11 +221,11 @@ export class DatePicker implements
228221 }
229222 get flatpickrOptions ( ) : Partial < Options > {
230223 const plugins = [ ...this . plugins , carbonFlatpickrMonthSelectPlugin ] ;
231- if ( this . range ) {
224+ if ( this . datePickerType === " range" ) {
232225 plugins . push ( rangePlugin ( { input : `#${ this . id } -rangeInput` , position : "left" } ) ) ;
233226 }
234227 return Object . assign ( { } , this . _flatpickrOptions , this . flatpickrBaseOptions , {
235- mode : this . range ? "range" : "single" ,
228+ mode : this . datePickerType === " range" ? "range" : "single" ,
236229 plugins,
237230 dateFormat : this . dateFormat ,
238231 locale : languages . default ?. default [ this . language ] || languages . default [ this . language ]
@@ -268,7 +261,7 @@ export class DatePicker implements
268261 onClose : ( date ) => {
269262 // This makes sure that the `flatpickrInstance selectedDates` are in sync with the values of
270263 // the inputs when the calendar closes.
271- if ( this . range && this . flatpickrInstance ) {
264+ if ( this . datePickerType === " range" && this . flatpickrInstance ) {
272265 const inputValue = this . input . input . nativeElement . value ;
273266 const rangeInputValue = this . rangeInput . input . nativeElement . value ;
274267 if ( inputValue || rangeInputValue ) {
@@ -332,7 +325,7 @@ export class DatePicker implements
332325 // and because we rely on a library that operates outside the Angular view of the world
333326 // we need to keep trying to load the library, until the relevant DOM is actually live
334327 ngAfterViewChecked ( ) {
335- if ( ! this . isFlatpickrLoaded ( ) ) {
328+ if ( this . datePickerType !== "simple" && ! this . isFlatpickrLoaded ( ) ) {
336329 // @ts -ignore ts is unhappy with the below call to `flatpickr`
337330 this . flatpickrInstance = flatpickr ( `#${ this . id } -input` , this . flatpickrOptions ) ;
338331 // if (and only if) the initialization succeeded, we can set the date values
@@ -348,7 +341,7 @@ export class DatePicker implements
348341 onFocus ( ) {
349342 // Updates the month manually when calendar mode is range because month
350343 // will not update properly without manually updating them on focus.
351- if ( this . range ) {
344+ if ( this . datePickerType === " range" ) {
352345 if ( this . rangeInput . input . nativeElement === document . activeElement && this . flatpickrInstance . selectedDates [ 1 ] ) {
353346 const currentMonth = this . flatpickrInstance . selectedDates [ 1 ] . getMonth ( ) ;
354347 this . flatpickrInstance . changeMonth ( currentMonth , false ) ;
@@ -414,7 +407,7 @@ export class DatePicker implements
414407 onValueChange ( event : string ) {
415408 if ( this . isFlatpickrLoaded ( ) ) {
416409 const date = this . flatpickrInstance . parseDate ( event , this . dateFormat ) ;
417- if ( this . range ) {
410+ if ( this . datePickerType === " range" ) {
418411 this . setDateValues ( [ date , this . flatpickrInstance . selectedDates [ 1 ] ] ) ;
419412 } else {
420413 this . setDateValues ( [ date ] ) ;
@@ -438,7 +431,7 @@ export class DatePicker implements
438431 * Handles opening the calendar "properly" when the calendar icon is clicked.
439432 */
440433 openCalendar ( datepickerInput : DatePickerInput ) {
441- if ( this . range ) {
434+ if ( this . datePickerType === " range" ) {
442435 datepickerInput . input . nativeElement . click ( ) ;
443436
444437 // If the first input's calendar icon is clicked when calendar is in range mode, then
@@ -469,7 +462,7 @@ export class DatePicker implements
469462 * Handles the initialization of event listeners for the datepicker input and range input fields.
470463 */
471464 protected addInputListeners ( ) {
472- if ( ! this . isFlatpickrLoaded ( ) ) {
465+ if ( this . datePickerType === "simple" || ! this . isFlatpickrLoaded ( ) ) {
473466 return ;
474467 }
475468
@@ -520,7 +513,7 @@ export class DatePicker implements
520513 * @param newDates An optional SimpleChange of date values
521514 */
522515 protected resetFlatpickrInstance ( newDates ?: SimpleChange ) {
523- if ( this . isFlatpickrLoaded ( ) ) {
516+ if ( this . datePickerType !== "simple" && this . isFlatpickrLoaded ( ) ) {
524517 let dates = this . flatpickrInstance . selectedDates ;
525518 if ( newDates && this . didDateValueChange ( newDates . currentValue , newDates . previousValue ) ) {
526519 dates = newDates . currentValue ;
@@ -646,7 +639,7 @@ export class DatePicker implements
646639 // In range mode, if a date is selected from the first calendar that is from the previous month,
647640 // the month will not be updated on the calendar until the calendar is re-opened.
648641 // This will make sure the calendar is updated with the correct month.
649- if ( this . range && this . flatpickrInstance . selectedDates [ 0 ] ) {
642+ if ( this . datePickerType === " range" && this . flatpickrInstance . selectedDates [ 0 ] ) {
650643 const currentMonth = this . flatpickrInstance . selectedDates [ 0 ] . getMonth ( ) ;
651644
652645 // `flatpickrInstance.changeMonth` removes the focus on the selected date element and will
0 commit comments