matrix-react-sdk
Version:
SDK for matrix.org using React
40 lines (39 loc) • 1.78 kB
TypeScript
import { FunctionComponent, Key, PropsWithChildren, ReactNode } from "react";
import { ButtonEvent } from "../views/elements/AccessibleButton";
export type GenericDropdownMenuOption<T> = {
key: T;
label: ReactNode;
description?: ReactNode;
adornment?: ReactNode;
};
export type GenericDropdownMenuGroup<T> = GenericDropdownMenuOption<T> & {
options: GenericDropdownMenuOption<T>[];
};
export type GenericDropdownMenuItem<T> = GenericDropdownMenuGroup<T> | GenericDropdownMenuOption<T>;
export declare function GenericDropdownMenuOption<T extends Key>({ label, description, onClick, isSelected, adornment, }: GenericDropdownMenuOption<T> & {
onClick: (ev: ButtonEvent) => void;
isSelected: boolean;
}): JSX.Element;
export declare function GenericDropdownMenuGroup<T extends Key>({ label, description, adornment, children, }: PropsWithChildren<GenericDropdownMenuOption<T>>): JSX.Element;
type WithKeyFunction<T> = T extends Key ? {
toKey?: (key: T) => Key;
} : {
toKey: (key: T) => Key;
};
export interface AdditionalOptionsProps {
menuDisplayed: boolean;
closeMenu: () => void;
openMenu: () => void;
}
type IProps<T> = WithKeyFunction<T> & {
value: T;
options: readonly GenericDropdownMenuOption<T>[] | readonly GenericDropdownMenuGroup<T>[];
onChange: (option: T) => void;
selectedLabel: (option: GenericDropdownMenuItem<T> | null | undefined) => ReactNode;
onOpen?: (ev: ButtonEvent) => void;
onClose?: (ev: ButtonEvent) => void;
className?: string;
AdditionalOptions?: FunctionComponent<AdditionalOptionsProps>;
};
export declare function GenericDropdownMenu<T>({ value, onChange, options, selectedLabel, onOpen, onClose, toKey, className, AdditionalOptions, }: IProps<T>): JSX.Element;
export {};