UNPKG

7.53 kBTypeScriptView Raw
1/// <reference types="react" />
2
3import * as React from 'react';
4import CommonProps from '../util';
5import { PopupProps } from '../overlay';
6
7export interface ItemProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
8 /**
9 * 是否禁用
10 */
11 disabled?: boolean;
12
13 /**
14 * 帮助文本
15 */
16 helper?: React.ReactNode;
17
18 /**
19 * 菜单项标签内容
20 */
21 children?: React.ReactNode;
22}
23
24export class Item extends React.Component<ItemProps, any> {}
25
26export interface SubMenuProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
27 /**
28 * 标签内容
29 */
30 label?: React.ReactNode;
31
32 /**
33 * 是否可选,该属性仅在设置 Menu 组件 selectMode 属性后生效
34 */
35 selectable?: boolean;
36
37 /**
38 * 子菜单打开方式,如果设置会覆盖 Menu 上的同名属性
39 */
40 mode?: 'inline' | 'popup';
41
42 /**
43 * 菜单项或下一级子菜单
44 */
45 children?: React.ReactNode;
46}
47
48export class SubMenu extends React.Component<SubMenuProps, any> {}
49
50export interface PopupItemProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
51 /**
52 * 标签内容
53 */
54 label?: React.ReactNode;
55
56 /**
57 * 自定义弹层内容
58 */
59 children?: React.ReactNode;
60
61 /**
62 * 子菜单打开的触发行为
63 */
64 triggerType?: 'click' | 'hover';
65}
66
67export class PopupItem extends React.Component<PopupItemProps, any> {}
68
69interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
70 onChange?: any;
71}
72
73export interface CheckboxItemProps extends HTMLAttributesWeak, CommonProps {
74 /**
75 * 是否选中
76 */
77 checked?: boolean;
78
79 /**
80 * 是否半选中
81 */
82 indeterminate?: boolean;
83
84 /**
85 * 是否禁用
86 */
87 disabled?: boolean;
88
89 /**
90 * 选中或取消选中触发的回调函数
91 */
92 onChange?: (checked: boolean, event: React.MouseEvent<HTMLElement>) => void;
93
94 /**
95 * 帮助文本
96 */
97 helper?: React.ReactNode;
98
99 /**
100 * 标签内容
101 */
102 children?: React.ReactNode;
103}
104
105export class CheckboxItem extends React.Component<CheckboxItemProps, any> {}
106
107interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
108 onChange?: any;
109}
110
111export interface RadioItemProps extends HTMLAttributesWeak, CommonProps {
112 /**
113 * 是否选中
114 */
115 checked?: boolean;
116
117 /**
118 * 是否禁用
119 */
120 disabled?: boolean;
121
122 /**
123 * 选中或取消选中触发的回调函数
124 */
125 onChange?: (checked: boolean, event: {}) => void;
126
127 /**
128 * 帮助文本
129 */
130 helper?: React.ReactNode;
131
132 /**
133 * 标签内容
134 */
135 children?: React.ReactNode;
136}
137
138export class RadioItem extends React.Component<RadioItemProps, any> {}
139
140export interface GroupProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
141 /**
142 * 标签内容
143 */
144 label?: React.ReactNode;
145
146 /**
147 * 菜单项
148 */
149 children?: React.ReactNode;
150}
151
152export class Group extends React.Component<GroupProps, any> {}
153
154export interface DividerProps extends React.HTMLAttributes<HTMLElement>, CommonProps {}
155
156export class Divider extends React.Component<DividerProps, any> {}
157interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
158 onSelect?: any;
159}
160
161export interface MenuProps extends HTMLAttributesWeak, CommonProps {
162 /**
163 * 菜单项和子菜单
164 */
165 children?: React.ReactNode;
166
167 /**
168 * 点击菜单项触发的回调函数
169 */
170 onItemClick?: (key: string, item: any, event: React.MouseEvent) => void;
171
172 /**
173 * 当前打开的子菜单的 key 值
174 */
175 openKeys?: string | Array<any>;
176
177 /**
178 * 初始打开的子菜单的 key 值
179 */
180 defaultOpenKeys?: string | Array<any>;
181
182 /**
183 * 初始展开所有的子菜单,只在 mode 设置为 'inline' 以及 openMode 设置为 'multiple' 下生效,优先级高于 defaultOpenKeys
184 */
185 defaultOpenAll?: boolean;
186
187 /**
188 * 打开或关闭子菜单触发的回调函数
189 */
190 onOpen?: (key: string[], extra: { key: string; open: boolean }) => void;
191
192 /**
193 * 子菜单打开的模式
194 */
195 mode?: 'inline' | 'popup';
196
197 /**
198 * 子菜单打开的触发行为
199 */
200 triggerType?: 'click' | 'hover';
201
202 /**
203 * 展开内连子菜单的模式,同时可以展开一个子菜单还是多个子菜单,该属性仅在 mode 为 inline 时生效
204 */
205 openMode?: 'single' | 'multiple';
206
207 /**
208 * 内连子菜单缩进距离
209 */
210 inlineIndent?: number;
211
212 /**
213 * 是否自动让弹层的宽度和菜单项保持一致,如果弹层的宽度比菜单项小则和菜单项保持一致,如果宽度大于菜单项则不做处理
214 */
215 popupAutoWidth?: boolean;
216
217 /**
218 * 弹层的对齐方式
219 */
220 popupAlign?: 'follow' | 'outside';
221
222 /**
223 * 弹层自定义 props
224 */
225 popupProps?: PopupProps | (() => void);
226
227 /**
228 * 弹出子菜单自定义 className
229 */
230 popupClassName?: string;
231
232 /**
233 * 弹出子菜单自定义 style
234 */
235 popupStyle?: React.CSSProperties;
236
237 /**
238 * 当前选中菜单项的 key
239 */
240 selectedKeys?: string | Array<any>;
241
242 /**
243 * 初始选中菜单项的 key
244 */
245 defaultSelectedKeys?: string | Array<any>;
246
247 /**
248 * 选中或取消选中菜单项触发的回调函数
249 */
250 onSelect?: (selectedKeys: Array<any>, item: any, extra: { select: boolean; lable: any; keyPath: any[]; key: string[] }) => void;
251
252 /**
253 * 选中模式,单选还是多选,默认无值,不可选
254 */
255 selectMode?: 'single' | 'multiple';
256
257 /**
258 * 是否只能选择第一层菜单项(不能选择子菜单中的菜单项)
259 */
260 shallowSelect?: boolean;
261
262 /**
263 * 是否显示选中图标,如果设置为 false 需配合配置平台设置选中时的背景色以示区分
264 */
265 hasSelectedIcon?: boolean;
266
267 /**
268 * 是否将选中图标居右,仅当 hasSelectedIcon 为true 时生效。
269 * 注意:SubMenu 上的选中图标一直居左,不受此API控制
270 */
271 isSelectIconRight?: boolean;
272
273 /**
274 * 菜单第一层展示方向
275 */
276 direction?: 'ver' | 'hoz';
277
278 /**
279 * 横向菜单条 item 和 footer 的对齐方向,在 direction 设置为 'hoz' 并且 header 存在时生效
280 */
281 hozAlign?: 'left' | 'right';
282
283 /**
284 * 自定义菜单头部
285 */
286 header?: React.ReactNode;
287
288 /**
289 * 自定义菜单尾部
290 */
291 footer?: React.ReactNode;
292
293 /**
294 * 是否自动获得焦点
295 */
296 autoFocus?: boolean;
297
298 /**
299 * 当前获得焦点的子菜单或菜单项 key 值
300 */
301 focusedKey?: string;
302 renderMore?: (items?: Array<any>) => React.ReactElement;
303
304 /**
305 * 是否开启嵌入式模式,一般用于Layout的布局中,开启后没有默认背景、外层border、box-shadow,可以配合`<Menu style={{lineHeight: '100px'}}>` 自定义高度
306 */
307 embeddable?: boolean;
308 icons?: {
309 select?: React.ReactNode;
310 };
311}
312
313export default class Menu extends React.Component<MenuProps, any> {
314 static Item: typeof Item;
315 static SubMenu: typeof SubMenu;
316 static PopupItem: typeof PopupItem;
317 static CheckboxItem: typeof CheckboxItem;
318 static RadioItem: typeof RadioItem;
319 static Group: typeof Group;
320 static Divider: typeof Divider;
321 static create(props: any): void;
322}