UNPKG

@wix/design-system

Version:

@wix/design-system

149 lines 7.38 kB
import React, { KeyboardEvent, PureComponent, RefObject } from 'react'; import { DATA_OPTION } from './DataAttr'; import { listItemSectionBuilder } from '../ListItemSection'; import { listItemSelectBuilder } from '../ListItemSelect'; import { listItemActionBuilder } from '../ListItemAction'; import { WithOverlayScrollbarProps } from './withOverlayScrollbar'; import { DropdownLayoutBuilderOption, DropdownLayoutDividerOption, DropdownLayoutOption, DropdownLayoutProps, DropdownLayoutValueOption } from './DropdownLayout.types'; type FocusedItemId = string | number | null; type SelectedOption = HTMLDivElement | null; type OnClickEvent = { id: FocusedItemId; }; type State = { hovered: number; selectedId: DropdownLayoutProps['selectedId']; scrollElement: HTMLElement | null; focusedItemId: FocusedItemId; }; type DropdownLayoutChildren = { [key: string | number]: { focus?: () => void; wrappedComponentRef?: { innerComponentRef: { focus: () => void; }; }; } | null; }; type ConvertedCustomOption = Pick<DropdownLayoutValueOption, 'id' | 'disabled' | 'disabledDescription' | 'overrideStyle' | 'overrideOptionStyle'> & Pick<DropdownLayoutBuilderOption, 'value'>; type ConvertedOption = ConvertedCustomOption | DropdownLayoutBuilderOption | undefined; export declare class DropdownLayout extends PureComponent<DropdownLayoutProps & WithOverlayScrollbarProps, State> { static defaultProps: DropdownLayoutProps; static displayName: string; static NONE_SELECTED_ID: -1; constructor(props: DropdownLayoutProps); setScrollElement: (node: HTMLElement | null) => void; containerRef: React.RefObject<HTMLDivElement>; optionsRef: RefObject<HTMLDivElement>; loadedWithUndefinedOptions: boolean; _boundEvents: string[]; focusableItemsIdsList: (string | number)[]; savedOnClicks: { id?: string | number; onClick: (e: OnClickEvent) => void; }[]; children: DropdownLayoutChildren; selectedOption: SelectedOption; componentDidMount(): void; componentWillUnmount(): void; componentDidUpdate(prevProps: DropdownLayoutProps): void; UNSAFE_componentWillReceiveProps(nextProps: DropdownLayoutProps): void; _getOptionElementId(optionIndex: number): string; _isDialogMode: () => boolean; _focusFirstOption(): void; /** @deprecated */ _checkIfEventOnElements(e: any, elem: any): boolean; /** @deprecated */ _onMouseEventsHandler: (e: any) => void; /** @deprecated */ _renderTopArrow(): React.JSX.Element | null; _convertOptionToListItemSectionBuilder({ option, idx, }: { option: DropdownLayoutDividerOption | DropdownLayoutValueOption; idx: number; }): ReturnType<typeof listItemSectionBuilder> | undefined; _convertOptionToListItemActionBuilder({ option, idx, }: { option: DropdownLayoutValueOption; idx: number; }): ReturnType<typeof listItemActionBuilder>; _isControlled(): boolean; _focusOnSelectedOption(): void; _setSelectedOptionNode(optionNode: HTMLDivElement | null, option: DropdownLayoutBuilderOption | ConvertedCustomOption): void; _onClickOutside: (event: TouchEvent | MouseEvent) => void; _markOption(index: number, options?: DropdownLayoutOption[]): void; _onSelect: (index: number, e: React.KeyboardEvent<Element> | React.MouseEvent<Element, MouseEvent>) => false | DropdownLayoutOption | undefined; _onActionClick: (e: OnClickEvent) => void; _saveOnClicks: () => void; _onOptionHoverStart: (index: number) => void; _onOptionHoverEnd: () => void; _onContainerMouseLeave: (e: React.MouseEvent<HTMLDivElement>) => void; _getMarkedIndex(): number; getActiveDescendentElementId(): string | undefined; _markNextStep(step: number): void; _focusOnOption: () => void; _scrollToOption(): void; _markOptionAtIndex: (markedIndex: number) => void; _scrollIntoViewByIndex: (index: number) => void; /** * Handle keydown events for the DropdownLayout, mostly for accessibility * * @param event - The keydown event triggered by React * @returns Whether the event was handled by the component */ _onSelectListKeyDown: (event: KeyboardEvent<Element>) => boolean | DropdownLayoutOption | undefined; _focus: (focusedItemId: FocusedItemId, e?: React.SyntheticEvent) => void; _handleActionListNavigation: (event: React.KeyboardEvent, id: string | number) => void; _onActionListKeyDown: (event: React.KeyboardEvent<HTMLDivElement>, id: string | number) => void; _onClose: () => void; _isEventFromFixedRegion(event: React.KeyboardEvent | KeyboardEvent): boolean; _isArrowNavigationDisabled(event: React.KeyboardEvent | KeyboardEvent): boolean; _renderNode(node: React.ReactNode, region?: 'header' | 'footer'): React.JSX.Element | null; _onFixedRegionFocus: () => void; _wrapWithInfiniteScroll: (scrollableElement: React.ReactNode) => React.JSX.Element; /** for testing purposes only */ _getDataAttributes: () => Partial<{ 'data-hook': string; "data-shown": boolean | undefined; "data-selected-option-id": string | number | undefined; "data-direction": string; }>; _convertCustomOptionToBuilder({ option, }: { option: DropdownLayoutValueOption; }): ConvertedCustomOption | undefined; _convertOptionToListItemSelectBuilder({ option, }: { option: DropdownLayoutValueOption; }): ReturnType<typeof listItemSelectBuilder>; _isBuilderOption(option: DropdownLayoutOption): option is DropdownLayoutBuilderOption; _isCustomOption(option: DropdownLayoutValueOption): boolean | undefined; _isActionOption(option: DropdownLayoutOption): option is DropdownLayoutValueOption; _isItemSection(option: DropdownLayoutOption): option is DropdownLayoutDividerOption | DropdownLayoutValueOption; _isDivider(opt: DropdownLayoutOption): opt is DropdownLayoutDividerOption; _convertOptionToBuilder(option: DropdownLayoutOption, idx: number): ConvertedOption; _renderOption({ option, idx, }: { option: DropdownLayoutOption; idx: number; }): React.ReactElement | undefined; _getItemDataAttr: ({ hovered, selected, disabled, }: { hovered: boolean; selected: boolean; disabled?: boolean; }) => Partial<{ [DATA_OPTION.DISABLED]: boolean | undefined; [DATA_OPTION.SELECTED]: boolean | undefined; [DATA_OPTION.HOVERED]: boolean; [DATA_OPTION.SIZE]: import("./DropdownLayout.types").DropdownLayoutItemHeight | undefined; }>; _renderOptionContent({ option, idx, hasLink, }: { option: ConvertedOption; idx: number; hasLink: boolean; }): React.ReactElement | undefined; _markOptionByProperty(props: DropdownLayoutProps): void; _findIndex(arr: DropdownLayoutOption[], predicate: (item: DropdownLayoutOption) => boolean): number; _isSelectableOption: (option: DropdownLayoutOption) => boolean; _renderOptions(): (React.ReactElement | undefined)[]; render(): React.JSX.Element; } declare const _default: React.ForwardRefExoticComponent<Omit<DropdownLayoutProps & WithOverlayScrollbarProps, "ref"> & React.RefAttributes<DropdownLayout>>; export default _default; //# sourceMappingURL=DropdownLayout.d.ts.map