UNPKG

1.88 kBTypeScriptView Raw
1import { ComponentType, ReactNode, MouseEventHandler, ReactElement } from 'react';
2import { CSSObject } from '@emotion/serialize';
3
4import { colors, spacing } from '../theme';
5import { CommonProps, InnerRef, OptionTypeBase, GroupTypeBase } from '../types';
6
7interface State {
8 /** Whether the option is disabled. */
9 isDisabled: boolean;
10 /** Whether the option is focused. */
11 isFocused: boolean;
12 /** Whether the option is selected. */
13 isSelected: boolean;
14}
15interface InnerProps {
16 id: string;
17 key: string;
18 onClick: MouseEventHandler<HTMLDivElement>;
19 onMouseMove: MouseEventHandler<HTMLDivElement>;
20 onMouseOver: MouseEventHandler<HTMLDivElement>;
21 tabIndex: number;
22}
23export type OptionProps<
24 OptionType extends OptionTypeBase,
25 IsMulti extends boolean,
26 GroupType extends GroupTypeBase<OptionType> = GroupTypeBase<OptionType>
27> = CommonProps<OptionType, IsMulti, GroupType> &
28 State & {
29 /** The children to be rendered. */
30 children: ReactNode;
31 /** Inner ref to DOM Node */
32 innerRef: InnerRef;
33 /** props passed to the wrapping element for the group. */
34 innerProps: InnerProps;
35 /* Text to be displayed representing the option. */
36 label: string;
37 /* Type is used by the menu to determine whether this is an option or a group.
38 In the case of option this is always `option`. */
39 type: 'option';
40 /* The data of the selected option. */
41 data: any;
42 };
43
44export function optionCSS(state: State): CSSObject;
45
46declare function Option<
47 OptionType extends OptionTypeBase,
48 IsMulti extends boolean,
49 GroupType extends GroupTypeBase<OptionType> = GroupTypeBase<OptionType>
50 // tslint:disable-next-line:no-unnecessary-generics
51>(props: OptionProps<OptionType, IsMulti, GroupType>): ReactElement;
52
53export default Option;