UNPKG

2.96 kBTypeScriptView Raw
1import type * as React from 'react';
2interface ItemSharedProps {
3 ref?: React.Ref<HTMLLIElement | null>;
4 style?: React.CSSProperties;
5 className?: string;
6}
7export interface SubMenuType extends ItemSharedProps {
8 type?: 'submenu';
9 label?: React.ReactNode;
10 children: ItemType[];
11 disabled?: boolean;
12 key: string;
13 rootClassName?: string;
14 itemIcon?: RenderIconType;
15 expandIcon?: RenderIconType;
16 onMouseEnter?: MenuHoverEventHandler;
17 onMouseLeave?: MenuHoverEventHandler;
18 popupClassName?: string;
19 popupOffset?: number[];
20 popupStyle?: React.CSSProperties;
21 onClick?: MenuClickEventHandler;
22 onTitleClick?: (info: MenuTitleInfo) => void;
23 onTitleMouseEnter?: MenuHoverEventHandler;
24 onTitleMouseLeave?: MenuHoverEventHandler;
25}
26export interface MenuItemType extends ItemSharedProps {
27 type?: 'item';
28 label?: React.ReactNode;
29 disabled?: boolean;
30 itemIcon?: RenderIconType;
31 extra?: React.ReactNode;
32 key: React.Key;
33 onMouseEnter?: MenuHoverEventHandler;
34 onMouseLeave?: MenuHoverEventHandler;
35 onClick?: MenuClickEventHandler;
36}
37export interface MenuItemGroupType extends ItemSharedProps {
38 type: 'group';
39 label?: React.ReactNode;
40 children?: ItemType[];
41}
42export interface MenuDividerType extends Omit<ItemSharedProps, 'ref'> {
43 type: 'divider';
44}
45export type ItemType = SubMenuType | MenuItemType | MenuItemGroupType | MenuDividerType | null;
46export type MenuMode = 'horizontal' | 'vertical' | 'inline';
47export type BuiltinPlacements = Record<string, any>;
48export type TriggerSubMenuAction = 'click' | 'hover';
49export interface RenderIconInfo {
50 isSelected?: boolean;
51 isOpen?: boolean;
52 isSubMenu?: boolean;
53 disabled?: boolean;
54}
55export type RenderIconType = React.ReactNode | ((props: RenderIconInfo) => React.ReactNode);
56export interface MenuInfo {
57 key: string;
58 keyPath: string[];
59 /** @deprecated This will not support in future. You should avoid to use this */
60 item: React.ReactInstance;
61 domEvent: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
62}
63export interface MenuTitleInfo {
64 key: string;
65 domEvent: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;
66}
67export type MenuHoverEventHandler = (info: {
68 key: string;
69 domEvent: React.MouseEvent<HTMLElement>;
70}) => void;
71export interface SelectInfo extends MenuInfo {
72 selectedKeys: string[];
73}
74export type SelectEventHandler = (info: SelectInfo) => void;
75export type MenuClickEventHandler = (info: MenuInfo) => void;
76export type MenuRef = {
77 /**
78 * Focus active child if any, or the first child which is not disabled will be focused.
79 * @param options
80 */
81 focus: (options?: FocusOptions) => void;
82 list: HTMLUListElement;
83};
84export type ComponentType = 'submenu' | 'item' | 'group' | 'divider';
85export type Components = Partial<Record<ComponentType, React.ComponentType<any>>>;
86export {};