UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

128 lines (127 loc) • 5.82 kB
/// <reference types="react" /> import * as React from 'react'; import { BaseComponent, KeyCodes } from '../../Utilities'; import { IFocusZone } from '../../FocusZone'; import { Selection } from '../../utilities/selection/index'; import { Suggestions } from './Suggestions/Suggestions'; import { ISuggestionsProps } from './Suggestions/Suggestions.types'; import { SuggestionsController } from './Suggestions/SuggestionsController'; import { IBasePicker, IBasePickerProps } from './BasePicker.types'; import { IAutofill, Autofill } from '../Autofill/index'; import { IPickerItemProps } from './PickerItem.types'; import { IPersonaProps } from '../Persona/Persona.types'; export interface IBasePickerState { items?: any; suggestedDisplayValue?: string; moreSuggestionsAvailable?: boolean; isFocused?: boolean; isSearching?: boolean; isMostRecentlyUsedVisible?: boolean; suggestionsVisible?: boolean; suggestionsLoading?: boolean; isResultsFooterVisible?: boolean; selectedIndices?: number[]; } /** * Aria id's for internal picker components */ export declare type IPickerAriaIds = { /** * Aria id for selected suggestion alert component */ selectedSuggestionAlert: string; /** * Aria id for selected items container component */ selectedItems: string; /** * Aria id for suggestions list component */ suggestionList: string; }; export declare class BasePicker<T, P extends IBasePickerProps<T>> extends BaseComponent<P, IBasePickerState> implements IBasePicker<T> { protected selection: Selection; protected root: { (component: HTMLDivElement | null): void; current: HTMLDivElement | null; value: HTMLDivElement | null; }; protected input: { (component: IAutofill | null): void; current: IAutofill | null; value: IAutofill | null; }; protected focusZone: { (component: IFocusZone | null): void; current: IFocusZone | null; value: IFocusZone | null; }; protected suggestionElement: { (component: Suggestions<T> | null): void; current: Suggestions<T> | null; value: Suggestions<T> | null; }; protected suggestionStore: SuggestionsController<T>; protected SuggestionOfProperType: new (props: ISuggestionsProps<T>) => Suggestions<T>; protected currentPromise: PromiseLike<any> | undefined; protected _ariaMap: IPickerAriaIds; private _id; constructor(basePickerProps: P); readonly items: T[]; componentWillUpdate(newProps: P, newState: IBasePickerState): void; componentDidMount(): void; componentWillReceiveProps(newProps: P): void; componentWillUnmount(): void; focus(): void; focusInput(): void; dismissSuggestions: (ev?: any) => void; completeSuggestion(): void; refocusSuggestions: (keyCode: KeyCodes) => void; render(): JSX.Element; protected canAddItems(): boolean; protected renderSuggestions(): JSX.Element | null; protected renderItems(): JSX.Element[]; protected resetFocus(index?: number): void; protected onSuggestionSelect(): void; protected onSelectionChange(): void; protected updateSuggestions(suggestions: any[]): void; protected onEmptyInputFocus(): void; protected updateValue(updatedValue: string): void; protected updateSuggestionsList(suggestions: T[] | PromiseLike<T[]>, updatedValue?: string): void; protected resolveNewValue(updatedValue: string, suggestions: T[]): void; protected onChange(items?: T[]): void; protected onInputChange: (value: string) => void; protected onSuggestionClick: (ev: React.MouseEvent<HTMLElement>, item: any, index: number) => void; protected onSuggestionRemove: (ev: React.MouseEvent<HTMLElement>, item: IPersonaProps, index: number) => void; protected onInputFocus: (ev: React.FocusEvent<HTMLInputElement | Autofill>) => void; protected onInputBlur: (ev: React.FocusEvent<HTMLInputElement | Autofill>) => void; protected onKeyDown: (ev: React.KeyboardEvent<HTMLElement>) => void; protected onItemChange: (changedItem: T, index: number) => void; protected onGetMoreResults: () => void; protected addItemByIndex: (index: number) => void; protected addItem: (item: T) => void; protected removeItem: (item: IPickerItemProps<T>, focusNextItem?: boolean | undefined) => void; protected removeItems: (itemsToRemove: any[]) => void; protected onBackspace(ev: React.KeyboardEvent<HTMLElement>): void; protected _isFocusZoneInnerKeystroke: (ev: React.KeyboardEvent<HTMLElement>) => boolean; protected getActiveDescendant(): string | undefined; protected getSuggestionsAlert(): JSX.Element | undefined; /** * Takes in the current updated value and either resolves it with the new suggestions * or if updated value is undefined then it clears out currently suggested items */ private _updateAndResolveValue(updatedValue, newSuggestions); /** * Controls what happens whenever there is an action that impacts the selected items. * If selectedItems is provided as a property then this will act as a controlled component and it will not update it's own state. */ private _updateSelectedItems(items, focusIndex?); private _onSelectedItemsUpdated(items?, focusIndex?); private _onResolveSuggestions(updatedValue); private _onValidateInput(); private _getTextFromItem(item, currentValue?); } export declare class BasePickerListBelow<T, P extends IBasePickerProps<T>> extends BasePicker<T, P> { render(): JSX.Element; protected onBackspace(ev: React.KeyboardEvent<HTMLElement>): void; }