forked from StreakYC/react-menu-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
187 lines (153 loc) · 4.49 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import * as React from 'react';
import {ReactNode, Ref} from 'react';
import {Options as FloatAnchorOptions} from 'react-float-anchor';
export {Options as FloatAnchorOptions} from 'react-float-anchor';
export type Direction = 'up' | 'down' | 'left' | 'right';
export interface Rect {
top: number;
bottom: number;
left: number;
right: number;
}
export interface MenuEvent {
type: string;
cancelBubble: boolean;
defaultPrevented: boolean;
stopPropagation(): void;
preventDefault(): void;
}
export interface ChosenEvent extends MenuEvent {
byKeyboard: boolean;
}
// MenuList
export interface MenuListProps {
onItemChosen?: (event: ChosenEvent) => void;
onLeftPushed?: (event: MenuEvent) => void;
onRightPushed?: (event: MenuEvent) => void;
children?: ReactNode;
}
export class MenuList extends React.Component<MenuListProps> {
moveCursor(direction: Direction, prevCursorLocation?: Rect): void;
hasHighlight(): boolean;
}
// MenuItem
export interface MenuItemProps {
onItemChosen?: (event: ChosenEvent) => void;
onLeftPushed?: (event: MenuEvent) => void;
onRightPushed?: (event: MenuEvent) => void;
onHighlightChange?: (
highlighted: boolean,
details: {
byKeyboard?: boolean;
prevCursorLocation?: Rect;
direction?: Direction;
}
) => void;
className?: string;
style?: Object;
highlightedClassName?: string;
highlightedStyle?: Object;
noMouseHighlight?: boolean;
index?: number;
onMouseLeave?: (event: MouseEvent) => void;
children?: ReactNode;
domRef?: Ref<HTMLDivElement>;
'aria-haspopup'?: boolean;
'aria-expanded'?: boolean;
}
export class MenuItem extends React.Component<MenuItemProps> {
hasHighlight(): boolean;
takeKeyboard(): void;
releaseKeyboard(): void;
lockHighlight(): void;
unlockHighlight(): void;
// TODO jsdoc/tsdoc?
// byKeyboard forces focus immediately and scrolls the item into view. It defaults to true.
// With it false, the highlight might be delayed depending on mouse movement
// and won't cause anything to scroll.
highlight(byKeyboard?: boolean): void;
unhighlight(): void;
moveCursor(direction: Direction, prevCursorLocation?: Rect): void;
}
// MenuListInspector
export interface MenuListInspectorProps {
onItemChosen?: (event: ChosenEvent) => void;
onLeftPushed?: (event: MenuEvent) => void;
onRightPushed?: (event: MenuEvent) => void;
children: ReactNode;
}
export class MenuListInspector extends React.Component<MenuListInspectorProps> {
moveCursor(direction: Direction, prevCursorLocation?: Rect): boolean;
hasHighlight(): boolean;
}
// Dropdown
export interface DropdownProps extends React.HTMLAttributes<HTMLDivElement> {}
export class Dropdown extends React.Component<DropdownProps> {}
// MenuButton
export type MenuButtonRenderProp = (
domRef: React.Ref<any>,
opened: boolean,
onKeyDown: (e: React.KeyboardEvent) => void,
onMouseDown: (e: React.MouseEvent) => void
) => ReactNode;
export interface MenuButtonProps {
className?: string;
style?: Object;
disabled?: boolean;
title?: string;
openedClassName?: string;
openedStyle?: Object;
children?: ReactNode;
anchorClassName?: string;
renderButton?: MenuButtonRenderProp;
positionOptions?: FloatAnchorOptions;
menuZIndex?: string | number;
menuParentElement?: HTMLElement;
menu: ReactNode;
onWillOpen?: () => void;
onDidOpen?: () => void;
onWillClose?: () => void;
}
export class MenuButton extends React.Component<MenuButtonProps> {
open(): Promise<void>;
close(): void;
toggle(): void;
reposition(): void;
}
// SubMenuItem
export interface SubMenuItemProps {
menu: ReactNode;
positionOptions?: FloatAnchorOptions;
menuZIndex?: string | number;
menuParentElement?: HTMLElement;
onWillOpen?: () => void;
onDidOpen?: () => void;
onWillClose?: () => void;
className?: string;
style?: Object;
highlightedClassName?: string;
highlightedStyle?: Object;
index?: number;
openedClassName?: string;
openedStyle?: Object;
onItemChosen?: (event: ChosenEvent) => void;
onHighlightChange?: (
highlighted: boolean,
details: {
byKeyboard?: boolean;
prevCursorLocation?: Rect;
direction?: Direction;
}
) => void;
children?: ReactNode;
}
export class SubMenuItem extends React.Component<SubMenuItemProps> {
open(): Promise<void>;
close(): void;
toggle(): void;
reposition(): void;
hasHighlight(): boolean;
highlight(byKeyboard?: boolean): void;
unhighlight(): void;
moveCursor(direction: Direction, prevCursorLocation?: Rect): void;
}