|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { ReactWrapperComponent } from '@angular-react/core'; |
| 5 | +import { |
| 6 | + ChangeDetectionStrategy, |
| 7 | + ChangeDetectorRef, |
| 8 | + Component, |
| 9 | + ElementRef, |
| 10 | + EventEmitter, |
| 11 | + Input, |
| 12 | + Output, |
| 13 | + Renderer2, |
| 14 | + ViewChild, |
| 15 | +} from '@angular/core'; |
| 16 | +import { ICalendarProps } from 'office-ui-fabric-react/lib/Calendar'; |
| 17 | + |
| 18 | +@Component({ |
| 19 | + selector: 'fab-calendar', |
| 20 | + exportAs: 'fabCalendar', |
| 21 | + template: ` |
| 22 | + <Calendar |
| 23 | + #reactNode |
| 24 | + [componentRef]="componentRef" |
| 25 | + [className]="className" |
| 26 | + [isMonthPickerVisible]="isMonthPickerVisible" |
| 27 | + [isDayPickerVisible]="isDayPickerVisible" |
| 28 | + [showMonthPickerAsOverlay]="showMonthPickerAsOverlay" |
| 29 | + [today]="today" |
| 30 | + [value]="value" |
| 31 | + [firstDayOfWeek]="firstDayOfWeek" |
| 32 | + [dateRangeType]="dateRangeType" |
| 33 | + [autoNavigateOnSelection]="autoNavigateOnSelection" |
| 34 | + [showGoToToday]="showGoToToday" |
| 35 | + [strings]="strings" |
| 36 | + [highlightCurrentMonth]="highlightCurrentMonth" |
| 37 | + [highlightSelectedMonth]="highlightSelectedMonth" |
| 38 | + [navigationIcons]="navigationIcons" |
| 39 | + [showWeekNumbers]="showWeekNumbers" |
| 40 | + [firstWeekOfYear]="firstWeekOfYear" |
| 41 | + [dateTimeFormatter]="dateTimeFormatter" |
| 42 | + [minDate]="minDate" |
| 43 | + [maxDate]="maxDate" |
| 44 | + [showSixWeeksByDefault]="showSixWeeksByDefault" |
| 45 | + [workWeekDays]="workWeekDays" |
| 46 | + [selectDateOnClick]="selectDateOnClick" |
| 47 | + [showCloseButton]="showCloseButton" |
| 48 | + [allFocusable]="allFocusable" |
| 49 | + [SelectDate]="onSelectDateHandler" |
| 50 | + [Dismiss]="onDismissHandler"> |
| 51 | + </Calendar> |
| 52 | + `, |
| 53 | + styles: ['react-renderer'], |
| 54 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 55 | +}) |
| 56 | +export class FabCalendarComponent extends ReactWrapperComponent<ICalendarProps> { |
| 57 | + @ViewChild('reactNode') |
| 58 | + protected reactNodeRef: ElementRef; |
| 59 | + |
| 60 | + @Input() |
| 61 | + componentRef?: ICalendarProps['componentRef']; |
| 62 | + @Input() |
| 63 | + className?: ICalendarProps['className']; |
| 64 | + @Input() |
| 65 | + isMonthPickerVisible?: ICalendarProps['isMonthPickerVisible']; |
| 66 | + @Input() |
| 67 | + isDayPickerVisible?: ICalendarProps['isDayPickerVisible']; |
| 68 | + @Input() |
| 69 | + showMonthPickerAsOverlay?: ICalendarProps['showMonthPickerAsOverlay']; |
| 70 | + @Input() |
| 71 | + today?: ICalendarProps['today']; |
| 72 | + @Input() |
| 73 | + value?: ICalendarProps['value']; |
| 74 | + @Input() |
| 75 | + firstDayOfWeek?: ICalendarProps['firstDayOfWeek']; |
| 76 | + @Input() |
| 77 | + dateRangeType?: ICalendarProps['dateRangeType']; |
| 78 | + @Input() |
| 79 | + autoNavigateOnSelection?: ICalendarProps['autoNavigateOnSelection']; |
| 80 | + @Input() |
| 81 | + showGoToToday?: ICalendarProps['showGoToToday']; |
| 82 | + @Input() |
| 83 | + strings: ICalendarProps['strings']; |
| 84 | + @Input() |
| 85 | + highlightCurrentMonth?: ICalendarProps['highlightCurrentMonth']; |
| 86 | + @Input() |
| 87 | + highlightSelectedMonth?: ICalendarProps['highlightSelectedMonth']; |
| 88 | + @Input() |
| 89 | + navigationIcons?: ICalendarProps['navigationIcons']; |
| 90 | + @Input() |
| 91 | + showWeekNumbers?: ICalendarProps['showWeekNumbers']; |
| 92 | + @Input() |
| 93 | + firstWeekOfYear?: ICalendarProps['firstWeekOfYear']; |
| 94 | + @Input() |
| 95 | + dateTimeFormatter?: ICalendarProps['dateTimeFormatter']; |
| 96 | + @Input() |
| 97 | + minDate?: ICalendarProps['minDate']; |
| 98 | + @Input() |
| 99 | + maxDate?: ICalendarProps['maxDate']; |
| 100 | + @Input() |
| 101 | + showSixWeeksByDefault?: ICalendarProps['showSixWeeksByDefault']; |
| 102 | + @Input() |
| 103 | + workWeekDays?: ICalendarProps['workWeekDays']; |
| 104 | + @Input() |
| 105 | + selectDateOnClick?: ICalendarProps['selectDateOnClick']; |
| 106 | + @Input() |
| 107 | + showCloseButton?: ICalendarProps['showCloseButton']; |
| 108 | + @Input() |
| 109 | + allFocusable?: ICalendarProps['allFocusable']; |
| 110 | + |
| 111 | + @Output() |
| 112 | + readonly onSelectDate = new EventEmitter<{ date: Date; selectedDateRangeArray?: Date[] }>(); |
| 113 | + @Output() |
| 114 | + readonly onDismiss = new EventEmitter<void>(); |
| 115 | + |
| 116 | + constructor(elementRef: ElementRef, changeDetectorRef: ChangeDetectorRef, renderer: Renderer2) { |
| 117 | + super(elementRef, changeDetectorRef, renderer); |
| 118 | + |
| 119 | + // coming from React context - we need to bind to this so we can access the Angular Component properties |
| 120 | + this.onSelectDateHandler = this.onSelectDateHandler.bind(this); |
| 121 | + this.onDismissHandler = this.onDismissHandler.bind(this); |
| 122 | + } |
| 123 | + |
| 124 | + onSelectDateHandler(date: Date, selectedDateRangeArray?: Date[]) { |
| 125 | + this.onSelectDate.emit({ |
| 126 | + date, |
| 127 | + selectedDateRangeArray, |
| 128 | + }); |
| 129 | + } |
| 130 | + |
| 131 | + onDismissHandler() { |
| 132 | + this.onDismiss.emit(); |
| 133 | + } |
| 134 | +} |
0 commit comments