1 | import * as React from 'react';
|
2 | import {StyletronComponent} from 'styletron-react';
|
3 | import {Override} from '../overrides';
|
4 |
|
5 | export interface KEY_STRINGS {
|
6 | ArrowUp: 'ArrowUp';
|
7 | ArrowDown: 'ArrowDown';
|
8 | ArrowLeft: 'ArrowLeft';
|
9 | ArrowRight: 'ArrowRight';
|
10 | Enter: 'Enter';
|
11 | Space: ' ';
|
12 | Escape: 'Escape';
|
13 | Backspace: 'Backspace';
|
14 | }
|
15 | export interface STATE_CHANGE_TYPES {
|
16 | click: 'click';
|
17 | moveUp: 'moveUp';
|
18 | moveDown: 'moveDown';
|
19 | mouseEnter: 'mouseEnter';
|
20 | focus: 'focus';
|
21 | reset: 'reset';
|
22 | character: 'character';
|
23 | enter: 'enter';
|
24 | }
|
25 |
|
26 | export interface OPTION_LIST_SIZE {
|
27 | default: 'default';
|
28 | compact: 'compact';
|
29 | }
|
30 |
|
31 | export interface MenuOverrides {
|
32 | EmptyState?: Override<any>;
|
33 | List?: Override<any>;
|
34 | Option?: Override<any>;
|
35 | ListItem?: Override<any>;
|
36 | }
|
37 |
|
38 | export type BaseMenuPropsT = {
|
39 | renderAll?: boolean;
|
40 | };
|
41 |
|
42 | export interface MenuOverrides {
|
43 | EmptyState?: Override<any>;
|
44 | List?: Override<any>;
|
45 | Option?: Override<any>;
|
46 | ListItem?: Override<any>;
|
47 | OptgroupHeader?: Override<any>;
|
48 | }
|
49 |
|
50 | export interface MenuProps extends BaseMenuPropsT {
|
51 | size?: keyof OPTION_LIST_SIZE;
|
52 | overrides?: MenuOverrides;
|
53 | }
|
54 |
|
55 | export type ItemT = any;
|
56 | export type ArrayItemsT = ItemT[];
|
57 | export type GroupedItemsT = {
|
58 | __ungrouped: ArrayItemsT;
|
59 | [key: string]: ArrayItemsT;
|
60 | };
|
61 | export type ItemsT = ArrayItemsT | GroupedItemsT;
|
62 |
|
63 | export type StatefulMenuProps = StatefulContainerProps & MenuProps;
|
64 | export class StatefulMenu extends React.PureComponent<StatefulMenuProps> {}
|
65 |
|
66 | export interface RenderItemProps {
|
67 | disabled?: boolean;
|
68 | ref?: React.Ref<any>;
|
69 | id?: string;
|
70 | isFocused?: boolean;
|
71 | isHighlighted?: boolean;
|
72 | resetMenu?: () => any;
|
73 | }
|
74 |
|
75 | export type OnItemSelect = (args: {
|
76 | item: any;
|
77 | event?: React.SyntheticEvent<HTMLElement> | KeyboardEvent;
|
78 | }) => any;
|
79 |
|
80 | export type StateReducer = (
|
81 | changeType: STATE_CHANGE_TYPES[keyof STATE_CHANGE_TYPES],
|
82 | changes: StatefulContainerState,
|
83 | currentState: StatefulContainerState,
|
84 | ) => StatefulContainerState;
|
85 |
|
86 | export type GetRequiredItemProps = (
|
87 | item: any,
|
88 | index: number,
|
89 | ) => RenderItemProps;
|
90 |
|
91 | export type RenderProps = StatefulContainerState & {
|
92 | items: ItemsT;
|
93 | getRequiredItemProps: GetRequiredItemProps;
|
94 | };
|
95 |
|
96 | export interface StatefulContainerProps {
|
97 | items: ItemsT;
|
98 | initialState?: StatefulContainerState;
|
99 | stateReducer?: StateReducer;
|
100 | getRequiredItemProps?: GetRequiredItemProps;
|
101 | onActiveDescendantChange?: (id?: string) => void;
|
102 | onItemSelect?: OnItemSelect;
|
103 | rootRef?: React.Ref<any>;
|
104 | keyboardControlNode?: React.Ref<any>;
|
105 | typeAhead?: boolean;
|
106 | children?: (args: RenderProps) => React.ReactNode;
|
107 | addMenuToNesting?: (ref: React.Ref<HTMLElement>) => void;
|
108 | removeMenuFromNesting?: (ref: React.Ref<HTMLElement>) => void;
|
109 | getParentMenu?: (ref: React.Ref<HTMLElement>) => void;
|
110 | getChildMenu?: (ref: React.Ref<HTMLElement>) => void;
|
111 | }
|
112 | export interface StatefulContainerState {
|
113 | activedescendantId?: string;
|
114 | highlightedIndex: number;
|
115 | isFocused: boolean;
|
116 | }
|
117 | export class StatefulContainer extends React.Component<
|
118 | StatefulContainerProps,
|
119 | StatefulContainerState
|
120 | > {}
|
121 |
|
122 | export interface OptionListProps extends BaseMenuPropsT {
|
123 | item: any;
|
124 | getItemLabel: (item: any) => React.ReactNode;
|
125 | getChildMenu?: (item: any) => React.ReactNode;
|
126 | onMouseEnter?: (event: MouseEvent) => any;
|
127 | size?: OPTION_LIST_SIZE[keyof OPTION_LIST_SIZE];
|
128 | overrides?: {
|
129 | ListItem?: Override<any>;
|
130 | ChildMenuPopover?: Override<any>;
|
131 | };
|
132 | renderHrefAsAnchor?: boolean;
|
133 | resetMenu?: () => void;
|
134 | $isHighlighted?: boolean;
|
135 | $isFocused?: boolean;
|
136 | }
|
137 | export const OptionList: React.FC<OptionListProps>;
|
138 |
|
139 | export interface OptionProfileProps extends BaseMenuPropsT {
|
140 | item: any;
|
141 | getChildMenu?: (item: any) => React.ReactNode;
|
142 | getProfileItemLabels: (
|
143 | item: any,
|
144 | ) => {title?: string; subtitle?: string; body?: string};
|
145 | getProfileItemImg: (item: any) => string | React.ComponentType<any>;
|
146 | getProfileItemImgText: (item: any) => string;
|
147 | overrides?: {
|
148 | ListItemProfile?: Override<any>;
|
149 | ProfileImgContainer?: Override<any>;
|
150 | ProfileImg?: Override<any>;
|
151 | ProfileLabelsContainer?: Override<any>;
|
152 | ProfileTitle?: Override<any>;
|
153 | ProfileSubtitle?: Override<any>;
|
154 | ProfileBody?: Override<any>;
|
155 | ChildMenuPopover?: Override<any>;
|
156 | };
|
157 | resetMenu?: () => void;
|
158 | $isHighlighted?: boolean;
|
159 | }
|
160 | export const OptionProfile: React.FC<OptionProfileProps>;
|
161 |
|
162 | export interface SharedStatelessProps {
|
163 | activedescendantId?: string;
|
164 | getRequiredItemProps?: (item: any, index: number) => RenderItemProps;
|
165 | highlightedIndex?: number;
|
166 | items: ItemsT;
|
167 | isFocused?: boolean;
|
168 | noResultsMsg?: React.ReactNode;
|
169 | onBlur?: (event: React.FocusEvent<HTMLElement>) => any;
|
170 | onFocus?: (event: React.FocusEvent<HTMLElement>) => any;
|
171 | rootRef?: React.Ref<any>;
|
172 | focusMenu?: (event: FocusEvent | MouseEvent | KeyboardEvent) => any;
|
173 | unfocusMenu?: () => any;
|
174 | handleKeyDown?: (event: KeyboardEvent) => any;
|
175 | }
|
176 |
|
177 | export type StatelessMenuProps = SharedStatelessProps & MenuProps;
|
178 | export const Menu: React.FC<StatelessMenuProps>;
|
179 |
|
180 | export interface NestedMenuProps {
|
181 | children: React.ReactNode;
|
182 | }
|
183 | export interface NestedMenuState {
|
184 | menus: Array<React.Ref<HTMLElement>>;
|
185 | }
|
186 | export class NestedMenus extends React.Component<
|
187 | NestedMenuProps,
|
188 | NestedMenuState
|
189 | > {
|
190 | addMenuToNesting(ref: React.Ref<HTMLElement>): void;
|
191 | removeMenuFromNesting(ref: React.Ref<HTMLElement>): void;
|
192 | findMenuIndexByRef(ref: React.Ref<HTMLElement>): number;
|
193 | getParentMenu(ref: React.Ref<HTMLElement>): React.Ref<HTMLElement>;
|
194 | getChildMenu(ref: React.Ref<HTMLElement>): React.Ref<HTMLElement>;
|
195 | }
|
196 |
|
197 | export const StyledEmptyState: StyletronComponent<any>;
|
198 | export const StyledList: StyletronComponent<any>;
|
199 | export const StyledListItem: StyletronComponent<any>;
|
200 | export const StyledListItemProfile: StyletronComponent<any>;
|
201 | export const StyledProfileImgContainer: StyletronComponent<any>;
|
202 | export const StyledProfileImg: StyletronComponent<any>;
|
203 | export const StyledProfileLabelsContainer: StyletronComponent<any>;
|
204 | export const StyledProfileTitle: StyletronComponent<any>;
|
205 | export const StyledProfileSubtitle: StyletronComponent<any>;
|
206 | export const StyledProfileBody: StyletronComponent<any>;
|
207 |
|
208 | export const KEY_STRINGS: KEY_STRINGS;
|
209 | export const STATE_CHANGE_TYPES: STATE_CHANGE_TYPES;
|
210 | export const OPTION_LIST_SIZE: OPTION_LIST_SIZE;
|