|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { InputRendererOptions, JsxRenderFunc, ReactWrapperComponent } from '@angular-react/core'; |
| 5 | +import { |
| 6 | + ChangeDetectionStrategy, |
| 7 | + ChangeDetectorRef, |
| 8 | + Component, |
| 9 | + ElementRef, |
| 10 | + Input, |
| 11 | + OnInit, |
| 12 | + Renderer2, |
| 13 | + ViewChild, |
| 14 | + Output, |
| 15 | + EventEmitter, |
| 16 | +} from '@angular/core'; |
| 17 | +import { IDropdownProps, IDropdownOption, IDropdown } from 'office-ui-fabric-react/lib/Dropdown'; |
| 18 | +import { ISelectableDroppableTextProps, ISelectableOption } from 'office-ui-fabric-react'; |
| 19 | + |
| 20 | +@Component({ |
| 21 | + selector: 'fab-dropdown', |
| 22 | + exportAs: 'fabDropdown', |
| 23 | + template: ` |
| 24 | + <Dropdown |
| 25 | + #reactNode |
| 26 | + [componentRef]="componentRef" |
| 27 | + [label]="label" |
| 28 | + [ariaLabel]="ariaLabel" |
| 29 | + [id]="id" |
| 30 | + [className]="className" |
| 31 | + [defaultSelectedKey]="defaultSelectedKey" |
| 32 | + [selectedKey]="selectedKey" |
| 33 | + [disabled]="disabled" |
| 34 | + [required]="required" |
| 35 | + [calloutProps]="calloutProps" |
| 36 | + [panelProps]="panelProps" |
| 37 | + [errorMessage]="errorMessage" |
| 38 | + [placeholder]="placeholder" |
| 39 | + [options]="options" |
| 40 | + [dropdownWidth]="dropdownWidth" |
| 41 | + [responsiveMode]="responsiveMode" |
| 42 | + [multiSelect]="multiSelect" |
| 43 | + [defaultSelectedKeys]="defaultSelectedKeys" |
| 44 | + [selectedKeys]="selectedKeys" |
| 45 | + [multiSelectDelimiter]="multiSelectDelimiter" |
| 46 | + [notifyOnReselect]="notifyOnReselect" |
| 47 | + [keytipProps]="keytipProps" |
| 48 | + [theme]="theme" |
| 49 | + [styles]="styles" |
| 50 | + [RenderContainer]="renderContainer && onRenderContainer" |
| 51 | + [RenderList]="renderList && onRenderList" |
| 52 | + [RenderItem]="renderItem && onRenderItem" |
| 53 | + [RenderOption]="renderOption && onRenderOption" |
| 54 | + [RenderPlaceHolder]="renderPlaceHolder && onRenderPlaceHolder" |
| 55 | + [RenderTitle]="renderTitle && onRenderTitle" |
| 56 | + [RenderCaretDown]="renderCaretDown && onRenderCaretDown" |
| 57 | + [Change]="onChangeHandler" |
| 58 | + [Dismiss]="onDismissHandler" |
| 59 | + ></Dropdown> |
| 60 | + `, |
| 61 | + styles: ['react-renderer'], |
| 62 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 63 | +}) |
| 64 | +export class FabDropdownComponent extends ReactWrapperComponent<IDropdownProps> implements OnInit { |
| 65 | + @ViewChild('reactNode') protected reactNodeRef: ElementRef; |
| 66 | + |
| 67 | + @Input() componentRef?: IDropdownProps['componentRef']; |
| 68 | + @Input() label?: IDropdownProps['label']; |
| 69 | + @Input() ariaLabel?: IDropdownProps['ariaLabel']; |
| 70 | + @Input() id?: IDropdownProps['id']; |
| 71 | + @Input() className?: IDropdownProps['className']; |
| 72 | + @Input() defaultSelectedKey?: IDropdownProps['defaultSelectedKey']; |
| 73 | + @Input() selectedKey?: IDropdownProps['selectedKey']; |
| 74 | + @Input() disabled?: IDropdownProps['disabled']; |
| 75 | + @Input() required?: IDropdownProps['required']; |
| 76 | + @Input() calloutProps?: IDropdownProps['calloutProps']; |
| 77 | + @Input() panelProps?: IDropdownProps['panelProps']; |
| 78 | + @Input() errorMessage?: IDropdownProps['errorMessage']; |
| 79 | + |
| 80 | + @Input() placeholder: IDropdownProps['placeholder']; |
| 81 | + @Input() options: IDropdownProps['options']; |
| 82 | + @Input() dropdownWidth?: IDropdownProps['dropdownWidth']; |
| 83 | + @Input() responsiveMode?: IDropdownProps['responsiveMode']; |
| 84 | + @Input() multiSelect?: IDropdownProps['multiSelect']; |
| 85 | + @Input() defaultSelectedKeys?: IDropdownProps['defaultSelectedKeys']; |
| 86 | + @Input() selectedKeys?: IDropdownProps['selectedKeys']; |
| 87 | + @Input() multiSelectDelimiter?: IDropdownProps['multiSelectDelimiter']; |
| 88 | + @Input() notifyOnReselect?: IDropdownProps['notifyOnReselect']; |
| 89 | + @Input() keytipProps?: IDropdownProps['keytipProps']; |
| 90 | + @Input() theme?: IDropdownProps['theme']; |
| 91 | + @Input() styles?: IDropdownProps['styles']; |
| 92 | + |
| 93 | + @Input() renderContainer?: InputRendererOptions<ISelectableDroppableTextProps<IDropdown>>; |
| 94 | + @Input() renderList?: InputRendererOptions<ISelectableDroppableTextProps<IDropdown>>; |
| 95 | + @Input() renderItem?: InputRendererOptions<ISelectableOption>; |
| 96 | + @Input() renderOption?: InputRendererOptions<ISelectableOption>; |
| 97 | + @Input() renderPlaceHolder?: InputRendererOptions<IDropdownProps>; |
| 98 | + @Input() renderTitle?: InputRendererOptions<IDropdownOption | IDropdownOption[]>; |
| 99 | + @Input() renderCaretDown?: InputRendererOptions<IDropdownProps>; |
| 100 | + |
| 101 | + @Output() readonly onChange = new EventEmitter<{ event: Event; option?: IDropdownOption; index?: number }>(); |
| 102 | + @Output() readonly onDismiss = new EventEmitter<void>(); |
| 103 | + |
| 104 | + onRenderContainer: ( |
| 105 | + props?: ISelectableDroppableTextProps<IDropdown, IDropdown>, |
| 106 | + defaultRender?: JsxRenderFunc<ISelectableDroppableTextProps<IDropdown, IDropdown>> |
| 107 | + ) => JSX.Element; |
| 108 | + onRenderList: ( |
| 109 | + props?: ISelectableDroppableTextProps<IDropdown, IDropdown>, |
| 110 | + defaultRender?: JsxRenderFunc<ISelectableDroppableTextProps<IDropdown, IDropdown>> |
| 111 | + ) => JSX.Element; |
| 112 | + onRenderItem: (props?: ISelectableOption, defaultRender?: JsxRenderFunc<ISelectableOption>) => JSX.Element; |
| 113 | + onRenderOption: (props?: ISelectableOption, defaultRender?: JsxRenderFunc<ISelectableOption>) => JSX.Element; |
| 114 | + onRenderPlaceHolder: (props?: IDropdownProps, defaultRender?: JsxRenderFunc<IDropdownProps>) => JSX.Element; |
| 115 | + onRenderTitle: ( |
| 116 | + props?: IDropdownOption | IDropdownOption[], |
| 117 | + defaultRender?: JsxRenderFunc<IDropdownOption | IDropdownOption[]> |
| 118 | + ) => JSX.Element; |
| 119 | + onRenderCaretDown: (props?: IDropdownProps, defaultRender?: JsxRenderFunc<IDropdownProps>) => JSX.Element; |
| 120 | + |
| 121 | + constructor(elementRef: ElementRef, changeDetectorRef: ChangeDetectorRef, renderer: Renderer2) { |
| 122 | + super(elementRef, changeDetectorRef, renderer, { setHostDisplay: true }); |
| 123 | + |
| 124 | + this.onChangeHandler = this.onChangeHandler.bind(this); |
| 125 | + this.onDismissHandler = this.onDismissHandler.bind(this); |
| 126 | + } |
| 127 | + |
| 128 | + ngOnInit() { |
| 129 | + this.onRenderContainer = this.createRenderPropHandler(this.renderContainer); |
| 130 | + this.onRenderList = this.createRenderPropHandler(this.renderList); |
| 131 | + this.onRenderItem = this.createRenderPropHandler(this.renderItem); |
| 132 | + this.onRenderOption = this.createRenderPropHandler(this.renderOption); |
| 133 | + this.onRenderPlaceHolder = this.createRenderPropHandler(this.renderPlaceHolder); |
| 134 | + this.onRenderTitle = this.createRenderPropHandler(this.renderTitle); |
| 135 | + this.onRenderCaretDown = this.createRenderPropHandler(this.renderCaretDown); |
| 136 | + } |
| 137 | + |
| 138 | + onChangeHandler(event: React.FormEvent<HTMLDivElement>, option?: IDropdownOption, index?: number) { |
| 139 | + this.onChange.emit({ |
| 140 | + event: event && event.nativeEvent, |
| 141 | + option, |
| 142 | + index, |
| 143 | + }); |
| 144 | + } |
| 145 | + |
| 146 | + onDismissHandler() { |
| 147 | + this.onDismiss.emit(); |
| 148 | + } |
| 149 | +} |
0 commit comments