-
-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathinterface.ts
More file actions
166 lines (125 loc) · 4.1 KB
/
Copy pathinterface.ts
File metadata and controls
166 lines (125 loc) · 4.1 KB
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
import type * as React from 'react';
import type { SubMenuProps } from './SubMenu';
// ========================= Options =========================
interface ItemSharedProps {
ref?: React.Ref<HTMLLIElement | null>;
style?: React.CSSProperties;
className?: string;
}
export interface SubMenuType extends ItemSharedProps {
type?: 'submenu';
label?: React.ReactNode;
title?: string;
children: ItemType[];
disabled?: boolean;
key: string;
rootClassName?: string;
// >>>>> Icon
itemIcon?: RenderIconType;
expandIcon?: RenderIconType;
// >>>>> Active
onMouseEnter?: MenuHoverEventHandler;
onMouseLeave?: MenuHoverEventHandler;
// >>>>> Popup
popupClassName?: string;
popupOffset?: number[];
popupStyle?: React.CSSProperties;
popupRender?: PopupRender;
// >>>>> Events
onClick?: MenuClickEventHandler;
onTitleClick?: (info: MenuTitleInfo) => void;
onTitleMouseEnter?: MenuHoverEventHandler;
onTitleMouseLeave?: MenuHoverEventHandler;
}
export interface MenuItemType extends ItemSharedProps {
type?: 'item';
label?: React.ReactNode;
disabled?: boolean;
itemIcon?: RenderIconType;
extra?: React.ReactNode;
key: React.Key;
// >>>>> Active
onMouseEnter?: MenuHoverEventHandler;
onMouseLeave?: MenuHoverEventHandler;
// >>>>> Events
onClick?: MenuClickEventHandler;
}
/** Info item type passed to onSelect/onClick callbacks, excluding event handlers */
export type ItemData = {
label?: React.ReactNode;
itemIcon?: RenderIconType;
extra?: React.ReactNode;
key: React.Key;
title?: string;
};
export interface MenuItemGroupType extends ItemSharedProps {
type: 'group';
label?: React.ReactNode;
children?: ItemType[];
}
export interface MenuDividerType extends Omit<ItemSharedProps, 'ref'> {
type: 'divider';
}
export type ItemType = SubMenuType | MenuItemType | MenuItemGroupType | MenuDividerType | null;
// ========================== Basic ==========================
export type MenuMode = 'horizontal' | 'vertical' | 'inline';
export type BuiltinPlacements = Record<string, any>;
export type TriggerSubMenuAction = 'click' | 'hover';
export interface RenderIconInfo {
isSelected?: boolean;
isOpen?: boolean;
isSubMenu?: boolean;
disabled?: boolean;
}
export type RenderIconType = React.ReactNode | ((props: RenderIconInfo) => React.ReactNode);
/**
* @deprecated Compatibility handle for deprecated `info.item`.
* Avoid relying on this shape since it will be removed in a future major version.
*/
export interface LegacyMenuItemInfo {
props: {
eventKey?: string;
[key: string]: unknown;
};
element: HTMLLIElement | null;
}
export interface MenuInfo {
key: string;
keyPath: string[];
/** @deprecated This will not support in future. You should avoid to use this */
item: LegacyMenuItemInfo;
domEvent: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
itemData: ItemData;
}
export interface MenuTitleInfo {
key: string;
domEvent: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
}
// ========================== Hover ==========================
export type MenuHoverEventHandler = (info: {
key: string;
domEvent: React.MouseEvent<HTMLElement>;
}) => void;
// ======================== Selection ========================
export interface SelectInfo extends MenuInfo {
selectedKeys: string[];
}
export type SelectEventHandler = (info: SelectInfo) => void;
// ========================== Click ==========================
export type MenuClickEventHandler = (info: MenuInfo) => void;
export type MenuRef = {
/**
* Focus active child if any, or the first child which is not disabled will be focused.
* @param options
*/
focus: (options?: FocusOptions) => void;
list: HTMLUListElement;
findItem: (params: { key: string }) => HTMLElement | null;
};
// ======================== Component ========================
export type ComponentType = 'submenu' | 'item' | 'group' | 'divider';
export type Components = Partial<Record<ComponentType, React.ComponentType<any>>>;
export type PopupRender = (
node: React.ReactElement,
info: { item: SubMenuProps; keys: string[] },
) => React.ReactNode;