@linzjs/step-ag-grid 1.4.4 → 1.4.6

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.
Files changed (102) hide show
  1. package/dist/index.js +1631 -3040
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/components/GridLoadableCell.d.ts +2 -0
  4. package/dist/src/components/gridForm/GridFormDropDown.d.ts +1 -1
  5. package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +1 -1
  6. package/dist/src/components/gridPopoverEdit/GridPopoverMenu.d.ts +1 -1
  7. package/dist/src/react-menu3/components/ControlledMenu.d.ts +2 -0
  8. package/dist/src/react-menu3/components/FocusableItem.d.ts +9 -0
  9. package/dist/src/react-menu3/components/Menu.d.ts +16 -0
  10. package/dist/src/react-menu3/components/MenuButton.d.ts +8 -0
  11. package/dist/src/react-menu3/components/MenuDivider.d.ts +3 -0
  12. package/dist/src/react-menu3/components/MenuGroup.d.ts +12 -0
  13. package/dist/src/react-menu3/components/MenuHeader.d.ts +4 -0
  14. package/dist/src/react-menu3/components/MenuItem.d.ts +59 -0
  15. package/dist/src/react-menu3/components/MenuList.d.ts +57 -0
  16. package/dist/src/react-menu3/components/MenuRadioGroup.d.ts +44 -0
  17. package/dist/src/react-menu3/components/SubMenu.d.ts +110 -0
  18. package/dist/src/react-menu3/hooks/index.d.ts +9 -0
  19. package/dist/src/react-menu3/hooks/useBEM.d.ts +10 -0
  20. package/dist/src/react-menu3/hooks/useCombinedRef.d.ts +2 -0
  21. package/dist/src/react-menu3/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
  22. package/dist/src/react-menu3/hooks/useItemEffect.d.ts +2 -0
  23. package/dist/src/react-menu3/hooks/useItemState.d.ts +7 -0
  24. package/dist/src/react-menu3/hooks/useItems.d.ts +7 -0
  25. package/dist/src/react-menu3/hooks/useMenuChange.d.ts +2 -0
  26. package/dist/src/react-menu3/hooks/useMenuState.d.ts +14 -0
  27. package/dist/src/react-menu3/hooks/useMenuStateAndFocus.d.ts +2 -0
  28. package/dist/src/react-menu3/index.d.ts +402 -0
  29. package/dist/src/react-menu3/positionUtils/getPositionHelpers.d.ts +11 -0
  30. package/dist/src/react-menu3/positionUtils/index.d.ts +3 -0
  31. package/dist/src/react-menu3/positionUtils/placeArrowHorizontal.d.ts +8 -0
  32. package/dist/src/react-menu3/positionUtils/placeArrowVertical.d.ts +8 -0
  33. package/dist/src/react-menu3/positionUtils/placeLeftorRight.d.ts +19 -0
  34. package/dist/src/react-menu3/positionUtils/placeToporBottom.d.ts +19 -0
  35. package/dist/src/react-menu3/positionUtils/positionContextMenu.d.ts +13 -0
  36. package/dist/src/react-menu3/positionUtils/positionMenu.d.ts +26 -0
  37. package/dist/src/react-menu3/style-utils/index.d.ts +11 -0
  38. package/dist/src/react-menu3/utils/constants.d.ts +92 -0
  39. package/dist/src/react-menu3/utils/index.d.ts +4 -0
  40. package/dist/src/react-menu3/utils/propTypes.d.ts +56 -0
  41. package/dist/src/react-menu3/utils/utils.d.ts +36 -0
  42. package/dist/src/react-menu3/utils/withHovering.d.ts +7 -0
  43. package/dist/src/stories/components/ReactMenu.stories.d.ts +8 -0
  44. package/dist/step-ag-grid.esm.js +1543 -2951
  45. package/dist/step-ag-grid.esm.js.map +1 -1
  46. package/package.json +22 -13
  47. package/src/components/GridLoadableCell.scss +4 -0
  48. package/src/components/GridLoadableCell.tsx +5 -1
  49. package/src/components/GridPopoverHook.tsx +4 -50
  50. package/src/components/gridForm/GridFormDropDown.tsx +3 -3
  51. package/src/components/gridForm/GridFormMultiSelect.tsx +12 -6
  52. package/src/components/gridForm/GridFormPopoutMenu.tsx +1 -1
  53. package/src/components/gridPopoverEdit/GridPopoverMenu.scss +6 -2
  54. package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +1 -1
  55. package/src/components/gridRender/GridRenderPopoutMenuCell.tsx +7 -9
  56. package/src/react-menu3/components/ControlledMenu.tsx +261 -0
  57. package/src/react-menu3/components/FocusableItem.tsx +75 -0
  58. package/src/react-menu3/components/Menu.tsx +108 -0
  59. package/src/react-menu3/components/MenuButton.tsx +34 -0
  60. package/src/react-menu3/components/MenuDivider.tsx +17 -0
  61. package/src/react-menu3/components/MenuGroup.tsx +47 -0
  62. package/src/react-menu3/components/MenuHeader.tsx +17 -0
  63. package/src/react-menu3/components/MenuItem.tsx +183 -0
  64. package/src/react-menu3/components/MenuList.tsx +502 -0
  65. package/src/react-menu3/components/MenuRadioGroup.tsx +72 -0
  66. package/src/react-menu3/components/SubMenu.tsx +349 -0
  67. package/src/react-menu3/hooks/index.ts +9 -0
  68. package/src/react-menu3/hooks/useBEM.ts +33 -0
  69. package/src/react-menu3/hooks/useCombinedRef.ts +24 -0
  70. package/src/react-menu3/hooks/useIsomorphicLayoutEffect.ts +15 -0
  71. package/src/react-menu3/hooks/useItemEffect.ts +23 -0
  72. package/src/react-menu3/hooks/useItemState.ts +67 -0
  73. package/src/react-menu3/hooks/useItems.ts +111 -0
  74. package/src/react-menu3/hooks/useMenuChange.ts +12 -0
  75. package/src/react-menu3/hooks/useMenuState.ts +42 -0
  76. package/src/react-menu3/hooks/useMenuStateAndFocus.ts +17 -0
  77. package/src/react-menu3/index.d.ts +683 -0
  78. package/src/react-menu3/index.ts +442 -0
  79. package/src/react-menu3/positionUtils/getPositionHelpers.ts +83 -0
  80. package/src/react-menu3/positionUtils/index.ts +3 -0
  81. package/src/react-menu3/positionUtils/placeArrowHorizontal.ts +15 -0
  82. package/src/react-menu3/positionUtils/placeArrowVertical.ts +15 -0
  83. package/src/react-menu3/positionUtils/placeLeftorRight.ts +92 -0
  84. package/src/react-menu3/positionUtils/placeToporBottom.ts +93 -0
  85. package/src/react-menu3/positionUtils/positionContextMenu.ts +61 -0
  86. package/src/react-menu3/positionUtils/positionMenu.ts +80 -0
  87. package/src/react-menu3/style-utils/index.ts +83 -0
  88. package/src/react-menu3/style-utils.d.ts +110 -0
  89. package/src/react-menu3/styles/_mixins.scss +11 -0
  90. package/src/react-menu3/styles/_var.scss +20 -0
  91. package/src/react-menu3/styles/core.scss +80 -0
  92. package/src/react-menu3/styles/index.scss +70 -0
  93. package/src/react-menu3/styles/theme-dark.scss +30 -0
  94. package/src/react-menu3/styles/transitions/slide.scss +47 -0
  95. package/src/react-menu3/utils/constants.ts +116 -0
  96. package/src/react-menu3/utils/index.ts +4 -0
  97. package/src/react-menu3/utils/propTypes.ts +63 -0
  98. package/src/react-menu3/utils/utils.ts +88 -0
  99. package/src/react-menu3/utils/withHovering.tsx +27 -0
  100. package/src/stories/components/GridPopoutEditDropDown.stories.tsx +1 -3
  101. package/src/stories/components/ReactMenu.stories.tsx +37 -0
  102. package/src/utils/util.ts +2 -1
@@ -0,0 +1,108 @@
1
+ import {
2
+ cloneElement,
3
+ Fragment,
4
+ forwardRef,
5
+ useRef,
6
+ useCallback,
7
+ useImperativeHandle,
8
+ ReactElement,
9
+ ForwardedRef,
10
+ } from "react";
11
+ import { ControlledMenu } from "./ControlledMenu";
12
+ import { useMenuChange, useMenuStateAndFocus, useCombinedRef } from "../hooks";
13
+ import { getName, mergeProps, safeCall, isMenuOpen, Keys, FocusPositions } from "../utils";
14
+ import { MenuButtonModifiers, RenderProp, RootMenuProps, UncontrolledMenuProps } from "../index";
15
+
16
+ //
17
+ // Menu
18
+ // ----------------------------------------------------------------------
19
+ export interface MenuProps extends RootMenuProps, UncontrolledMenuProps {
20
+ /**
21
+ * Can be a `MenuButton`, a `button` element, or a React component.
22
+ * It also can be a render function that returns one.
23
+ *
24
+ * If a React component is provided, it needs to implement the following contracts:
25
+ * - Accepts a `ref` prop that is forwarded to an element to which menu will be positioned.
26
+ * The element should be able to receive focus.
27
+ * - Accepts `onClick` and `onKeyDown` event props.
28
+ */
29
+ menuButton: RenderProp<MenuButtonModifiers, ReactElement>;
30
+ }
31
+
32
+ export function MenuFr(
33
+ { "aria-label": ariaLabel, menuButton, instanceRef, onMenuChange, ...restProps }: MenuProps,
34
+ externalRef: ForwardedRef<any>, // FIXME Matt correct type?
35
+ ) {
36
+ const [stateProps, toggleMenu, openMenu] = useMenuStateAndFocus(restProps);
37
+ const isOpen = isMenuOpen(stateProps.state);
38
+ const skipOpen = useRef(false);
39
+ const buttonRef = useRef<HTMLButtonElement>(null);
40
+
41
+ const handleClose = useCallback(
42
+ (e) => {
43
+ toggleMenu(false);
44
+ if (e.key) buttonRef.current && buttonRef.current.focus();
45
+ },
46
+ [toggleMenu],
47
+ );
48
+
49
+ const onClick = (e: MouseEvent) => {
50
+ if (skipOpen.current) return;
51
+ // Focus (hover) the first menu item when onClick event is trigger by keyboard
52
+ openMenu(e.detail === 0 ? FocusPositions.FIRST : undefined);
53
+ };
54
+
55
+ const onKeyDown = (e: KeyboardEvent) => {
56
+ switch (e.key) {
57
+ case Keys.UP:
58
+ openMenu(FocusPositions.LAST);
59
+ break;
60
+
61
+ case Keys.DOWN:
62
+ openMenu(FocusPositions.FIRST);
63
+ break;
64
+
65
+ default:
66
+ return;
67
+ }
68
+
69
+ e.preventDefault();
70
+ };
71
+
72
+ // FIXME erk! button seems to be many types
73
+ const button: any = safeCall(menuButton, { open: isOpen });
74
+ if (!button || !button.type) throw new Error("Menu requires a menuButton prop.");
75
+
76
+ const buttonProps = {
77
+ ref: useCombinedRef(button.ref, buttonRef),
78
+ ...mergeProps({ onClick, onKeyDown }, button.props),
79
+ isOpen: false,
80
+ };
81
+ if (getName(button.type) === "MenuButton") {
82
+ buttonProps.isOpen = isOpen;
83
+ }
84
+ const renderButton = cloneElement(button, buttonProps);
85
+
86
+ useMenuChange(onMenuChange, isOpen);
87
+
88
+ useImperativeHandle(instanceRef, () => ({
89
+ openMenu,
90
+ closeMenu: () => toggleMenu(false),
91
+ }));
92
+
93
+ return (
94
+ <Fragment>
95
+ {renderButton}
96
+ <ControlledMenu
97
+ {...restProps}
98
+ {...stateProps}
99
+ aria-label={ariaLabel || (typeof button.props.children === "string" ? button.props.children : "Menu")}
100
+ anchorRef={buttonRef}
101
+ ref={externalRef}
102
+ onClose={handleClose}
103
+ skipOpen={skipOpen}
104
+ />
105
+ </Fragment>
106
+ );
107
+ }
108
+ export const Menu = forwardRef(MenuFr);
@@ -0,0 +1,34 @@
1
+ import { forwardRef, LegacyRef, ReactNode, useMemo } from "react";
2
+ import { useBEM } from "../hooks";
3
+ import { menuButtonClass } from "../utils";
4
+ import { BaseProps, MenuButtonModifiers } from "../index";
5
+
6
+ export interface MenuButtonProps extends BaseProps<MenuButtonModifiers> {
7
+ disabled?: boolean;
8
+ children?: ReactNode;
9
+
10
+ // FIXME Matt added, seems to be an internal thing
11
+ isOpen?: boolean;
12
+ }
13
+
14
+ export const MenuButton = forwardRef(function MenuButton(
15
+ { className, isOpen, disabled, children, ...restProps }: MenuButtonProps,
16
+ ref: LegacyRef<HTMLButtonElement>,
17
+ ) {
18
+ const modifiers = useMemo(() => ({ open: isOpen }), [isOpen]);
19
+
20
+ return (
21
+ <button
22
+ aria-haspopup
23
+ aria-expanded={isOpen}
24
+ aria-disabled={disabled || undefined}
25
+ type="button"
26
+ disabled={disabled}
27
+ {...restProps}
28
+ ref={ref}
29
+ className={useBEM({ block: menuButtonClass, modifiers, className })}
30
+ >
31
+ {children}
32
+ </button>
33
+ );
34
+ });
@@ -0,0 +1,17 @@
1
+ import { memo, forwardRef, LegacyRef } from "react";
2
+ import { useBEM } from "../hooks";
3
+ import { menuClass, menuDividerClass } from "../utils";
4
+ import { BaseProps } from "../index";
5
+
6
+ const MenuDividerFr = ({ className, ...restProps }: BaseProps, externalRef: LegacyRef<HTMLLIElement>) => {
7
+ return (
8
+ <li
9
+ role="separator"
10
+ {...restProps}
11
+ ref={externalRef}
12
+ className={useBEM({ block: menuClass, element: menuDividerClass, className })}
13
+ />
14
+ );
15
+ };
16
+
17
+ export const MenuDivider = memo(forwardRef(MenuDividerFr)) as any as typeof MenuDividerFr;
@@ -0,0 +1,47 @@
1
+ import { ForwardedRef, forwardRef, ReactNode, useContext, useRef, useState } from "react";
2
+ import { useBEM, useLayoutEffect, useCombinedRef } from "../hooks";
3
+ import { menuClass, menuGroupClass, MenuListContext } from "../utils";
4
+ import { BaseProps, MenuOverflow } from "../index";
5
+
6
+ export interface MenuGroupProps extends BaseProps {
7
+ children?: ReactNode;
8
+ /**
9
+ * Set `true` to apply overflow of the parent menu to the group.
10
+ * Only one `MenuGroup` in a menu should set this prop as `true`.
11
+ */
12
+ takeOverflow?: boolean;
13
+ }
14
+
15
+ export const MenuGroupFr = (
16
+ { className, style, takeOverflow, ...restProps }: MenuGroupProps,
17
+ externalRef: ForwardedRef<HTMLDivElement>,
18
+ ) => {
19
+ const ref = useRef<HTMLDivElement>(null);
20
+ const [overflowStyle, setOverflowStyle] = useState<{ maxHeight?: number; overflow?: MenuOverflow }>();
21
+ const { overflow, overflowAmt } = useContext(MenuListContext);
22
+
23
+ useLayoutEffect(() => {
24
+ let maxHeight;
25
+ if (takeOverflow && overflowAmt != null && overflowAmt >= 0 && ref.current) {
26
+ // FIXME Matt added && ref.current
27
+ maxHeight = ref.current.getBoundingClientRect().height - overflowAmt;
28
+ if (maxHeight < 0) maxHeight = 0;
29
+ }
30
+ setOverflowStyle(maxHeight != null && maxHeight >= 0 ? { maxHeight, overflow } : undefined);
31
+ }, [takeOverflow, overflow, overflowAmt]);
32
+
33
+ useLayoutEffect(() => {
34
+ if (overflowStyle && ref.current) ref.current.scrollTop = 0;
35
+ }, [overflowStyle]);
36
+
37
+ return (
38
+ <div
39
+ {...restProps}
40
+ ref={useCombinedRef(externalRef, ref)} // TODO wierd refs
41
+ className={useBEM({ block: menuClass, element: menuGroupClass, className })}
42
+ style={{ ...style, ...overflowStyle }}
43
+ />
44
+ );
45
+ };
46
+
47
+ export const MenuGroup = forwardRef(MenuGroupFr);
@@ -0,0 +1,17 @@
1
+ import { memo, forwardRef, ForwardedRef } from "react";
2
+ import { useBEM } from "../hooks";
3
+ import { menuClass, menuHeaderClass } from "../utils";
4
+ import { BaseProps } from "../index";
5
+
6
+ export const MenuHeaderFr = ({ className, ...restProps }: BaseProps, externalRef: ForwardedRef<HTMLLIElement>) => {
7
+ return (
8
+ <li
9
+ role="presentation"
10
+ {...restProps}
11
+ ref={externalRef}
12
+ className={useBEM({ block: menuClass, element: menuHeaderClass, className })}
13
+ />
14
+ );
15
+ };
16
+
17
+ export const MenuHeader = memo(forwardRef(MenuHeaderFr));
@@ -0,0 +1,183 @@
1
+ import { Ref, useContext, useMemo } from "react";
2
+ import { useBEM, useItemState, useCombinedRef } from "../hooks";
3
+ import {
4
+ mergeProps,
5
+ commonProps,
6
+ safeCall,
7
+ menuClass,
8
+ menuItemClass,
9
+ withHovering,
10
+ EventHandlersContext,
11
+ RadioGroupContext,
12
+ Keys,
13
+ RMEvent,
14
+ } from "../utils";
15
+ import { BaseProps, ClickEvent, EventHandler, Hoverable, MenuItemTypeProp, RenderProp } from "../index";
16
+ import { withHoveringResultProps } from "../utils/withHovering";
17
+
18
+ //
19
+ // MenuItem
20
+ // ----------------------------------------------------------------------
21
+ export type MenuItemModifiers = Readonly<{
22
+ /**
23
+ * 'radio' for radio item, 'checkbox' for checkbox item, or `undefined` for other items.
24
+ */
25
+ type?: MenuItemTypeProp;
26
+ /**
27
+ * Indicates if the menu item is disabled.
28
+ */
29
+ disabled: boolean;
30
+ /**
31
+ * Indicates if the menu item is being hovered and has focus.
32
+ */
33
+ hover: boolean;
34
+ /**
35
+ * Indicates if the menu item is checked when it's a radio or checkbox item.
36
+ */
37
+ checked: boolean;
38
+ /**
39
+ * Indicates if the menu item has a URL link.
40
+ */
41
+ anchor: boolean;
42
+ }>;
43
+
44
+ export interface MenuItemProps extends Omit<BaseProps<MenuItemModifiers>, "onClick">, Hoverable {
45
+ /**
46
+ * Any value provided to this prop will be available in the event object of click events.
47
+ *
48
+ * It's useful for helping identify which menu item is clicked when you
49
+ * listen on `onItemClick` event on root menu component.
50
+ */
51
+ value?: any;
52
+ /**
53
+ * If provided, menu item renders an HTML `<a>` element with this `href` attribute.
54
+ */
55
+ href?: string;
56
+ rel?: string;
57
+ target?: string;
58
+ /**
59
+ * Set this prop to make the item a checkbox or radio menu item.
60
+ */
61
+ type?: MenuItemTypeProp;
62
+ /**
63
+ * Set `true` if a checkbox menu item is checked.
64
+ *
65
+ * *Please note radio menu item doesn't use this prop.*
66
+ */
67
+ checked?: boolean;
68
+ /**
69
+ * Event fired when the menu item is clicked.
70
+ */
71
+ onClick?: EventHandler<ClickEvent>;
72
+ /**
73
+ * Any valid React node or a render function that returns one.
74
+ */
75
+ children?: RenderProp<MenuItemModifiers>;
76
+ }
77
+
78
+ const MenuItemFr = ({
79
+ className,
80
+ value,
81
+ href,
82
+ type,
83
+ checked,
84
+ disabled,
85
+ children,
86
+ onClick,
87
+ isHovering,
88
+ menuItemRef,
89
+ externalRef,
90
+ ...restProps
91
+ }: MenuItemProps & withHoveringResultProps) => {
92
+ const isDisabled = !!disabled;
93
+ const { setHover, ...restStateProps } = useItemState(menuItemRef, menuItemRef, isHovering, isDisabled);
94
+ const eventHandlers = useContext(EventHandlersContext);
95
+ const radioGroup = useContext(RadioGroupContext);
96
+ const isRadio = type === "radio";
97
+ const isCheckBox = type === "checkbox";
98
+ const isAnchor = !!href && !isDisabled && !isRadio && !isCheckBox;
99
+ const isChecked = isRadio ? radioGroup.value === value : isCheckBox ? !!checked : false;
100
+
101
+ // FIXME handle click seems to be a combination of multiple event types
102
+ const handleClick = (e: any) => {
103
+ if (isDisabled) {
104
+ e.stopPropagation();
105
+ e.preventDefault();
106
+ return;
107
+ }
108
+
109
+ const event: RMEvent = {
110
+ value,
111
+ syntheticEvent: e,
112
+ };
113
+ if (e.key !== undefined) event.key = e.key;
114
+ if (isCheckBox) event.checked = !isChecked;
115
+ if (isRadio) event.name = radioGroup.name;
116
+ safeCall(onClick, event);
117
+ if (isRadio) safeCall(radioGroup.onRadioChange, event);
118
+ eventHandlers.handleClick(event, isCheckBox || isRadio);
119
+ };
120
+
121
+ const handleKeyDown = (e: KeyboardEvent) => {
122
+ if (!isHovering) return;
123
+
124
+ switch (e.key) {
125
+ case Keys.ENTER:
126
+ case Keys.SPACE:
127
+ if (isAnchor) {
128
+ menuItemRef?.current && menuItemRef.current.click();
129
+ } else {
130
+ handleClick(e);
131
+ }
132
+ break;
133
+ }
134
+ };
135
+
136
+ const modifiers = useMemo(
137
+ () => ({
138
+ type,
139
+ disabled: isDisabled,
140
+ hover: isHovering,
141
+ checked: isChecked,
142
+ anchor: isAnchor,
143
+ }),
144
+ [type, isDisabled, isHovering, isChecked, isAnchor],
145
+ );
146
+
147
+ const mergedProps = mergeProps(
148
+ {
149
+ ...restStateProps,
150
+ onPointerDown: setHover,
151
+ onKeyDown: handleKeyDown,
152
+ onClick: handleClick,
153
+ },
154
+ restProps,
155
+ );
156
+
157
+ // Order of props overriding (same in all components):
158
+ // 1. Preset props adhering to WAI-ARIA Authoring Practices.
159
+ // 2. Merged outer and local props
160
+ // 3. ref, className
161
+ const menuItemProps = {
162
+ role: isRadio ? "menuitemradio" : isCheckBox ? "menuitemcheckbox" : "menuitem",
163
+ "aria-checked": isRadio || isCheckBox ? isChecked : undefined,
164
+ ...mergedProps,
165
+ ...commonProps(isDisabled, isHovering),
166
+ ref: useCombinedRef(externalRef as Ref<any>, menuItemRef),
167
+ className: useBEM({ block: menuClass, element: menuItemClass, modifiers, className }),
168
+ children: useMemo(() => safeCall(children, modifiers), [children, modifiers]),
169
+ };
170
+
171
+ if (isAnchor) {
172
+ return (
173
+ <li role="presentation">
174
+ <a href={href} {...menuItemProps} />
175
+ </li>
176
+ );
177
+ } else {
178
+ return <li {...menuItemProps} />;
179
+ }
180
+ };
181
+
182
+ // FIXME matt as any
183
+ export const MenuItem = withHovering("MenuItem", MenuItemFr) as any as typeof MenuItemFr;