From be38f956f108f7f7b16485bd12b54ab4023658c1 Mon Sep 17 00:00:00 2001 From: katebatura Date: Fri, 14 Jan 2022 12:05:25 +0300 Subject: [PATCH] feat(date-time picker): add dateTime input property --- .../datepicker/date-timepicker.component.ts | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/framework/theme/components/datepicker/date-timepicker.component.ts b/src/framework/theme/components/datepicker/date-timepicker.component.ts index 0001198baf..2e2f76782c 100644 --- a/src/framework/theme/components/datepicker/date-timepicker.component.ts +++ b/src/framework/theme/components/datepicker/date-timepicker.component.ts @@ -32,13 +32,24 @@ import { NB_DATE_SERVICE_OPTIONS } from './datepicker.directive'; template: '', changeDetection: ChangeDetectionStrategy.OnPush, }) -export class NbDateTimePickerComponent extends NbBasePickerComponent> - implements OnInit { - +export class NbDateTimePickerComponent + extends NbBasePickerComponent> + implements OnInit +{ protected pickerClass: Type> = NbCalendarWithTimeComponent; + /** + * Date with time which will be rendered as selected. + * */ + @Input() set dateTime(date: D) { + this.value = date; + if (this.format) { + this.onChange$.next(date); + } + } + get value(): any { - return this.picker ? this.picker.date : undefined; + return this.picker?.date ?? undefined; } set value(date: any) { if (!this.picker) { @@ -112,19 +123,25 @@ export class NbDateTimePickerComponent extends NbBasePickerComponent; } - constructor(@Inject(NB_DOCUMENT) document, - positionBuilder: NbPositionBuilderService, - triggerStrategyBuilder: NbTriggerStrategyBuilderService, - overlay: NbOverlayService, - cfr: ComponentFactoryResolver, - dateService: NbDateService, - @Optional() @Inject(NB_DATE_SERVICE_OPTIONS) dateServiceOptions, - protected calendarWithTimeModelService: NbCalendarTimeModelService) { + constructor( + @Inject(NB_DOCUMENT) document, + positionBuilder: NbPositionBuilderService, + triggerStrategyBuilder: NbTriggerStrategyBuilderService, + overlay: NbOverlayService, + cfr: ComponentFactoryResolver, + dateService: NbDateService, + @Optional() @Inject(NB_DATE_SERVICE_OPTIONS) dateServiceOptions, + protected calendarWithTimeModelService: NbCalendarTimeModelService, + ) { super(document, positionBuilder, triggerStrategyBuilder, overlay, cfr, dateService, dateServiceOptions); } ngOnInit() { + super.ngOnInit(); this.format = this.format || this.buildTimeFormat(); + if (this.queue) { + this.dateTime = this.queue; + } } protected patchWithInputs() { @@ -140,8 +157,9 @@ export class NbDateTimePickerComponent extends NbBasePickerComponent extends NbBasePickerComponent