@linzjs/step-ag-grid 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +284 -232
- package/dist/index.js.map +1 -1
- package/dist/src/components/GridCell.d.ts +4 -3
- package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +8 -5
- package/dist/src/react-menu3/components/ControlledMenu.d.ts +8 -2
- package/dist/src/react-menu3/components/FocusableItem.d.ts +8 -0
- package/dist/src/react-menu3/components/Menu.d.ts +16 -2
- package/dist/src/react-menu3/components/MenuButton.d.ts +8 -1
- package/dist/src/react-menu3/components/MenuDivider.d.ts +2 -1
- package/dist/src/react-menu3/components/MenuGroup.d.ts +12 -2
- package/dist/src/react-menu3/components/MenuHeader.d.ts +4 -2
- package/dist/src/react-menu3/components/MenuItem.d.ts +56 -0
- package/dist/src/react-menu3/components/MenuList.d.ts +2 -29
- package/dist/src/react-menu3/components/MenuRadioGroup.d.ts +44 -2
- package/dist/src/react-menu3/components/SubMenu.d.ts +109 -0
- package/dist/src/react-menu3/hooks/useBEM.d.ts +4 -3
- package/dist/src/react-menu3/hooks/useCombinedRef.d.ts +2 -2
- package/dist/src/react-menu3/hooks/useItemEffect.d.ts +1 -1
- package/dist/src/react-menu3/hooks/useItemState.d.ts +4 -3
- package/dist/src/react-menu3/hooks/useItems.d.ts +6 -4
- package/dist/src/react-menu3/hooks/useMenuChange.d.ts +2 -1
- package/dist/src/react-menu3/hooks/useMenuState.d.ts +13 -10
- package/dist/src/react-menu3/hooks/useMenuStateAndFocus.d.ts +2 -10
- package/dist/src/react-menu3/index.d.ts +1 -0
- package/dist/src/react-menu3/positionUtils/getPositionHelpers.d.ts +10 -9
- package/dist/src/react-menu3/positionUtils/placeArrowHorizontal.d.ts +7 -6
- package/dist/src/react-menu3/positionUtils/placeArrowVertical.d.ts +7 -6
- package/dist/src/react-menu3/positionUtils/placeLeftorRight.d.ts +17 -19
- package/dist/src/react-menu3/positionUtils/placeToporBottom.d.ts +18 -20
- package/dist/src/react-menu3/positionUtils/positionContextMenu.d.ts +11 -6
- package/dist/src/react-menu3/positionUtils/positionMenu.d.ts +23 -18
- package/dist/src/react-menu3/types.d.ts +389 -0
- package/dist/src/react-menu3/utils/constants.d.ts +58 -9
- package/dist/src/react-menu3/utils/index.d.ts +0 -1
- package/dist/src/react-menu3/utils/{propTypes.d.ts → propTypes2.d.ts} +1 -0
- package/dist/src/react-menu3/utils/utils.d.ts +20 -11
- package/dist/src/react-menu3/utils/withHovering.d.ts +7 -1
- package/dist/src/stories/components/ReactMenu.stories.d.ts +8 -0
- package/dist/step-ag-grid.esm.js +276 -235
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +11 -11
- package/src/components/GridCell.tsx +6 -3
- package/src/components/GridPopoverHook.tsx +1 -1
- package/src/components/gridForm/GridFormDropDown.tsx +1 -1
- package/src/components/gridForm/GridFormMultiSelect.tsx +36 -17
- package/src/components/gridRender/GridRenderGenericCell.tsx +11 -7
- package/src/components/gridRender/GridRenderPopoutMenuCell.tsx +14 -2
- package/src/contexts/GridContextProvider.tsx +3 -2
- package/src/react-menu3/components/ControlledMenu.tsx +40 -45
- package/src/react-menu3/components/FocusableItem.tsx +58 -53
- package/src/react-menu3/components/Menu.tsx +40 -28
- package/src/react-menu3/components/MenuButton.tsx +30 -29
- package/src/react-menu3/components/MenuDivider.tsx +14 -18
- package/src/react-menu3/components/MenuGroup.tsx +25 -16
- package/src/react-menu3/components/MenuHeader.tsx +14 -18
- package/src/react-menu3/components/MenuItem.tsx +158 -106
- package/src/react-menu3/components/MenuList.tsx +61 -36
- package/src/react-menu3/components/MenuRadioGroup.tsx +54 -15
- package/src/react-menu3/components/SubMenu.tsx +317 -202
- package/src/react-menu3/hooks/useBEM.ts +4 -3
- package/src/react-menu3/hooks/useCombinedRef.ts +6 -12
- package/src/react-menu3/hooks/useItemEffect.ts +6 -5
- package/src/react-menu3/hooks/useItemState.ts +16 -12
- package/src/react-menu3/hooks/useItems.ts +11 -10
- package/src/react-menu3/hooks/useMenuChange.ts +3 -3
- package/src/react-menu3/hooks/useMenuState.ts +25 -7
- package/src/react-menu3/hooks/useMenuStateAndFocus.ts +6 -4
- package/src/react-menu3/index.ts +1 -0
- package/src/react-menu3/positionUtils/getPositionHelpers.ts +19 -12
- package/src/react-menu3/positionUtils/placeArrowHorizontal.ts +12 -5
- package/src/react-menu3/positionUtils/placeArrowVertical.ts +12 -5
- package/src/react-menu3/positionUtils/placeLeftorRight.ts +33 -17
- package/src/react-menu3/positionUtils/placeToporBottom.ts +34 -18
- package/src/react-menu3/positionUtils/positionContextMenu.ts +15 -3
- package/src/react-menu3/positionUtils/positionMenu.ts +21 -14
- package/src/react-menu3/style-utils/index.ts +10 -7
- package/src/react-menu3/{index.d.ts → types.ts} +106 -358
- package/src/react-menu3/utils/constants.ts +82 -10
- package/src/react-menu3/utils/index.ts +1 -1
- package/src/react-menu3/utils/{propTypes.ts → propTypes2.ts} +3 -1
- package/src/react-menu3/utils/utils.ts +41 -24
- package/src/react-menu3/utils/withHovering.tsx +11 -6
- package/src/stories/components/GridReadOnly.stories.tsx +3 -4
- package/src/stories/components/ReactMenu.stories.tsx +37 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React = require("react");
|
|
2
|
-
|
|
3
1
|
//
|
|
4
2
|
// base types
|
|
5
3
|
// ----------------------------------------------------------------------
|
|
4
|
+
import { ForwardedRef, MutableRefObject } from "react";
|
|
5
|
+
|
|
6
6
|
export type MenuState = "opening" | "open" | "closing" | "closed";
|
|
7
7
|
export type MenuAlign = "start" | "center" | "end";
|
|
8
8
|
export type MenuDirection = "left" | "right" | "top" | "bottom";
|
|
@@ -19,11 +19,11 @@ export type CloseReason = "click" | "cancel" | "blur" | "scroll";
|
|
|
19
19
|
*/
|
|
20
20
|
export type FocusPosition = "first" | "last" | number;
|
|
21
21
|
|
|
22
|
-
type ClassNameProp<M = undefined> = string | ((modifiers: M) => string);
|
|
22
|
+
export type ClassNameProp<M = undefined> = string | ((modifiers: M) => string);
|
|
23
23
|
|
|
24
|
-
type RenderProp<M, R = React.ReactNode> = R | ((modifiers: M) => R);
|
|
24
|
+
export type RenderProp<M, R = React.ReactNode> = R | ((modifiers: M) => R);
|
|
25
25
|
|
|
26
|
-
interface BaseProps<M = undefined> extends Omit<React.HTMLAttributes<HTMLElement>, "className" | "children"> {
|
|
26
|
+
export interface BaseProps<M = undefined> extends Omit<React.HTMLAttributes<HTMLElement>, "className" | "children"> {
|
|
27
27
|
ref?: React.Ref<any>;
|
|
28
28
|
/**
|
|
29
29
|
* Can be a string or a function which receives a modifier object and returns a CSS `class` string.
|
|
@@ -31,7 +31,7 @@ interface BaseProps<M = undefined> extends Omit<React.HTMLAttributes<HTMLElement
|
|
|
31
31
|
className?: ClassNameProp<M>;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
interface Event {
|
|
34
|
+
export interface Event {
|
|
35
35
|
/**
|
|
36
36
|
* The `value` prop passed to the `MenuItem` being clicked.
|
|
37
37
|
* It's useful for identifying which menu item is clicked.
|
|
@@ -50,33 +50,6 @@ export interface MenuCloseEvent extends Event {
|
|
|
50
50
|
reason: CloseReason;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export interface RadioChangeEvent extends Event {
|
|
54
|
-
/**
|
|
55
|
-
* The `name` prop passed to the `MenuRadioGroup` when the menu item is in a radio group.
|
|
56
|
-
*/
|
|
57
|
-
name?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Set this property on event object to control whether to keep menu open after menu item is activated.
|
|
60
|
-
* Leaving it `undefined` will behave in accordance with WAI-ARIA Authoring Practices.
|
|
61
|
-
*/
|
|
62
|
-
keepOpen?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Setting this property on event object to `true` will skip `onItemClick` event on root menu component.
|
|
65
|
-
*/
|
|
66
|
-
stopPropagation?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* DOM event object (React synthetic event)
|
|
69
|
-
*/
|
|
70
|
-
syntheticEvent: MouseEvent | KeyboardEvent;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface ClickEvent extends RadioChangeEvent {
|
|
74
|
-
/**
|
|
75
|
-
* Indicates if the menu item is checked, only for `MenuItem` type="checkbox".
|
|
76
|
-
*/
|
|
77
|
-
checked?: boolean;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
53
|
export interface MenuChangeEvent {
|
|
81
54
|
/**
|
|
82
55
|
* Indicates if the menu is open or closed.
|
|
@@ -84,11 +57,11 @@ export interface MenuChangeEvent {
|
|
|
84
57
|
open: boolean;
|
|
85
58
|
}
|
|
86
59
|
|
|
87
|
-
interface EventHandler<E> {
|
|
60
|
+
export interface EventHandler<E> {
|
|
88
61
|
(event: E): void;
|
|
89
62
|
}
|
|
90
63
|
|
|
91
|
-
interface RectElement {
|
|
64
|
+
export interface RectElement {
|
|
92
65
|
getBoundingClientRect(): {
|
|
93
66
|
left: number;
|
|
94
67
|
right: number;
|
|
@@ -122,6 +95,14 @@ export type MenuArrowModifiers = Readonly<{
|
|
|
122
95
|
dir: MenuDirection;
|
|
123
96
|
}>;
|
|
124
97
|
|
|
98
|
+
export type TransitionFieldType =
|
|
99
|
+
| boolean
|
|
100
|
+
| {
|
|
101
|
+
open?: boolean;
|
|
102
|
+
close?: boolean;
|
|
103
|
+
item?: boolean;
|
|
104
|
+
};
|
|
105
|
+
|
|
125
106
|
export interface MenuStateOptions {
|
|
126
107
|
/**
|
|
127
108
|
* By default menu isn't mounted into DOM until it's opened for the first time.
|
|
@@ -145,13 +126,8 @@ export interface MenuStateOptions {
|
|
|
145
126
|
*
|
|
146
127
|
* @example [CodeSandbox Demo](https://codesandbox.io/s/react-menu-sass-i1wxo)
|
|
147
128
|
*/
|
|
148
|
-
transition?:
|
|
149
|
-
|
|
150
|
-
| {
|
|
151
|
-
open?: boolean;
|
|
152
|
-
close?: boolean;
|
|
153
|
-
item?: boolean;
|
|
154
|
-
};
|
|
129
|
+
transition?: TransitionFieldType;
|
|
130
|
+
|
|
155
131
|
/**
|
|
156
132
|
* A fallback timeout in `ms` to stop transition if `onAnimationEnd` events are not fired.
|
|
157
133
|
*
|
|
@@ -163,7 +139,7 @@ export interface MenuStateOptions {
|
|
|
163
139
|
transitionTimeout?: number;
|
|
164
140
|
}
|
|
165
141
|
|
|
166
|
-
interface Hoverable {
|
|
142
|
+
export interface Hoverable {
|
|
167
143
|
disabled?: boolean;
|
|
168
144
|
index?: number;
|
|
169
145
|
}
|
|
@@ -242,10 +218,85 @@ interface BaseMenuProps extends Omit<BaseProps, "style"> {
|
|
|
242
218
|
children?: React.ReactNode;
|
|
243
219
|
}
|
|
244
220
|
|
|
221
|
+
//
|
|
222
|
+
// MenuButton
|
|
223
|
+
// ----------------------------------------------------------------------
|
|
224
|
+
export type MenuButtonModifiers = Readonly<{
|
|
225
|
+
/**
|
|
226
|
+
* Indicates if the associated menu is open.
|
|
227
|
+
*/
|
|
228
|
+
open: boolean;
|
|
229
|
+
}>;
|
|
230
|
+
|
|
231
|
+
export interface MenuInstance {
|
|
232
|
+
/**
|
|
233
|
+
* Open menu and optionally request which menu item will be hovered.
|
|
234
|
+
*/
|
|
235
|
+
openMenu: (position?: FocusPosition, alwaysUpdate?: boolean) => void;
|
|
236
|
+
/**
|
|
237
|
+
* Close menu
|
|
238
|
+
*/
|
|
239
|
+
closeMenu: () => void;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Common props for `Menu` and `SubMenu`
|
|
244
|
+
*/
|
|
245
|
+
export interface UncontrolledMenuProps {
|
|
246
|
+
/**
|
|
247
|
+
* Menu component ref which can be used to programmatically open or close menu.
|
|
248
|
+
*/
|
|
249
|
+
instanceRef?: React.Ref<MenuInstance>;
|
|
250
|
+
/**
|
|
251
|
+
* Event fired after menu is open or closed.
|
|
252
|
+
*/
|
|
253
|
+
onMenuChange?: EventHandler<MenuChangeEvent>;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface RadioChangeEvent extends Event {
|
|
257
|
+
/**
|
|
258
|
+
* The `name` prop passed to the `MenuRadioGroup` when the menu item is in a radio group.
|
|
259
|
+
*/
|
|
260
|
+
name?: string;
|
|
261
|
+
/**
|
|
262
|
+
* Set this property on event object to control whether to keep menu open after menu item is activated.
|
|
263
|
+
* Leaving it `undefined` will behave in accordance with WAI-ARIA Authoring Practices.
|
|
264
|
+
*/
|
|
265
|
+
keepOpen?: boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Setting this property on event object to `true` will skip `onItemClick` event on root menu component.
|
|
268
|
+
*/
|
|
269
|
+
stopPropagation?: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* DOM event object (React synthetic event)
|
|
272
|
+
*/
|
|
273
|
+
syntheticEvent: MouseEvent | KeyboardEvent;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface ClickEvent extends RadioChangeEvent {
|
|
277
|
+
/**
|
|
278
|
+
* Indicates if the menu item is checked, only for `MenuItem` type="checkbox".
|
|
279
|
+
*/
|
|
280
|
+
checked?: boolean;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export type PortalFieldType =
|
|
284
|
+
| boolean
|
|
285
|
+
| {
|
|
286
|
+
/**
|
|
287
|
+
* A DOM node under which menu will be rendered.
|
|
288
|
+
*/
|
|
289
|
+
target?: Element | null;
|
|
290
|
+
/**
|
|
291
|
+
* When `target` is null, setting this value `true` prevents menu from rendering into the DOM hierarchy of its parent component.
|
|
292
|
+
*/
|
|
293
|
+
stablePosition?: boolean;
|
|
294
|
+
};
|
|
295
|
+
|
|
245
296
|
/**
|
|
246
297
|
* Common props for `Menu` and `ControlledMenu`
|
|
247
298
|
*/
|
|
248
|
-
interface RootMenuProps extends BaseMenuProps, MenuStateOptions {
|
|
299
|
+
export interface RootMenuProps extends BaseMenuProps, MenuStateOptions {
|
|
249
300
|
/**
|
|
250
301
|
* Properties of this object are spread to the root DOM element containing the menu.
|
|
251
302
|
*/
|
|
@@ -279,18 +330,8 @@ interface RootMenuProps extends BaseMenuProps, MenuStateOptions {
|
|
|
279
330
|
* - You have a DOM structure that creates a complex hierarchy of stacking contexts,
|
|
280
331
|
* and menu is overlapped regardless of `z-index` value.
|
|
281
332
|
*/
|
|
282
|
-
portal?:
|
|
283
|
-
|
|
284
|
-
| {
|
|
285
|
-
/**
|
|
286
|
-
* A DOM node under which menu will be rendered.
|
|
287
|
-
*/
|
|
288
|
-
target?: Element | null;
|
|
289
|
-
/**
|
|
290
|
-
* When `target` is null, setting this value `true` prevents menu from rendering into the DOM hierarchy of its parent component.
|
|
291
|
-
*/
|
|
292
|
-
stablePosition?: boolean;
|
|
293
|
-
};
|
|
333
|
+
portal?: PortalFieldType;
|
|
334
|
+
|
|
294
335
|
/**
|
|
295
336
|
* Specify when menu is repositioned:
|
|
296
337
|
* - 'initial' Don't automatically reposition menu. Set to this value when you want
|
|
@@ -330,70 +371,18 @@ interface RootMenuProps extends BaseMenuProps, MenuStateOptions {
|
|
|
330
371
|
onItemClick?: EventHandler<ClickEvent>;
|
|
331
372
|
}
|
|
332
373
|
|
|
333
|
-
export interface
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
* Close menu
|
|
340
|
-
*/
|
|
341
|
-
closeMenu: () => void;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Common props for `Menu` and `SubMenu`
|
|
346
|
-
*/
|
|
347
|
-
interface UncontrolledMenuProps {
|
|
348
|
-
/**
|
|
349
|
-
* Menu component ref which can be used to programmatically open or close menu.
|
|
350
|
-
*/
|
|
351
|
-
instanceRef?: React.Ref<MenuInstance>;
|
|
352
|
-
/**
|
|
353
|
-
* Event fired after menu is open or closed.
|
|
354
|
-
*/
|
|
355
|
-
onMenuChange?: EventHandler<MenuChangeEvent>;
|
|
374
|
+
export interface ExtraMenuProps {
|
|
375
|
+
isDisabled?: boolean;
|
|
376
|
+
ariaLabel?: string;
|
|
377
|
+
containerRef?: MutableRefObject<HTMLElement | undefined>;
|
|
378
|
+
externalRef?: ForwardedRef<HTMLUListElement>;
|
|
379
|
+
parentScrollingRef?: MutableRefObject<any>;
|
|
356
380
|
}
|
|
357
381
|
|
|
358
|
-
//
|
|
359
|
-
// MenuButton
|
|
360
|
-
// ----------------------------------------------------------------------
|
|
361
|
-
export type MenuButtonModifiers = Readonly<{
|
|
362
|
-
/**
|
|
363
|
-
* Indicates if the associated menu is open.
|
|
364
|
-
*/
|
|
365
|
-
open: boolean;
|
|
366
|
-
}>;
|
|
367
|
-
|
|
368
|
-
export interface MenuButtonProps extends BaseProps<MenuButtonModifiers> {
|
|
369
|
-
disabled?: boolean;
|
|
370
|
-
children?: React.ReactNode;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export const MenuButton: React.NamedExoticComponent<MenuButtonProps>;
|
|
374
|
-
|
|
375
|
-
//
|
|
376
|
-
// Menu
|
|
377
|
-
// ----------------------------------------------------------------------
|
|
378
|
-
export interface MenuProps extends RootMenuProps, UncontrolledMenuProps {
|
|
379
|
-
/**
|
|
380
|
-
* Can be a `MenuButton`, a `button` element, or a React component.
|
|
381
|
-
* It also can be a render function that returns one.
|
|
382
|
-
*
|
|
383
|
-
* If a React component is provided, it needs to implement the following contracts:
|
|
384
|
-
* - Accepts a `ref` prop that is forwarded to an element to which menu will be positioned.
|
|
385
|
-
* The element should be able to receive focus.
|
|
386
|
-
* - Accepts `onClick` and `onKeyDown` event props.
|
|
387
|
-
*/
|
|
388
|
-
menuButton: RenderProp<MenuButtonModifiers, React.ReactElement>;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
export const Menu: React.NamedExoticComponent<MenuProps>;
|
|
392
|
-
|
|
393
382
|
//
|
|
394
383
|
// ControlledMenu
|
|
395
384
|
// ----------------------------------------------------------------------
|
|
396
|
-
export interface ControlledMenuProps extends RootMenuProps {
|
|
385
|
+
export interface ControlledMenuProps extends RootMenuProps, ExtraMenuProps {
|
|
397
386
|
/**
|
|
398
387
|
* Viewport coordinates to which context menu will be positioned.
|
|
399
388
|
*
|
|
@@ -408,8 +397,8 @@ export interface ControlledMenuProps extends RootMenuProps {
|
|
|
408
397
|
*
|
|
409
398
|
* *Don't set this prop for context menu*
|
|
410
399
|
*/
|
|
411
|
-
anchorRef?: React.
|
|
412
|
-
skipOpen?: React.
|
|
400
|
+
anchorRef?: React.MutableRefObject<HTMLElement>;
|
|
401
|
+
skipOpen?: React.MutableRefObject<boolean>;
|
|
413
402
|
/**
|
|
414
403
|
* If `true`, the menu list element will gain focus after menu is open.
|
|
415
404
|
* @default true
|
|
@@ -439,244 +428,3 @@ export interface ControlledMenuProps extends RootMenuProps {
|
|
|
439
428
|
*/
|
|
440
429
|
onClose?: EventHandler<MenuCloseEvent>;
|
|
441
430
|
}
|
|
442
|
-
|
|
443
|
-
export const ControlledMenu: React.NamedExoticComponent<ControlledMenuProps>;
|
|
444
|
-
|
|
445
|
-
//
|
|
446
|
-
// SubMenu
|
|
447
|
-
// ----------------------------------------------------------------------
|
|
448
|
-
export type SubMenuItemModifiers = Readonly<{
|
|
449
|
-
/**
|
|
450
|
-
* Indicates if the submenu is open.
|
|
451
|
-
*/
|
|
452
|
-
open: boolean;
|
|
453
|
-
/**
|
|
454
|
-
* Indicates if the submenu item is being hovered and has focus.
|
|
455
|
-
*/
|
|
456
|
-
hover: boolean;
|
|
457
|
-
/**
|
|
458
|
-
* Indicates if the submenu and item are disabled.
|
|
459
|
-
*/
|
|
460
|
-
disabled: boolean;
|
|
461
|
-
}>;
|
|
462
|
-
|
|
463
|
-
export interface SubMenuProps extends BaseMenuProps, Hoverable, UncontrolledMenuProps {
|
|
464
|
-
/**
|
|
465
|
-
* Properties of this object are spread to the submenu item DOM element.
|
|
466
|
-
*/
|
|
467
|
-
itemProps?: BaseProps<SubMenuItemModifiers>;
|
|
468
|
-
/**
|
|
469
|
-
* The submenu `label` can be a `string` or JSX element, or a render function that returns one.
|
|
470
|
-
*/
|
|
471
|
-
label?: RenderProp<SubMenuItemModifiers>;
|
|
472
|
-
/**
|
|
473
|
-
* - `undefined` submenu opens when the label item is hovered or clicked. This is the default behaviour.
|
|
474
|
-
* - 'clickOnly' submenu opens when the label item is clicked.
|
|
475
|
-
* - 'none' submenu doesn't open with mouse or keyboard events;
|
|
476
|
-
* you can call the `openMenu` function on `instanceRef` to open submenu programmatically.
|
|
477
|
-
*/
|
|
478
|
-
openTrigger?: "none" | "clickOnly";
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
export const SubMenu: React.NamedExoticComponent<SubMenuProps>;
|
|
482
|
-
|
|
483
|
-
//
|
|
484
|
-
// MenuItem
|
|
485
|
-
// ----------------------------------------------------------------------
|
|
486
|
-
export type MenuItemModifiers = Readonly<{
|
|
487
|
-
/**
|
|
488
|
-
* 'radio' for radio item, 'checkbox' for checkbox item, or `undefined` for other items.
|
|
489
|
-
*/
|
|
490
|
-
type?: MenuItemTypeProp;
|
|
491
|
-
/**
|
|
492
|
-
* Indicates if the menu item is disabled.
|
|
493
|
-
*/
|
|
494
|
-
disabled: boolean;
|
|
495
|
-
/**
|
|
496
|
-
* Indicates if the menu item is being hovered and has focus.
|
|
497
|
-
*/
|
|
498
|
-
hover: boolean;
|
|
499
|
-
/**
|
|
500
|
-
* Indicates if the menu item is checked when it's a radio or checkbox item.
|
|
501
|
-
*/
|
|
502
|
-
checked: boolean;
|
|
503
|
-
/**
|
|
504
|
-
* Indicates if the menu item has a URL link.
|
|
505
|
-
*/
|
|
506
|
-
anchor: boolean;
|
|
507
|
-
}>;
|
|
508
|
-
|
|
509
|
-
export interface MenuItemProps extends Omit<BaseProps<MenuItemModifiers>, "onClick">, Hoverable {
|
|
510
|
-
/**
|
|
511
|
-
* Any value provided to this prop will be available in the event object of click events.
|
|
512
|
-
*
|
|
513
|
-
* It's useful for helping identify which menu item is clicked when you
|
|
514
|
-
* listen on `onItemClick` event on root menu component.
|
|
515
|
-
*/
|
|
516
|
-
value?: any;
|
|
517
|
-
/**
|
|
518
|
-
* If provided, menu item renders an HTML `<a>` element with this `href` attribute.
|
|
519
|
-
*/
|
|
520
|
-
href?: string;
|
|
521
|
-
rel?: string;
|
|
522
|
-
target?: string;
|
|
523
|
-
/**
|
|
524
|
-
* Set this prop to make the item a checkbox or radio menu item.
|
|
525
|
-
*/
|
|
526
|
-
type?: MenuItemTypeProp;
|
|
527
|
-
/**
|
|
528
|
-
* Set `true` if a checkbox menu item is checked.
|
|
529
|
-
*
|
|
530
|
-
* *Please note radio menu item doesn't use this prop.*
|
|
531
|
-
*/
|
|
532
|
-
checked?: boolean;
|
|
533
|
-
/**
|
|
534
|
-
* Event fired when the menu item is clicked.
|
|
535
|
-
*/
|
|
536
|
-
onClick?: EventHandler<ClickEvent>;
|
|
537
|
-
/**
|
|
538
|
-
* Any valid React node or a render function that returns one.
|
|
539
|
-
*/
|
|
540
|
-
children?: RenderProp<MenuItemModifiers>;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
export const MenuItem: React.NamedExoticComponent<MenuItemProps>;
|
|
544
|
-
|
|
545
|
-
//
|
|
546
|
-
// FocusableItem
|
|
547
|
-
// ----------------------------------------------------------------------
|
|
548
|
-
export type FocusableItemModifiers = Readonly<{
|
|
549
|
-
/**
|
|
550
|
-
* Indicates if the focusable item is disabled.
|
|
551
|
-
*/
|
|
552
|
-
disabled: boolean;
|
|
553
|
-
/**
|
|
554
|
-
* Indicates if the focusable item is being hovered.
|
|
555
|
-
*/
|
|
556
|
-
hover: boolean;
|
|
557
|
-
/**
|
|
558
|
-
* Always `true` for a focusable item.
|
|
559
|
-
*/
|
|
560
|
-
focusable: true;
|
|
561
|
-
}>;
|
|
562
|
-
|
|
563
|
-
export interface FocusableItemProps extends BaseProps<FocusableItemModifiers>, Hoverable {
|
|
564
|
-
/**
|
|
565
|
-
* A render function that returns a React node.
|
|
566
|
-
*/
|
|
567
|
-
children: (modifiers: {
|
|
568
|
-
/**
|
|
569
|
-
* Indicates if the focusable item is disabled.
|
|
570
|
-
*/
|
|
571
|
-
disabled: boolean;
|
|
572
|
-
/**
|
|
573
|
-
* Indicates if the focusable item is being hovered.
|
|
574
|
-
*/
|
|
575
|
-
hover: boolean;
|
|
576
|
-
/**
|
|
577
|
-
* A ref to be attached to the element which should receive focus when this focusable item is hovered.
|
|
578
|
-
*
|
|
579
|
-
* If you render a React component, it needs to expose a `focus` method or implement ref forwarding.
|
|
580
|
-
*/
|
|
581
|
-
ref: React.RefObject<any>;
|
|
582
|
-
/**
|
|
583
|
-
* A function that requests to close the root menu.
|
|
584
|
-
* @param {string} key Indicate which key initiates the close request.
|
|
585
|
-
*/
|
|
586
|
-
closeMenu: (key?: string) => void;
|
|
587
|
-
}) => React.ReactNode;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* A component to wrap focusable element (input, button) in a menu item.
|
|
592
|
-
* It manages focus automatically among other menu items during mouse and keyboard interactions.
|
|
593
|
-
*
|
|
594
|
-
* @example https://szhsin.github.io/react-menu/#focusable-item
|
|
595
|
-
*/
|
|
596
|
-
export const FocusableItem: React.NamedExoticComponent<FocusableItemProps>;
|
|
597
|
-
|
|
598
|
-
//
|
|
599
|
-
// MenuDivider
|
|
600
|
-
// ----------------------------------------------------------------------
|
|
601
|
-
export const MenuDivider: React.NamedExoticComponent<BaseProps>;
|
|
602
|
-
|
|
603
|
-
//
|
|
604
|
-
// MenuHeader
|
|
605
|
-
// ----------------------------------------------------------------------
|
|
606
|
-
export interface MenuHeaderProps extends BaseProps {
|
|
607
|
-
children?: React.ReactNode;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
export const MenuHeader: React.NamedExoticComponent<MenuHeaderProps>;
|
|
611
|
-
|
|
612
|
-
//
|
|
613
|
-
// MenuGroup
|
|
614
|
-
// ----------------------------------------------------------------------
|
|
615
|
-
export interface MenuGroupProps extends BaseProps {
|
|
616
|
-
children?: React.ReactNode;
|
|
617
|
-
/**
|
|
618
|
-
* Set `true` to apply overflow of the parent menu to the group.
|
|
619
|
-
* Only one `MenuGroup` in a menu should set this prop as `true`.
|
|
620
|
-
*/
|
|
621
|
-
takeOverflow?: boolean;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* A component to wrap a subset related menu items and make them scrollable.
|
|
626
|
-
*
|
|
627
|
-
* @example https://szhsin.github.io/react-menu/#menu-overflow
|
|
628
|
-
*/
|
|
629
|
-
export const MenuGroup: React.NamedExoticComponent<MenuGroupProps>;
|
|
630
|
-
|
|
631
|
-
//
|
|
632
|
-
// MenuRadioGroup
|
|
633
|
-
// ----------------------------------------------------------------------
|
|
634
|
-
export interface MenuRadioGroupProps extends BaseProps {
|
|
635
|
-
/**
|
|
636
|
-
* Optionally set the radio group name.
|
|
637
|
-
*
|
|
638
|
-
* The name will be passed to the `onRadioChange` event.
|
|
639
|
-
* It's useful for identifying radio groups if you attach the same event handler to multiple groups.
|
|
640
|
-
*/
|
|
641
|
-
name?: string;
|
|
642
|
-
/**
|
|
643
|
-
* Set value of the radio group.
|
|
644
|
-
*
|
|
645
|
-
* The child menu item which has the same value (strict equality ===) as the
|
|
646
|
-
* radio group is marked as checked.
|
|
647
|
-
*/
|
|
648
|
-
value?: any;
|
|
649
|
-
children?: React.ReactNode;
|
|
650
|
-
/**
|
|
651
|
-
* Event fired when a child menu item is clicked (selected).
|
|
652
|
-
*/
|
|
653
|
-
onRadioChange?: EventHandler<RadioChangeEvent>;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
export const MenuRadioGroup: React.NamedExoticComponent<MenuRadioGroupProps>;
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* A custom Hook which helps manage the states of `ControlledMenu`.
|
|
660
|
-
*/
|
|
661
|
-
export function useMenuState(options?: MenuStateOptions): [
|
|
662
|
-
{
|
|
663
|
-
/**
|
|
664
|
-
* Menu state which should be forwarded to `ControlledMenu`.
|
|
665
|
-
*/
|
|
666
|
-
state?: MenuState;
|
|
667
|
-
/**
|
|
668
|
-
* Stop transition animation. This function value should be forwarded to `ControlledMenu`.
|
|
669
|
-
*/
|
|
670
|
-
endTransition: () => void;
|
|
671
|
-
},
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Open or close menu.
|
|
675
|
-
*
|
|
676
|
-
* - If no parameter is supplied, this function will toggle state between open and close phases.
|
|
677
|
-
* - You can set a boolean parameter to explicitly switch into one of the two phases.
|
|
678
|
-
*/
|
|
679
|
-
(open?: boolean) => void,
|
|
680
|
-
];
|
|
681
|
-
|
|
682
|
-
export {};
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import { createContext, MutableRefObject, RefObject } from "react";
|
|
2
|
+
import {
|
|
3
|
+
ControlledMenuProps,
|
|
4
|
+
EventHandler,
|
|
5
|
+
FocusPosition,
|
|
6
|
+
MenuDirection,
|
|
7
|
+
MenuOverflow,
|
|
8
|
+
MenuReposition,
|
|
9
|
+
MenuState,
|
|
10
|
+
MenuViewScroll,
|
|
11
|
+
RectElement,
|
|
12
|
+
TransitionFieldType,
|
|
13
|
+
} from "../types";
|
|
14
|
+
import { RadioChangeEvent } from "../components/MenuRadioGroup";
|
|
3
15
|
|
|
4
16
|
export const menuContainerClass = "szh-menu-container";
|
|
5
17
|
export const menuClass = "szh-menu";
|
|
@@ -12,13 +24,73 @@ export const menuGroupClass = "group";
|
|
|
12
24
|
export const subMenuClass = "submenu";
|
|
13
25
|
export const radioGroupClass = "radio-group";
|
|
14
26
|
|
|
15
|
-
export const HoverItemContext = createContext();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
export const HoverItemContext = createContext(undefined);
|
|
28
|
+
|
|
29
|
+
interface MenuListItemContextType {
|
|
30
|
+
isParentOpen?: boolean;
|
|
31
|
+
isSubmenuOpen?: boolean;
|
|
32
|
+
dispatch: (actionType: number, item: any, nextIndex: FocusPosition) => void;
|
|
33
|
+
updateItems: (item: any, isMounted?: boolean) => void;
|
|
34
|
+
setOpenSubmenuCount: (fn: (count: number) => number) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const MenuListItemContext = createContext<MenuListItemContextType>({
|
|
38
|
+
dispatch: () => {},
|
|
39
|
+
updateItems: () => {},
|
|
40
|
+
setOpenSubmenuCount: () => 0,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const MenuListContext = createContext<{
|
|
44
|
+
overflow?: MenuOverflow;
|
|
45
|
+
overflowAmt?: number;
|
|
46
|
+
parentMenuRef?: MutableRefObject<any>;
|
|
47
|
+
parentDir?: MenuDirection;
|
|
48
|
+
reposSubmenu?: boolean;
|
|
49
|
+
}>({});
|
|
50
|
+
|
|
51
|
+
export interface RMEvent {
|
|
52
|
+
value: any;
|
|
53
|
+
syntheticEvent: any;
|
|
54
|
+
checked?: boolean;
|
|
55
|
+
name?: string;
|
|
56
|
+
key?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const EventHandlersContext = createContext<{
|
|
60
|
+
handleClose?: () => void;
|
|
61
|
+
handleClick: (event: RMEvent, checked: boolean) => void;
|
|
62
|
+
}>({
|
|
63
|
+
handleClick: () => {},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const RadioGroupContext = createContext<{
|
|
67
|
+
value?: any;
|
|
68
|
+
name?: string;
|
|
69
|
+
onRadioChange?: EventHandler<RadioChangeEvent>;
|
|
70
|
+
}>({});
|
|
71
|
+
|
|
72
|
+
interface SettingsContextType extends ControlledMenuProps {
|
|
73
|
+
rootMenuRef?: MutableRefObject<any>;
|
|
74
|
+
rootAnchorRef?: MutableRefObject<any>;
|
|
75
|
+
scrollNodesRef: MutableRefObject<{ anchors?: Element[]; menu?: any }>;
|
|
76
|
+
|
|
77
|
+
initialMounted?: boolean;
|
|
78
|
+
unmountOnClose?: boolean;
|
|
79
|
+
transition?: TransitionFieldType;
|
|
80
|
+
transitionTimeout?: number;
|
|
81
|
+
boundingBoxRef?: RefObject<Element | RectElement>;
|
|
82
|
+
boundingBoxPadding?: string;
|
|
83
|
+
reposition?: MenuReposition;
|
|
84
|
+
viewScroll?: MenuViewScroll;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// FIXME hacking a default context in here is probably bad
|
|
88
|
+
export const SettingsContext = createContext<SettingsContextType>({} as SettingsContextType);
|
|
89
|
+
|
|
90
|
+
export const ItemSettingsContext = createContext<{ submenuCloseDelay: number; submenuOpenDelay: number }>({
|
|
91
|
+
submenuOpenDelay: 0,
|
|
92
|
+
submenuCloseDelay: 0,
|
|
93
|
+
});
|
|
22
94
|
|
|
23
95
|
export const Keys = Object.freeze({
|
|
24
96
|
ENTER: "Enter",
|
|
@@ -55,7 +127,7 @@ export const FocusPositions = Object.freeze({
|
|
|
55
127
|
LAST: "last",
|
|
56
128
|
});
|
|
57
129
|
|
|
58
|
-
export const MenuStateMap: Record<string,
|
|
130
|
+
export const MenuStateMap: Record<string, MenuState> = Object.freeze({
|
|
59
131
|
entering: "opening",
|
|
60
132
|
entered: "open",
|
|
61
133
|
exiting: "closing",
|
|
@@ -4,6 +4,8 @@ export const stylePropTypes = (name?: string) => ({
|
|
|
4
4
|
[name ? `${name}ClassName` : "className"]: oneOfType([string, func]),
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
+
export const Direction = oneOf(["left", "right", "top", "bottom"]);
|
|
8
|
+
|
|
7
9
|
// Menu, SubMenu and ControlledMenu
|
|
8
10
|
export const menuPropTypes = {
|
|
9
11
|
className: string,
|
|
@@ -16,7 +18,7 @@ export const menuPropTypes = {
|
|
|
16
18
|
offsetX: number,
|
|
17
19
|
offsetY: number,
|
|
18
20
|
align: oneOf(["start", "center", "end"]),
|
|
19
|
-
direction:
|
|
21
|
+
direction: Direction,
|
|
20
22
|
position: oneOf(["auto", "anchor", "initial"]),
|
|
21
23
|
overflow: oneOf(["auto", "visible", "hidden"]),
|
|
22
24
|
};
|