From 41b9cabd6e4500850c846fdcf469191694f34db1 Mon Sep 17 00:00:00 2001 From: SAndreeva Date: Fri, 8 Feb 2019 15:51:28 +0200 Subject: [PATCH] feat(month picker): month picker POC #3126 --- .../src/lib/calendar/calendar.component.ts | 15 ++++ .../month-picker/month-picker.component.html | 28 +++++++ .../month-picker/month-picker.component.ts | 80 +++++++++++++++++++ .../calendar-views/calendar-views.sample.html | 17 +++- src/app/shared/shared.module.ts | 4 +- 5 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 projects/igniteui-angular/src/lib/month-picker/month-picker.component.html create mode 100644 projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts diff --git a/projects/igniteui-angular/src/lib/calendar/calendar.component.ts b/projects/igniteui-angular/src/lib/calendar/calendar.component.ts index 94dc174b024..72b6b45d0b5 100644 --- a/projects/igniteui-angular/src/lib/calendar/calendar.component.ts +++ b/projects/igniteui-angular/src/lib/calendar/calendar.component.ts @@ -207,6 +207,15 @@ export class IgxCalendarComponent extends IgxDaysViewComponent { get activeView(): CalendarView { return this._activeView; } + /** + * Sets the current active view of the calendar. + * ```typescript + * this.calendar.activeView = activeView; + * ``` + */ + set activeView(val: CalendarView) { + this._activeView = val; + } /** * @hidden @@ -214,6 +223,12 @@ export class IgxCalendarComponent extends IgxDaysViewComponent { get monthAction(): string { return this._monthAction; } + /** + * @hidden + */ + set monthAction(val: string) { + this._monthAction = val; + } /** * Gets the header template. * ```typescript diff --git a/projects/igniteui-angular/src/lib/month-picker/month-picker.component.html b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.html new file mode 100644 index 00000000000..fb55c69b84f --- /dev/null +++ b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.html @@ -0,0 +1,28 @@ +
+
+
+ keyboard_arrow_left +
+
+ + {{ formattedYear(viewDate) }} + +
+
+ keyboard_arrow_right +
+
+ + + +
+ + diff --git a/projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts new file mode 100644 index 00000000000..7ea5696d997 --- /dev/null +++ b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts @@ -0,0 +1,80 @@ +import { + Component, + NgModule +} from '@angular/core'; +import { IgxCalendarModule, CalendarView, IgxCalendarComponent } from '../calendar/index'; +import { IgxIconModule } from '../icon/index'; +import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'; +import { CommonModule } from '@angular/common'; +import { trigger, transition, useAnimation } from '@angular/animations'; +import { fadeIn, scaleInCenter, slideInLeft, slideInRight } from '../animations/main'; + +@Component({ + providers: [ + { + multi: true, + provide: NG_VALUE_ACCESSOR, + useExisting: IgxMonthPickerComponent + } + ], + animations: [ + trigger('animateView', [ + transition('void => 0', useAnimation(fadeIn)), + transition('void => *', useAnimation(scaleInCenter, { + params: { + duration: '.2s', + fromScale: .9 + } + })) + ]), + trigger('animateChange', [ + transition('* => prev', useAnimation(slideInLeft, { + params: { + fromPosition: 'translateX(-30%)' + } + })), + transition('* => next', useAnimation(slideInRight, { + params: { + fromPosition: 'translateX(30%)' + } + })) + ]) + ], + selector: 'igx-month-picker', + templateUrl: 'month-picker.component.html' +}) +export class IgxMonthPickerComponent extends IgxCalendarComponent implements ControlValueAccessor { + + public animateAction = ''; + + public previousYear() { + this.animateAction = 'prev'; + this.viewDate = this.calendarModel.timedelta(this.viewDate, 'year', -1); + } + + public nextYear() { + this.animateAction = 'next'; + this.viewDate = this.calendarModel.timedelta(this.viewDate, 'year', 1); + } + + public selectMonth(event: Date) { + this.viewDate = new Date(event.getFullYear(), event.getMonth(), event.getDate()); + this._onChangeCallback(this.viewDate); + } + + public selectYear(event: Date) { + this.viewDate = new Date(event.getFullYear(), event.getMonth(), event.getDate()); + this.activeView = CalendarView.DEFAULT; + + requestAnimationFrame(() => { + this.monthsView.el.nativeElement.focus(); + }); + } +} + +@NgModule({ + declarations: [IgxMonthPickerComponent], + exports: [IgxMonthPickerComponent], + imports: [CommonModule, IgxIconModule, IgxCalendarModule] +}) +export class IgxMonthPickerModule { } diff --git a/src/app/calendar-views/calendar-views.sample.html b/src/app/calendar-views/calendar-views.sample.html index 1b1aa176d86..c416065974b 100644 --- a/src/app/calendar-views/calendar-views.sample.html +++ b/src/app/calendar-views/calendar-views.sample.html @@ -5,18 +5,27 @@

Default Calendar

- + [selection]="'multi'">
- {{ date1 }} + {{ dates }} +
+
+

Month Picker

+ + + +
+ {{ date1 }} +
diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 1066fc16bb8..5969b529c85 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -37,6 +37,7 @@ import { IgxToggleModule, IgxTooltipModule } from 'igniteui-angular'; +import { IgxMonthPickerModule } from 'projects/igniteui-angular/src/lib/month-picker/month-picker.component'; const igniteModules = [ IgxAvatarModule, @@ -74,7 +75,8 @@ const igniteModules = [ IgxTimePickerModule, IgxToastModule, IgxToggleModule, - IgxTooltipModule + IgxTooltipModule, + IgxMonthPickerModule ]; @NgModule({