@@ -26,13 +26,13 @@ import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
2626 template : `
2727 <div class="bx--form-item">
2828 <ng2-flatpickr
29- [setDate]= "value"
30- [config]= "range ? flatpickrOptionsRange : flatpickrOptions"
29+ [setDate]="value"
30+ [config]=" flatpickrOptions"
3131 [hideButton]="true">
3232 <div class="bx--form-item">
3333 <div
3434 data-date-picker
35- [attr.data-date-picker-type]= " range ? 'range' : 'single'"
35+ [attr.data-date-picker-type]="( range ? 'range' : 'single') "
3636 class="bx--date-picker"
3737 [ngClass]="{
3838 'bx--date-picker--range' : range,
@@ -43,11 +43,11 @@ import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
4343 <div class="bx--date-picker-container">
4444 <ibm-date-picker-input
4545 [label]= "label"
46- [placeholder]= "placeholder"
47- [pattern]= "pattern"
48- [id]= "id"
49- [type]= " range ? 'range' : 'single'"
50- [hasIcon]= " range ? false : true"
46+ [placeholder]="placeholder"
47+ [pattern]="pattern"
48+ [id]="id"
49+ [type]="( range ? 'range' : 'single') "
50+ [hasIcon]="( range ? false : true) "
5151 [disabled]="disabled"
5252 [invalid]="invalid"
5353 [invalidText]="invalidText"
@@ -58,12 +58,12 @@ import rangePlugin from "flatpickr/dist/plugins/rangePlugin";
5858
5959 <div *ngIf="range" class="bx--date-picker-container">
6060 <ibm-date-picker-input
61- [label]= "rangeLabel"
62- [placeholder]= "placeholder"
63- [pattern]= "pattern"
64- [id]= "id + '-rangeInput'"
65- [type]= " range ? 'range' : 'single'"
66- [hasIcon]= " range ? true : null"
61+ [label]="rangeLabel"
62+ [placeholder]="placeholder"
63+ [pattern]="pattern"
64+ [id]="id + '-rangeInput'"
65+ [type]="( range ? 'range' : 'single') "
66+ [hasIcon]="( range ? true : null) "
6767 [disabled]="disabled"
6868 [invalid]="invalid"
6969 [invalidText]="invalidText"
@@ -89,7 +89,7 @@ export class DatePicker implements OnDestroy {
8989 /**
9090 * Select calendar range mode
9191 */
92- @Input ( ) range : boolean ;
92+ @Input ( ) range = false ;
9393
9494 /**
9595 * Format of date
@@ -120,20 +120,39 @@ export class DatePicker implements OnDestroy {
120120
121121 @Input ( ) skeleton = false ;
122122
123+ @Input ( ) plugins = [ ] ;
124+
125+ @Input ( )
126+ set flatpickrOptions ( options : FlatpickrOptions ) {
127+ this . _flatpickrOptions = Object . assign ( { } , this . _flatpickrOptions , options ) ;
128+ }
129+ get flatpickrOptions ( ) : FlatpickrOptions {
130+ const plugins = [ ...this . plugins ] ;
131+ if ( this . range ) {
132+ plugins . push ( rangePlugin ( { input : "#" + this . id + "-rangeInput" } ) ) ;
133+ }
134+ return Object . assign ( { } , this . _flatpickrOptions , this . flatpickrBaseOptions , { plugins} ) ;
135+ }
136+
137+ set flatpickrOptionsRange ( options : FlatpickrOptions ) {
138+ console . warn ( "flatpickrOptionsRange is deprecated, use flatpickrOptions and set the range to true instead" ) ;
139+ this . range = true ;
140+ options = this . flatpickrOptions ;
141+ }
142+ get flatpickrOptionsRange ( ) {
143+ console . warn ( "flatpickrOptionsRange is deprecated, use flatpickrOptions and set the range to true instead" ) ;
144+ return this . flatpickrOptions ;
145+ }
146+
123147 @Output ( ) valueChange : EventEmitter < any > = new EventEmitter ( ) ;
124148
125- flatpickrOptions : FlatpickrOptions = {
126- dateFormat : this . dateFormat ,
127- allowInput : true ,
128- onChange : ( selectedValue : any ) => { this . doSelect ( selectedValue ) ; } ,
129- onOpen : ( ) => { this . updateClassNames ( ) ; } ,
130- value : this . value
149+ protected _flatpickrOptions : FlatpickrOptions = {
150+ allowInput : true
131151 } ;
132152
133- flatpickrOptionsRange : FlatpickrOptions = {
153+ protected flatpickrBaseOptions : FlatpickrOptions = {
134154 dateFormat : this . dateFormat ,
135- "plugins" : [ rangePlugin ( { input : "#" + this . id + "-rangeInput" } ) ] ,
136- allowInput : true ,
155+ plugins : this . plugins ,
137156 onChange : ( selectedValue : any ) => { this . doSelect ( selectedValue ) ; } ,
138157 onOpen : ( ) => { this . updateClassNames ( ) ; } ,
139158 value : this . value
0 commit comments