@@ -57,54 +57,52 @@ if (languages.default?.default["en"]?.weekdays) {
5757 <div
5858 class="cds--date-picker"
5959 [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',
6263 'cds--date-picker--light' : theme === 'light',
6364 'cds--skeleton' : skeleton
6465 }">
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>
108106 </div>
109107 </div>
110108 ` ,
@@ -125,10 +123,7 @@ export class DatePicker implements
125123 AfterViewInit {
126124 private static datePickerCount = 0 ;
127125
128- /**
129- * Select calendar range mode
130- */
131- @Input ( ) range = false ;
126+ @Input ( ) datePickerType : "simple" | "single" | "range" = "simple" ;
132127
133128 /**
134129 * Format of date
@@ -199,7 +194,7 @@ export class DatePicker implements
199194 */
200195 @Input ( ) warnText : string | TemplateRef < any > ;
201196
202- @Input ( ) size : "sm" | "md" | "lg" = "md " ;
197+ @Input ( ) size : "sm" | "md" | "lg" = "sm " ;
203198 /**
204199 * Set to `true` to display the invalid state for the second datepicker input.
205200 */
@@ -227,11 +222,11 @@ export class DatePicker implements
227222 }
228223 get flatpickrOptions ( ) {
229224 const plugins = [ ...this . plugins , carbonFlatpickrMonthSelectPlugin ] ;
230- if ( this . range ) {
225+ if ( this . datePickerType === " range" ) {
231226 plugins . push ( rangePlugin ( { input : `#${ this . id } -rangeInput` , position : "left" } ) ) ;
232227 }
233228 return Object . assign ( { } , this . _flatpickrOptions , this . flatpickrBaseOptions , {
234- mode : this . range ? "range" : "single" ,
229+ mode : this . datePickerType === " range" ? "range" : "single" ,
235230 plugins,
236231 dateFormat : this . dateFormat ,
237232 locale : languages . default ?. default [ this . language ] || languages . default [ this . language ]
@@ -267,7 +262,7 @@ export class DatePicker implements
267262 onClose : ( date ) => {
268263 // This makes sure that the `flatpickrInstance selectedDates` are in sync with the values of
269264 // the inputs when the calendar closes.
270- if ( this . range && this . flatpickrInstance ) {
265+ if ( this . datePickerType === " range" && this . flatpickrInstance ) {
271266 if ( this . flatpickrInstance . selectedDates . length !== 2 ) {
272267 // we could `this.flatpickrInstance.clear()` but it insists on opening the second picker
273268 // in some cases, so instead we do this
@@ -354,7 +349,7 @@ export class DatePicker implements
354349 onFocus ( ) {
355350 // Updates the month manually when calendar mode is range because month
356351 // will not update properly without manually updating them on focus.
357- if ( this . range ) {
352+ if ( this . datePickerType === " range" ) {
358353 if ( this . rangeInput . input . nativeElement === document . activeElement && this . flatpickrInstance . selectedDates [ 1 ] ) {
359354 const currentMonth = this . flatpickrInstance . selectedDates [ 1 ] . getMonth ( ) ;
360355 this . flatpickrInstance . changeMonth ( currentMonth , false ) ;
@@ -420,7 +415,7 @@ export class DatePicker implements
420415 onValueChange ( event : string ) {
421416 if ( this . isFlatpickrLoaded ( ) ) {
422417 const date = this . flatpickrInstance . parseDate ( event , this . dateFormat ) ;
423- if ( this . range ) {
418+ if ( this . datePickerType === " range" ) {
424419 this . setDateValues ( [ date , this . flatpickrInstance . selectedDates [ 1 ] ] ) ;
425420 } else {
426421 this . setDateValues ( [ date ] ) ;
@@ -444,7 +439,7 @@ export class DatePicker implements
444439 * Handles opening the calendar "properly" when the calendar icon is clicked.
445440 */
446441 openCalendar ( datepickerInput : DatePickerInput ) {
447- if ( this . range ) {
442+ if ( this . datePickerType === " range" ) {
448443 datepickerInput . input . nativeElement . click ( ) ;
449444
450445 // If the first input's calendar icon is clicked when calendar is in range mode, then
@@ -652,7 +647,7 @@ export class DatePicker implements
652647 // In range mode, if a date is selected from the first calendar that is from the previous month,
653648 // the month will not be updated on the calendar until the calendar is re-opened.
654649 // 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 ] ) {
656651 const currentMonth = this . flatpickrInstance . selectedDates [ 0 ] . getMonth ( ) ;
657652
658653 // `flatpickrInstance.changeMonth` removes the focus on the selected date element and will
0 commit comments