|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { ReactWrapperComponent } from '@angular-react/core'; |
| 5 | +import { INavProps, INavLink, INav } from 'office-ui-fabric-react'; |
| 6 | +import { |
| 7 | + Component, |
| 8 | + ChangeDetectionStrategy, |
| 9 | + Input, |
| 10 | + ViewChild, |
| 11 | + ElementRef, |
| 12 | + ChangeDetectorRef, |
| 13 | + Renderer2, |
| 14 | + Output, |
| 15 | + EventEmitter, |
| 16 | +} from '@angular/core'; |
| 17 | + |
| 18 | +@Component({ |
| 19 | + selector: 'fab-nav', |
| 20 | + exportAs: 'fabNav', |
| 21 | + template: ` |
| 22 | + <Nav |
| 23 | + #reactNode |
| 24 | + [groups]="groups" |
| 25 | + [LinkClick]="onLinkClickHandler" |
| 26 | + [selectedKey]="selectedKey" |
| 27 | + [expandButtonAriaLabel]="expandButtonAriaLabel" |
| 28 | + [expandedStateText]="expandedStateText" |
| 29 | + [collapsedStateText]="collapsedStateText" |
| 30 | + [LinkExpandClick]="onLinkExpandClickHandler" |
| 31 | + [isOnTop]="isOnTop" |
| 32 | + [initialSelectedKey]="initialSelectedKey" |
| 33 | + [ariaLabel]="ariaLabel" |
| 34 | + > |
| 35 | + </Nav> |
| 36 | + `, |
| 37 | + styles: ['react-renderer'], |
| 38 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 39 | +}) |
| 40 | +export class FabNavComponent extends ReactWrapperComponent<INavProps> { |
| 41 | + @ViewChild('reactNode') |
| 42 | + protected reactNodeRef: ElementRef; |
| 43 | + |
| 44 | + @Input() componentRef?: INavProps['componentRef']; |
| 45 | + @Input() groups: INavProps["groups"]; |
| 46 | + @Input() selectedKey: INavProps["selectedKey"]; |
| 47 | + @Input() expandedStateText: INavProps["expandedStateText"]; |
| 48 | + @Input() collapsedStateText: INavProps["collapsedStateText"]; |
| 49 | + @Input() isOnTop: INavProps["isOnTop"]; |
| 50 | + @Input() initialSelectedKey: INavProps["initialSelectedKey"]; |
| 51 | + @Input() ariaLabel: INavProps["ariaLabel"]; |
| 52 | + @Input() expandButtonAriaLabel: INavProps["expandButtonAriaLabel"]; |
| 53 | + |
| 54 | + |
| 55 | + @Output() readonly onLinkClick = new EventEmitter<{ |
| 56 | + event: Event, |
| 57 | + link: INavLink |
| 58 | + }>(); |
| 59 | + @Output() readonly onLinkExpandClick = new EventEmitter<{ |
| 60 | + event: Event, |
| 61 | + link: INavLink |
| 62 | + }>(); |
| 63 | + |
| 64 | + constructor(elementRef: ElementRef, changeDetectorRef: ChangeDetectorRef, renderer: Renderer2) { |
| 65 | + super(elementRef, changeDetectorRef, renderer); |
| 66 | + this.onLinkClickHandler = this.onLinkClickHandler.bind(this); |
| 67 | + this.onLinkExpandClickHandler = this.onLinkExpandClickHandler.bind(this); |
| 68 | + } |
| 69 | + |
| 70 | + onLinkClickHandler(event: React.MouseEvent<HTMLElement>, link?: INavLink): void { |
| 71 | + this.onLinkClick.emit({ |
| 72 | + event: event.nativeEvent, |
| 73 | + link: link |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + onLinkExpandClickHandler(event: React.MouseEvent<HTMLElement>, link?: INavLink): void { |
| 78 | + this.onLinkExpandClick.emit({ |
| 79 | + event: event.nativeEvent, |
| 80 | + link: link |
| 81 | + }); |
| 82 | + } |
| 83 | +} |
0 commit comments