Files
decky-frontend-lib/src/components/Dropdown.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

import { ReactNode, FC } from 'react';
2022-06-08 09:57:50 +02:00
import { CommonUIModule } from '../webpack';
import { ItemProps } from './Item';
2024-06-26 22:28:58 -04:00
import { createPropListRegex } from '../utils';
import type { ContextMenuPositionOptions } from './Menu';
2022-06-08 09:57:50 +02:00
export interface SingleDropdownOption {
data: any;
label: ReactNode;
2022-06-08 09:57:50 +02:00
options?: never;
}
export interface MultiDropdownOption {
label: ReactNode;
2022-06-08 09:57:50 +02:00
options: DropdownOption[];
data?: never;
}
export type DropdownOption = SingleDropdownOption | MultiDropdownOption;
export interface DropdownProps {
rgOptions: DropdownOption[];
selectedOption: any;
2022-06-08 09:57:50 +02:00
disabled?: boolean;
onMenuWillOpen?(showMenu: () => void): void;
onMenuOpened?(): void;
onChange?(data: SingleDropdownOption): void;
contextMenuPositionOptions?: ContextMenuPositionOptions;
2022-06-08 09:57:50 +02:00
menuLabel?: string;
strDefaultLabel?: string;
renderButtonValue?(element: ReactNode): ReactNode;
focusable?: boolean;
}
export const Dropdown = Object.values(CommonUIModule).find(
(mod: any) => mod?.prototype?.SetSelectedOption && mod?.prototype?.BuildMenu,
) as FC<DropdownProps>;
2022-06-08 09:57:50 +02:00
export interface DropdownItemProps extends DropdownProps, ItemProps {}
2022-06-08 09:57:50 +02:00
2024-06-26 22:28:58 -04:00
const dropdownItemRegex = createPropListRegex(["dropDownControlRef", "description"], false);
2022-06-08 09:57:50 +02:00
export const DropdownItem = Object.values(CommonUIModule).find((mod: any) =>
2024-06-26 22:28:58 -04:00
mod?.toString && dropdownItemRegex.test(mod.toString()),
) as FC<DropdownItemProps>;