@muraldevkit/ui-toolkit 2.23.1 → 2.24.0
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/components/menu/MrlMenu/MrlMenu.d.ts +16 -11
- package/dist/components/menu/MrlMenu/utilities.d.ts +37 -0
- package/dist/components/menu/constants.d.ts +1 -1
- package/dist/components/menu/demo/MenuWithSubmenu.d.ts +20 -0
- package/dist/components/menu/demo/MenuWithTrigger.d.ts +8 -7
- package/dist/components/menu/hooks/useSubMenuElementPosition.d.ts +17 -0
- package/dist/components/portal/MrlPortal.d.ts +2 -1
- package/dist/hooks/useClickOutside/index.d.ts +3 -3
- package/dist/hooks/useTriggerPosition/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/styles/MrlMenu/module.scss +8 -7
- package/dist/styles/MrlMenuItem/module.scss +30 -18
- package/dist/styles/demo/module.scss +11 -0
- package/package.json +1 -1
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import React, { RefObject } from 'react';
|
|
2
2
|
import { MenuPosition, VerticalAlign, HorizontalAlign } from '../constants';
|
|
3
|
-
export type ActionType = 'ArrowUp' | 'ArrowDown' | 'Enter' | 'Escape' | ' ' | 'click' | null;
|
|
3
|
+
export type ActionType = 'ArrowUp' | 'ArrowDown' | 'ArrowRight' | 'Enter' | 'Escape' | ' ' | 'click' | null;
|
|
4
4
|
export interface MrlMenuState {
|
|
5
5
|
actionType: ActionType;
|
|
6
6
|
isOpen: boolean;
|
|
7
7
|
}
|
|
8
|
-
interface MrlMenuProps {
|
|
8
|
+
export interface MrlMenuProps {
|
|
9
9
|
/** Children to be rendered within the menu component*/
|
|
10
10
|
children: React.ReactNode;
|
|
11
11
|
/** Unique identifier for the menu */
|
|
12
12
|
id?: string;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Private isSubMenu prop for use with MrlMenuItem
|
|
15
|
+
*
|
|
16
|
+
* !!! Please do not use this prop directly, it is only used internally by MrlMenuItem !!!
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
14
20
|
isSubMenu?: boolean;
|
|
15
21
|
/**
|
|
16
22
|
* Kind of menu
|
|
@@ -19,6 +25,12 @@ interface MrlMenuProps {
|
|
|
19
25
|
* @default 'default'
|
|
20
26
|
*/
|
|
21
27
|
kind?: 'default' | 'compact';
|
|
28
|
+
/**
|
|
29
|
+
* Offset of the menu from the trigger element in pixels
|
|
30
|
+
*
|
|
31
|
+
* @default 10px
|
|
32
|
+
*/
|
|
33
|
+
menuOffset?: number;
|
|
22
34
|
/**
|
|
23
35
|
* Horizontal and vertical alignment of the menu relative to the trigger element
|
|
24
36
|
*
|
|
@@ -53,12 +65,6 @@ interface MrlMenuProps {
|
|
|
53
65
|
* @param type - type of close event
|
|
54
66
|
*/
|
|
55
67
|
onClose?: (type?: string) => void;
|
|
56
|
-
/**
|
|
57
|
-
* Callback to be called when the menu is opened
|
|
58
|
-
*
|
|
59
|
-
* @param type - type of close event
|
|
60
|
-
*/
|
|
61
|
-
onOpen?: (type?: string) => void;
|
|
62
68
|
}
|
|
63
69
|
/**
|
|
64
70
|
* MrlMenu component
|
|
@@ -68,5 +74,4 @@ interface MrlMenuProps {
|
|
|
68
74
|
* @param {MrlMenuProps} props - The props for the MrlMenu component
|
|
69
75
|
* @returns {Element} - rendered MrlMenu component
|
|
70
76
|
*/
|
|
71
|
-
export declare function MrlMenu({ children, id, isSubMenu, kind, menuPosition, menuState, verticalAlign, horizontalAlign, onClose,
|
|
72
|
-
export {};
|
|
77
|
+
export declare function MrlMenu({ children, id, isSubMenu, kind, menuOffset, menuPosition, menuState, verticalAlign, horizontalAlign, onClose, triggerRef }: MrlMenuProps): JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the closest menu parent of an element
|
|
3
|
+
*
|
|
4
|
+
* @param el - The element to start searching from
|
|
5
|
+
* @returns The closest menu parent or null if none is found
|
|
6
|
+
*/
|
|
7
|
+
export declare const findClosestMenuParent: (el: HTMLElement | null) => HTMLElement | null | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Find the interactive element immediately before or after a reference element
|
|
10
|
+
*
|
|
11
|
+
* @param ref - The reference element
|
|
12
|
+
* @param direction - The direction to search in
|
|
13
|
+
* @returns The interactive element or null if none is found
|
|
14
|
+
*/
|
|
15
|
+
export declare const findInteractiveElement: (ref: React.RefObject<HTMLElement> | undefined, direction?: 'next' | 'previous') => HTMLElement | null;
|
|
16
|
+
/**
|
|
17
|
+
* Calculate the horizontal positioning of the submenu
|
|
18
|
+
*
|
|
19
|
+
* @param overlapsRight - Whether the menu overlaps the right side of the screen
|
|
20
|
+
* @param overlapsLeft - Whether the menu overlaps the left side of the screen
|
|
21
|
+
* @param menuRect - The bounding rectangle of the menu
|
|
22
|
+
* @param triggerRef - The ref of the trigger element
|
|
23
|
+
* @returns The left position of the menu
|
|
24
|
+
*/
|
|
25
|
+
export declare const calculateLeftPosition: (overlapsRight: boolean, overlapsLeft: boolean, menuRect: DOMRect, triggerRef: React.RefObject<HTMLElement>) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Calculate vertical positioning of the submenu
|
|
28
|
+
*
|
|
29
|
+
* @param overlapsRight - Whether the menu overlaps the right side of the screen
|
|
30
|
+
* @param overlapsLeft - Whether the menu overlaps the left side of the screen
|
|
31
|
+
* @param triggerRef - The ref of the trigger element
|
|
32
|
+
* @param menuRect - The bounding rectangle of the menu
|
|
33
|
+
* @param parentMenu - The parent menu element
|
|
34
|
+
* @param triggerRect - The bounding rectangle of the trigger element
|
|
35
|
+
* @returns The top position of the menu
|
|
36
|
+
*/
|
|
37
|
+
export declare const calculateTopPosition: (overlapsRight: boolean, overlapsLeft: boolean, triggerRef: React.RefObject<HTMLElement>, menuRect: DOMRect, parentMenu: HTMLElement, triggerRect: DOMRect) => string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type MenuPosition = 'bottom' | 'left' | 'right' | 'top';
|
|
1
|
+
export type MenuPosition = 'bottom' | 'left' | 'right' | 'top' | 'below';
|
|
2
2
|
export type HorizontalAlign = 'left' | 'right' | 'center';
|
|
3
3
|
export type VerticalAlign = 'top' | 'bottom' | 'center';
|
|
4
4
|
export type MenuIgnore = 'ignore';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MrlMenuState } from '../';
|
|
3
|
+
import { MenuPosition, VerticalAlign, HorizontalAlign } from '../constants';
|
|
4
|
+
interface MenuWithSubmenuProps {
|
|
5
|
+
menuAlign?: MenuPosition;
|
|
6
|
+
kind?: 'default' | 'compact';
|
|
7
|
+
verticalAlign?: VerticalAlign;
|
|
8
|
+
horizontalAlign?: HorizontalAlign;
|
|
9
|
+
menuState?: MrlMenuState;
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
triggerAlignment?: 'left' | 'right' | 'center';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Demo of a menu with a trigger for stories and testing
|
|
15
|
+
*
|
|
16
|
+
* @param {MenuWithSubmenuProps} props - The props for the menu with trigger
|
|
17
|
+
* @returns {Element} The menu with trigger demo
|
|
18
|
+
*/
|
|
19
|
+
export declare const MenuWithSubmenu: ({ menuAlign, verticalAlign, horizontalAlign, kind, menuState, onClose, triggerAlignment }: MenuWithSubmenuProps) => JSX.Element;
|
|
20
|
+
export {};
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { MrlMenuState } from '../';
|
|
3
3
|
import { MenuPosition, VerticalAlign, HorizontalAlign } from '../constants';
|
|
4
4
|
interface MenuWithTriggerProps {
|
|
5
|
-
menuAlign?: MenuPosition
|
|
6
|
-
kind?: 'default' | 'compact'
|
|
7
|
-
verticalAlign
|
|
8
|
-
horizontalAlign
|
|
9
|
-
menuState?: MrlMenuState
|
|
10
|
-
onClose?: () => void
|
|
5
|
+
menuAlign?: MenuPosition;
|
|
6
|
+
kind?: 'default' | 'compact';
|
|
7
|
+
verticalAlign?: VerticalAlign;
|
|
8
|
+
horizontalAlign?: HorizontalAlign;
|
|
9
|
+
menuState?: MrlMenuState;
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
triggerAlignment?: 'left' | 'right' | 'center';
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Demo of a menu with a trigger for stories and testing
|
|
@@ -15,5 +16,5 @@ interface MenuWithTriggerProps {
|
|
|
15
16
|
* @param {MenuWithTriggerProps} props - The props for the menu with trigger
|
|
16
17
|
* @returns {Element} The menu with trigger demo
|
|
17
18
|
*/
|
|
18
|
-
export declare const MenuWithTrigger: ({ menuAlign, verticalAlign, horizontalAlign, kind, menuState, onClose }: MenuWithTriggerProps) => JSX.Element;
|
|
19
|
+
export declare const MenuWithTrigger: ({ menuAlign, verticalAlign, horizontalAlign, kind, menuState, onClose, triggerAlignment }: MenuWithTriggerProps) => JSX.Element;
|
|
19
20
|
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
interface SubMenuPosition {
|
|
3
|
+
left: string;
|
|
4
|
+
top: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the position of the sub menu element
|
|
8
|
+
*
|
|
9
|
+
* @param triggerRef - The trigger element ref
|
|
10
|
+
* @param menuRef - The menu element ref
|
|
11
|
+
* @param isSubMenu - Is the menu a sub menu
|
|
12
|
+
* @param isOpen - Is the element visible
|
|
13
|
+
* @param originalMenuRect - The menu element rect
|
|
14
|
+
* @returns The sub menu position
|
|
15
|
+
*/
|
|
16
|
+
export declare const useSubMenuElementPosition: (triggerRef: RefObject<HTMLElement> | undefined, menuRef: RefObject<HTMLDivElement>, isSubMenu: boolean, isOpen: boolean, originalMenuRect: DOMRect | null) => SubMenuPosition;
|
|
17
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface PortalProps {
|
|
3
3
|
children: React.ReactNode;
|
|
4
|
+
id?: string;
|
|
4
5
|
}
|
|
5
6
|
export declare const MRL_PORTAL_ID = "mrl-root-portal";
|
|
6
7
|
/**
|
|
@@ -10,4 +11,4 @@ export declare const MRL_PORTAL_ID = "mrl-root-portal";
|
|
|
10
11
|
* @param PortalProps Portal only takes children. Contact the platform team if you need to extend this.
|
|
11
12
|
* @returns MrlPortal component
|
|
12
13
|
*/
|
|
13
|
-
export declare const MrlPortal: ({ children }: PortalProps) => React.ReactElement | null;
|
|
14
|
+
export declare const MrlPortal: ({ children, id }: PortalProps) => React.ReactElement | null;
|
|
@@ -2,7 +2,7 @@ import { RefObject } from 'react';
|
|
|
2
2
|
/**
|
|
3
3
|
* Hook to detect clicks outside of a given DOM element.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param onOutsideClick - Function to call when a click is detected outside the
|
|
5
|
+
* @param menuRef - Reference to the DOM element that caused this menu to be shown.
|
|
6
|
+
* @param onOutsideClick - Function to call when a click is detected outside the menuRef element
|
|
7
7
|
*/
|
|
8
|
-
export declare const useClickOutside: (
|
|
8
|
+
export declare const useClickOutside: (menuRef: RefObject<HTMLElement>, onOutsideClick: () => void) => void;
|
|
@@ -7,8 +7,10 @@ import { Alignment, Position } from './constants';
|
|
|
7
7
|
*
|
|
8
8
|
* @param {RefObject<HTMLElement>} triggerRef - Reference to the DOM element that triggers the menu.
|
|
9
9
|
* @param {RefObject<HTMLElement>} elementRef - Reference to the DOM element that is the menu.
|
|
10
|
-
* @param {boolean} isElementVisible - Whether the trigger element is visible.
|
|
11
10
|
* @param {Alignment} menuAlign - The alignment configuration of the menu.
|
|
11
|
+
* @param {boolean} isElementVisible - Tells the hook if the element is visible. If false, the hook will not calculate the position.
|
|
12
|
+
* @param {number} menuOffset - The offset of the menu from the trigger element.
|
|
13
|
+
* @param disable - Whether to disable the hook.
|
|
12
14
|
* @returns {Position} The calculated position of the menu element.
|
|
13
15
|
*/
|
|
14
|
-
export declare const useTriggerPosition: (triggerRef: RefObject<HTMLElement> | undefined, elementRef: RefObject<HTMLElement>,
|
|
16
|
+
export declare const useTriggerPosition: (triggerRef: RefObject<HTMLElement> | undefined, elementRef: RefObject<HTMLElement>, menuAlign: Alignment, isElementVisible?: boolean, menuOffset?: number, disable?: boolean) => Position;
|