@muraldevkit/ui-toolkit 2.21.1 → 2.22.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.
@@ -0,0 +1,72 @@
1
+ import React, { RefObject } from 'react';
2
+ import { MenuPosition, VerticalAlign, HorizontalAlign } from '../constants';
3
+ export type ActionType = 'ArrowUp' | 'ArrowDown' | 'Enter' | 'Escape' | ' ' | 'click' | null;
4
+ export interface MrlMenuState {
5
+ actionType: ActionType;
6
+ isOpen: boolean;
7
+ }
8
+ interface MrlMenuProps {
9
+ /** Children to be rendered within the menu component*/
10
+ children: React.ReactNode;
11
+ /** Unique identifier for the menu */
12
+ id?: string;
13
+ /** If the menu is a submenu */
14
+ isSubMenu?: boolean;
15
+ /**
16
+ * Kind of menu
17
+ * - compact has less padding
18
+ *
19
+ * @default 'default'
20
+ */
21
+ kind?: 'default' | 'compact';
22
+ /**
23
+ * Horizontal and vertical alignment of the menu relative to the trigger element
24
+ *
25
+ * @default 'bottom'
26
+ */
27
+ menuPosition?: MenuPosition;
28
+ /**
29
+ * Set initial state of menu
30
+ *
31
+ * @default { actionType: null, isOpen: false }
32
+ */
33
+ menuState?: MrlMenuState;
34
+ /**
35
+ * Reference to the DOM element that triggers this menu.
36
+ */
37
+ triggerRef?: RefObject<HTMLButtonElement>;
38
+ /**
39
+ * Vertical alignment of the menu relative to the trigger element
40
+ *
41
+ * @default 'center'
42
+ */
43
+ verticalAlign?: VerticalAlign;
44
+ /**
45
+ * Horizontal alignment of the menu relative to the trigger element
46
+ *
47
+ * @default 'left'
48
+ */
49
+ horizontalAlign?: HorizontalAlign;
50
+ /**
51
+ * Callback to be called when the menu is closed
52
+ *
53
+ * @param type - type of close event
54
+ */
55
+ 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
+ }
63
+ /**
64
+ * MrlMenu component
65
+ *
66
+ * Renders a menu component with alignment relative to a trigger element
67
+ *
68
+ * @param {MrlMenuProps} props - The props for the MrlMenu component
69
+ * @returns {Element} - rendered MrlMenu component
70
+ */
71
+ export declare function MrlMenu({ children, id, isSubMenu, kind, menuPosition, menuState, verticalAlign, horizontalAlign, onClose, onOpen, triggerRef }: MrlMenuProps): JSX.Element;
72
+ export {};
@@ -0,0 +1 @@
1
+ export * from './MrlMenu';
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ export interface MrlMenuGroupPropTypes {
3
+ children: React.ReactNode;
4
+ divider?: boolean;
5
+ groupLabel: string;
6
+ }
7
+ /**
8
+ * MrlMenuGroup
9
+ *
10
+ * @param props - component properties
11
+ * @returns JSX.Element
12
+ */
13
+ export declare const MrlMenuGroup: ({ children, divider, groupLabel }: MrlMenuGroupPropTypes) => JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './MrlMenuGroup';
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ interface MrlMenuItemProps {
3
+ /** ID for associated description */
4
+ ariaDescribedBy?: string;
5
+ /**
6
+ Children to be rendered within the menu component
7
+ */
8
+ children: React.ReactNode | string;
9
+ /** If the menu item is disabled */
10
+ disabled?: boolean;
11
+ /** Unique ID for the menu item */
12
+ id?: string;
13
+ /** Callback to be called when the menu item is clicked */
14
+ onClick?: (e: React.MouseEvent<HTMLElement>) => void;
15
+ /** Data-qa attribute for the menu item */
16
+ dataQa?: string;
17
+ /** If the menu item is selected */
18
+ selected?: boolean;
19
+ }
20
+ /**
21
+ * MrlMenuItem component
22
+ *
23
+ * Renders a menu item to be used within the MrlMenu component
24
+ *
25
+ * @param {MrlMenuItemProps} props - The props for the MrlMenuItem component
26
+ * @returns {Element} - rendered MrlMenuItem component
27
+ */
28
+ export declare function MrlMenuItem({ ariaDescribedBy, children, dataQa, disabled, id, onClick, selected }: MrlMenuItemProps): JSX.Element;
29
+ export {};
@@ -0,0 +1 @@
1
+ export * from './MrlMenuItem';
@@ -0,0 +1,4 @@
1
+ export type MenuPosition = 'bottom' | 'left' | 'right' | 'top';
2
+ export type HorizontalAlign = 'left' | 'right' | 'center';
3
+ export type VerticalAlign = 'top' | 'bottom' | 'center';
4
+ export type MenuIgnore = 'ignore';
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * Demo of a menu group with a trigger for stories and testing
4
+ *
5
+ * @returns {Element} The menu group with trigger demo
6
+ */
7
+ export declare const MenuGroupWithTrigger: () => JSX.Element;
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import { MrlMenuState } from '../';
3
+ import { MenuPosition, VerticalAlign, HorizontalAlign } from '../constants';
4
+ interface MenuWithTriggerProps {
5
+ menuAlign?: MenuPosition | undefined;
6
+ kind?: 'default' | 'compact' | undefined;
7
+ verticalAlign: VerticalAlign | undefined;
8
+ horizontalAlign: HorizontalAlign | undefined;
9
+ menuState?: MrlMenuState | undefined;
10
+ onClose?: () => void | undefined;
11
+ }
12
+ /**
13
+ * Demo of a menu with a trigger for stories and testing
14
+ *
15
+ * @param {MenuWithTriggerProps} props - The props for the menu with trigger
16
+ * @returns {Element} The menu with trigger demo
17
+ */
18
+ export declare const MenuWithTrigger: ({ menuAlign, verticalAlign, horizontalAlign, kind, menuState, onClose }: MenuWithTriggerProps) => JSX.Element;
19
+ export {};
@@ -0,0 +1,17 @@
1
+ import { MenuPosition } from '../constants';
2
+ interface MenuScrollStyles {
3
+ className: string | null;
4
+ styles: AdjustedMenuStyle;
5
+ }
6
+ interface AdjustedMenuStyle {
7
+ maxHeight: string;
8
+ }
9
+ /**
10
+ * useMenuScroll hook
11
+ *
12
+ * @param menuRef - reference to the DOM element that is the menu
13
+ * @param menuAlign - the alignment of the menu
14
+ * @returns AdjustedMenuStyle - returns the new updated style for scrolling the menu
15
+ */
16
+ export declare const useMenuScroll: (menuRef: React.RefObject<HTMLElement>, menuAlign?: MenuPosition) => MenuScrollStyles;
17
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './MrlMenu';
2
+ export * from './MrlMenuItem';
3
+ export * from './MrlMenuGroup';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- export interface portalProps {
2
+ export interface PortalProps {
3
3
  children: React.ReactNode;
4
4
  }
5
5
  export declare const MRL_PORTAL_ID = "mrl-root-portal";
@@ -7,7 +7,7 @@ export declare const MRL_PORTAL_ID = "mrl-root-portal";
7
7
  * Dynamically creates a single portal and send your children to the portal.
8
8
  * Where they will live outside of the normal document flow
9
9
  *
10
- * @param portalProps Portal only takes children. Contact the platform team if you need to extend this.
10
+ * @param PortalProps Portal only takes children. Contact the platform team if you need to extend this.
11
11
  * @returns MrlPortal component
12
12
  */
13
- export declare const MrlPortal: ({ children }: portalProps) => React.ReactElement | null;
13
+ export declare const MrlPortal: ({ children }: PortalProps) => React.ReactElement | null;
@@ -0,0 +1,8 @@
1
+ import { RefObject } from 'react';
2
+ /**
3
+ * Hook to detect clicks outside of a given DOM element.
4
+ *
5
+ * @param elementRef - 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 elementRef element
7
+ */
8
+ export declare const useClickOutside: (elementRef: RefObject<HTMLElement>, onOutsideClick: () => void) => void;
@@ -0,0 +1,10 @@
1
+ import { VerticalAlign, HorizontalAlign, MenuPosition } from '../../components/menu/constants';
2
+ export interface Alignment {
3
+ vertical: VerticalAlign;
4
+ horizontal: HorizontalAlign;
5
+ align: MenuPosition;
6
+ }
7
+ export interface Position {
8
+ top: number;
9
+ left: number;
10
+ }
@@ -0,0 +1,14 @@
1
+ import { RefObject } from 'react';
2
+ import { Alignment, Position } from './constants';
3
+ /**
4
+ * useTriggerPosition hook.
5
+ *
6
+ * Calculates the position of a menu element based on the alignment settings relative to a trigger element.
7
+ *
8
+ * @param {RefObject<HTMLElement>} triggerRef - Reference to the DOM element that triggers the menu.
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
+ * @param {Alignment} menuAlign - The alignment configuration of the menu.
12
+ * @returns {Position} The calculated position of the menu element.
13
+ */
14
+ export declare const useTriggerPosition: (triggerRef: RefObject<HTMLElement> | undefined, elementRef: RefObject<HTMLElement>, isElementVisible: boolean, menuAlign: Alignment) => Position;
@@ -0,0 +1,11 @@
1
+ import { Alignment, Position } from './constants';
2
+ /**
3
+ * Position object
4
+ *
5
+ * @param triggerRect - Rect of the trigger element
6
+ * @param elementRect - Rect of the element to be positioned
7
+ * @param menuAlign - Alignment object
8
+ * @param offset - Offset value
9
+ * @returns Position object
10
+ */
11
+ export declare const calculatePosition: (triggerRect: DOMRect, elementRect: DOMRect, menuAlign: Alignment, offset: number) => Position;