-
-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathinterface.ts
142 lines (104 loc) · 3.3 KB
/
interface.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
import type * as React from 'react';
// ========================= Options =========================
interface ItemSharedProps {
ref?: React.Ref<HTMLLIElement | null>;
style?: React.CSSProperties;
className?: string;
}
export interface SubMenuType extends ItemSharedProps {
type?: 'submenu';
label?: React.ReactNode;
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;
// >>>>> 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;
}
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);
export interface MenuInfo {
key: string;
keyPath: string[];
/** @deprecated This will not support in future. You should avoid to use this */
item: React.ReactInstance;
domEvent: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
}
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;
};
// ======================== Component ========================
export type ComponentType = 'submenu' | 'item' | 'group' | 'divider';
export type Components = Partial<Record<ComponentType, React.ComponentType<any>>>;