carbon-react 154.13.2 → 154.13.4
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/esm/__internal__/focus-trap/focus-trap-utils.d.ts +2 -4
- package/esm/__internal__/focus-trap/focus-trap.component.d.ts +4 -7
- package/esm/__internal__/focus-trap/index.d.ts +1 -1
- package/esm/__internal__/popover/popover.component.d.ts +2 -5
- package/esm/components/date/__internal__/date-picker/date-picker.component.d.ts +2 -5
- package/esm/components/dialog/dialog.component.d.ts +3 -4
- package/esm/components/dialog-full-screen/dialog-full-screen.component.d.ts +3 -4
- package/esm/components/sidebar/sidebar.component.d.ts +2 -5
- package/esm/components/textbox/utils.d.ts +83 -0
- package/esm/components/textbox/utils.js +1 -0
- package/esm/components/vertical-menu/responsive-vertical-menu/responsive-vertical-menu.component.js +1 -1
- package/esm/hooks/__internal__/useFloating/useFloating.d.ts +2 -5
- package/lib/__internal__/focus-trap/focus-trap-utils.d.ts +2 -4
- package/lib/__internal__/focus-trap/focus-trap.component.d.ts +4 -7
- package/lib/__internal__/focus-trap/index.d.ts +1 -1
- package/lib/__internal__/popover/popover.component.d.ts +2 -5
- package/lib/components/date/__internal__/date-picker/date-picker.component.d.ts +2 -5
- package/lib/components/dialog/dialog.component.d.ts +3 -4
- package/lib/components/dialog-full-screen/dialog-full-screen.component.d.ts +3 -4
- package/lib/components/sidebar/sidebar.component.d.ts +2 -5
- package/lib/components/textbox/utils.d.ts +83 -0
- package/lib/components/textbox/utils.js +1 -0
- package/lib/components/vertical-menu/responsive-vertical-menu/responsive-vertical-menu.component.js +1 -1
- package/lib/hooks/__internal__/useFloating/useFloating.d.ts +2 -5
- package/package.json +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
current?: T | null;
|
|
3
|
-
};
|
|
1
|
+
import { RefObject } from "react";
|
|
4
2
|
declare const defaultFocusableSelectors = "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
|
|
5
3
|
declare const setElementFocus: (element: HTMLElement) => void;
|
|
6
4
|
declare const getNextElement: (element: HTMLElement, focusableElements: HTMLElement[], shiftKey: boolean) => HTMLElement | undefined;
|
|
7
|
-
declare const onTabGuardFocus: (trapWrappers:
|
|
5
|
+
declare const onTabGuardFocus: (trapWrappers: RefObject<HTMLElement>[], focusableSelectors: string | undefined, position: "top" | "bottom") => (guardWrapperRef: RefObject<HTMLElement>) => () => void;
|
|
8
6
|
declare const trapFunction: (ev: KeyboardEvent, defaultFocusableElements: HTMLElement[], isWrapperFocused: boolean, focusableSelectors?: string, bespokeTrap?: ((event: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void) | undefined) => void;
|
|
9
7
|
export { defaultFocusableSelectors, getNextElement, setElementFocus, onTabGuardFocus, trapFunction, };
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
export declare const TAB_GUARD_TOP = "tab-guard-top";
|
|
3
3
|
export declare const TAB_GUARD_BOTTOM = "tab-guard-bottom";
|
|
4
|
-
export type CustomRefObject<T> = {
|
|
5
|
-
current?: T | null;
|
|
6
|
-
};
|
|
7
4
|
export interface FocusTrapProps {
|
|
8
5
|
children: React.ReactNode;
|
|
9
6
|
autoFocus?: boolean;
|
|
10
7
|
/** provide a custom first element to focus */
|
|
11
|
-
focusFirstElement?:
|
|
8
|
+
focusFirstElement?: RefObject<HTMLElement> | HTMLElement | null;
|
|
12
9
|
/** a custom callback that will override the default focus trap behaviour */
|
|
13
10
|
bespokeTrap?: (ev: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void;
|
|
14
11
|
/** optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
15
12
|
focusableSelectors?: string;
|
|
16
13
|
/** a ref to the container wrapping the focusable elements */
|
|
17
|
-
wrapperRef:
|
|
14
|
+
wrapperRef: RefObject<HTMLElement>;
|
|
18
15
|
isOpen?: boolean;
|
|
19
16
|
/** an optional array of refs to containers whose content should also be reachable from the FocusTrap */
|
|
20
|
-
additionalWrapperRefs?:
|
|
17
|
+
additionalWrapperRefs?: RefObject<HTMLElement>[];
|
|
21
18
|
}
|
|
22
19
|
declare const FocusTrap: ({ children, autoFocus, focusableSelectors, focusFirstElement, bespokeTrap, wrapperRef, isOpen, additionalWrapperRefs, }: FocusTrapProps) => React.JSX.Element;
|
|
23
20
|
export default FocusTrap;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from "./focus-trap.component";
|
|
2
|
-
export type {
|
|
2
|
+
export type { FocusTrapProps } from "./focus-trap.component";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import React, { MutableRefObject } from "react";
|
|
1
|
+
import React, { MutableRefObject, RefObject } from "react";
|
|
2
2
|
import { Placement, Middleware } from "@floating-ui/dom";
|
|
3
|
-
type CustomRefObject<T> = {
|
|
4
|
-
current?: T | null;
|
|
5
|
-
};
|
|
6
3
|
export interface PopoverProps {
|
|
7
4
|
/**
|
|
8
5
|
* Element to be positioned, has to be a single node and has to accept `ref` and `style` props.
|
|
@@ -28,7 +25,7 @@ export interface PopoverProps {
|
|
|
28
25
|
/**
|
|
29
26
|
* Reference element, children will be positioned in relation to this element - should be a ref shaped object.
|
|
30
27
|
*/
|
|
31
|
-
reference:
|
|
28
|
+
reference: RefObject<HTMLElement>;
|
|
32
29
|
/**
|
|
33
30
|
* Determines if the popover is currently open/visible or not. Defaults to true.
|
|
34
31
|
*/
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { DayPickerProps, Modifiers } from "react-day-picker";
|
|
3
|
-
type CustomRefObject<T> = {
|
|
4
|
-
current?: T | null;
|
|
5
|
-
};
|
|
6
3
|
export interface PickerProps extends Omit<DayPickerProps, "mode" | "modifiers"> {
|
|
7
4
|
modifiers?: Partial<Modifiers>;
|
|
8
5
|
}
|
|
@@ -19,7 +16,7 @@ export interface DatePickerProps {
|
|
|
19
16
|
* */
|
|
20
17
|
pickerProps?: PickerProps;
|
|
21
18
|
/** Element that the DatePicker will be displayed under */
|
|
22
|
-
inputElement:
|
|
19
|
+
inputElement: RefObject<HTMLElement>;
|
|
23
20
|
/** Currently selected date */
|
|
24
21
|
selectedDays?: Date | undefined;
|
|
25
22
|
/** Callback to handle mousedown event on picker container */
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { ModalProps } from "../modal";
|
|
3
3
|
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
4
4
|
import { DialogSizes } from "./dialog.config";
|
|
5
|
-
import { CustomRefObject } from "../../__internal__/focus-trap";
|
|
6
5
|
declare const PADDING_VALUES: readonly [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
|
7
6
|
type PaddingValues = (typeof PADDING_VALUES)[number];
|
|
8
7
|
export interface ContentPaddingInterface {
|
|
@@ -39,7 +38,7 @@ export interface DialogProps extends ModalProps, TagProps {
|
|
|
39
38
|
*/
|
|
40
39
|
bespokeFocusTrap?: (ev: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void;
|
|
41
40
|
/** Optional reference to an element meant to be focused on open */
|
|
42
|
-
focusFirstElement?:
|
|
41
|
+
focusFirstElement?: RefObject<HTMLElement> | HTMLElement | null;
|
|
43
42
|
/** Optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
44
43
|
focusableSelectors?: string;
|
|
45
44
|
/** Allows developers to specify a specific height for the dialog. */
|
|
@@ -66,7 +65,7 @@ export interface DialogProps extends ModalProps, TagProps {
|
|
|
66
65
|
/** Change the background color of the content to grey */
|
|
67
66
|
greyBackground?: boolean;
|
|
68
67
|
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
69
|
-
focusableContainers?:
|
|
68
|
+
focusableContainers?: RefObject<HTMLElement>[];
|
|
70
69
|
/** @private @internal @ignore */
|
|
71
70
|
"data-component"?: string;
|
|
72
71
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { ModalProps } from "../modal";
|
|
3
|
-
import { CustomRefObject } from "../../__internal__/focus-trap";
|
|
4
3
|
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
5
4
|
export interface DialogFullScreenProps extends Omit<ModalProps, "disableClose"> {
|
|
6
5
|
/** Prop to specify the aria-describedby property of the DialogFullscreen component */
|
|
@@ -25,7 +24,7 @@ export interface DialogFullScreenProps extends Omit<ModalProps, "disableClose">
|
|
|
25
24
|
/** remove padding from content */
|
|
26
25
|
disableContentPadding?: boolean;
|
|
27
26
|
/** Optional reference to an element meant to be focused on open */
|
|
28
|
-
focusFirstElement?:
|
|
27
|
+
focusFirstElement?: RefObject<HTMLElement> | HTMLElement | null;
|
|
29
28
|
/**
|
|
30
29
|
* Function to replace focus trap
|
|
31
30
|
* @ignore
|
|
@@ -49,7 +48,7 @@ export interface DialogFullScreenProps extends Omit<ModalProps, "disableClose">
|
|
|
49
48
|
/** The ARIA role to be applied to the DialogFullscreen container */
|
|
50
49
|
role?: string;
|
|
51
50
|
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
52
|
-
focusableContainers?:
|
|
51
|
+
focusableContainers?: RefObject<HTMLElement>[];
|
|
53
52
|
/** Optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
54
53
|
focusableSelectors?: string;
|
|
55
54
|
/** A custom close event handler */
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { PaddingProps, WidthProps } from "styled-system";
|
|
3
3
|
import { ModalProps } from "../modal";
|
|
4
4
|
import { TagProps } from "../../__internal__/utils/helpers/tags/tags";
|
|
5
|
-
type CustomRefObject<T> = {
|
|
6
|
-
current?: T | null;
|
|
7
|
-
};
|
|
8
5
|
export interface SidebarProps extends PaddingProps, TagProps, WidthProps, Pick<ModalProps, "topModalOverride" | "restoreFocusOnClose"> {
|
|
9
6
|
/** Prop to specify the aria-describedby property of the component */
|
|
10
7
|
"aria-describedby"?: string;
|
|
@@ -47,7 +44,7 @@ export interface SidebarProps extends PaddingProps, TagProps, WidthProps, Pick<M
|
|
|
47
44
|
/** Sets the size of the sidebar when open. */
|
|
48
45
|
size?: "extra-small" | "small" | "medium-small" | "medium" | "medium-large" | "large" | "extra-large";
|
|
49
46
|
/** an optional array of refs to containers whose content should also be reachable by tabbing from the sidebar */
|
|
50
|
-
focusableContainers?:
|
|
47
|
+
focusableContainers?: RefObject<HTMLElement>[];
|
|
51
48
|
/** Optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
52
49
|
focusableSelectors?: string;
|
|
53
50
|
/** Padding to be set on the Sidebar header */
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface CommonTextboxArgs {
|
|
2
|
+
prefix: string;
|
|
3
|
+
fieldHelp: string;
|
|
4
|
+
label: string;
|
|
5
|
+
labelHelp: string;
|
|
6
|
+
placeholder: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const getCommonTextboxArgs: (isNewValidation?: boolean, autoFocusDefault?: boolean, disabledDefault?: boolean) => {
|
|
9
|
+
size: string;
|
|
10
|
+
inputIcon: undefined;
|
|
11
|
+
required: boolean;
|
|
12
|
+
characterLimit: undefined;
|
|
13
|
+
error: string;
|
|
14
|
+
warning: string;
|
|
15
|
+
fieldHelp?: string | undefined;
|
|
16
|
+
labelInline?: boolean | undefined;
|
|
17
|
+
labelWidth?: number | undefined;
|
|
18
|
+
inputWidth?: number | undefined;
|
|
19
|
+
labelAlign?: undefined;
|
|
20
|
+
tooltipId?: string | undefined;
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
readOnly: boolean;
|
|
23
|
+
autoFocus: boolean;
|
|
24
|
+
prefix: string;
|
|
25
|
+
label: string;
|
|
26
|
+
labelHelp: string;
|
|
27
|
+
placeholder: string;
|
|
28
|
+
adaptiveLabelBreakpoint: undefined;
|
|
29
|
+
};
|
|
30
|
+
export declare const getCommonTextboxArgsWithSpecialCharacters: (args: CommonTextboxArgs) => {
|
|
31
|
+
prefix: string;
|
|
32
|
+
fieldHelp: string;
|
|
33
|
+
label: string;
|
|
34
|
+
labelHelp: string;
|
|
35
|
+
helpAriaLabel: string;
|
|
36
|
+
placeholder: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const commonTextboxArgTypes: (isNewValidation?: boolean) => {
|
|
39
|
+
adaptiveLabelBreakpoint: {
|
|
40
|
+
control: {
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
labelWidth?: {
|
|
45
|
+
control: {
|
|
46
|
+
type: string;
|
|
47
|
+
min: number;
|
|
48
|
+
max: number;
|
|
49
|
+
step: number;
|
|
50
|
+
};
|
|
51
|
+
} | undefined;
|
|
52
|
+
inputWidth?: {
|
|
53
|
+
control: {
|
|
54
|
+
type: string;
|
|
55
|
+
min: number;
|
|
56
|
+
max: number;
|
|
57
|
+
step: number;
|
|
58
|
+
};
|
|
59
|
+
} | undefined;
|
|
60
|
+
tooltipId?: {
|
|
61
|
+
control: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
} | undefined;
|
|
65
|
+
size: {
|
|
66
|
+
options: string[];
|
|
67
|
+
control: {
|
|
68
|
+
type: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
inputIcon: {
|
|
72
|
+
options: string[];
|
|
73
|
+
control: {
|
|
74
|
+
type: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
labelAlign: {
|
|
78
|
+
options: string[];
|
|
79
|
+
control: {
|
|
80
|
+
type: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ICONS as e}from"../icon/icon-config.js";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e){for(var r=1;r<arguments.length;r++){var l=null!=arguments[r]?arguments[r]:{},o=Object.keys(l);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(l).filter((function(e){return Object.getOwnPropertyDescriptor(l,e).enumerable})))),o.forEach((function(r){t(e,r,l[r])}))}return e}function l(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}const o=(e=!1,t=!1,o=!1)=>l(r({disabled:o,readOnly:o,autoFocus:t,prefix:"",label:e?"Label - new validation":"Label",labelHelp:"",placeholder:"",adaptiveLabelBreakpoint:void 0},!e&&{fieldHelp:"",labelInline:!1,labelWidth:30,inputWidth:70,labelAlign:void 0,tooltipId:""}),{size:"medium",inputIcon:void 0,required:!1,characterLimit:void 0,error:"",warning:""}),n=e=>{const{prefix:t,fieldHelp:o,label:n,labelHelp:i,placeholder:p}=e;return l(r({},e),{prefix:t,fieldHelp:o,label:n,labelHelp:i,helpAriaLabel:i,placeholder:p})},i=t=>l(r({size:{options:["small","medium","large"],control:{type:"select"}},inputIcon:{options:["",...e],control:{type:"select"}},labelAlign:{options:["left","right"],control:{type:"select"}}},!t&&{labelWidth:{control:{type:"range",min:0,max:100,step:1}},inputWidth:{control:{type:"range",min:0,max:100,step:1}},tooltipId:{control:{type:"text"}}}),{adaptiveLabelBreakpoint:{control:{type:"number"}}});export{i as commonTextboxArgTypes,o as getCommonTextboxArgs,n as getCommonTextboxArgsWithSpecialCharacters};
|
package/esm/components/vertical-menu/responsive-vertical-menu/responsive-vertical-menu.component.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as r,Fragment as n}from"react/jsx-runtime";import t,{useState as o,useRef as i,useCallback as c,useLayoutEffect as s,useEffect as l}from"react";import{useResponsiveVerticalMenu as a}from"./responsive-vertical-menu.context.js";import{StyledButton as u,StyledCloseButton as
|
|
1
|
+
import{jsx as e,jsxs as r,Fragment as n}from"react/jsx-runtime";import t,{useState as o,useRef as i,useCallback as c,useLayoutEffect as s,useEffect as l}from"react";import{useResponsiveVerticalMenu as a}from"./responsive-vertical-menu.context.js";import{StyledButton as u,StyledCloseButton as d,StyledResponsiveMenu as p,StyledGlobalVerticalMenuWrapper as m}from"./responsive-vertical-menu.style.js";import{Box as v}from"../../box/box.component.js";import f from"../../modal/modal.component.js";import h from"../../../hooks/__internal__/useIsAboveBreakpoint/useIsAboveBreakpoint.js";import y from"../../../hooks/useMediaQuery/useMediaQuery.js";import b from"../../../__internal__/utils/helpers/tags/tags.js";import{DepthProvider as w}from"./__internal__/depth.context.js";import{MenuFocusProvider as g}from"./__internal__/focus.context.js";import O from"../../../hooks/__internal__/useLocale/useLocale.js";function j(e,r,n){return r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function _(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{},t=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(n).filter((function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})))),t.forEach((function(r){j(e,r,n[r])}))}return e}function x(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(r)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})),e}function k(e,r){if(null==e)return{};var n,t,o=function(e,r){if(null==e)return{};var n,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)n=i[t],r.indexOf(n)>=0||(o[n]=e[n]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(t=0;t<i.length;t++)n=i[t],r.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}const E=w=>{var g,j,{children:E,height:L,responsiveBreakpoint:M=700,width:P}=w,C=k(w,["children","height","responsiveBreakpoint","width"]);const T=O(),{activeMenuItem:B,buttonRef:I,containerRef:R,menuRef:S,responsiveMode:z,setActiveMenuItem:D,setReducedMotion:A,setResponsiveMode:q}=a(),[Q,V]=o(!1),[$,G]=o(0),F=h(M),[H,J]=o("auto"),[K,N]=o("100%"),[U,W]=o("auto"),X=i(null),Y=!y("screen and (prefers-reduced-motion: no-preference)"),{current:Z}=S,{current:ee}=I,re=c((()=>{if(Q&&z){const e=Z||document.querySelector("[id='responsive-vertical-menu-primary']");e&&N(e.getBoundingClientRect().width-16+"px")}J(B&&Z?`${Z.getBoundingClientRect().right}px`:"auto"),W(B&&ee?`${ee.getBoundingClientRect().bottom}px`:"auto")}),[Q,Z,z,B,ee]),ne=c((e=>{R.current&&!R.current.contains(e.target)&&V(!1)}),[R]),te=c((()=>{V((e=>!e)),D(null)}),[D]);s((()=>(re(),window.addEventListener("resize",re),()=>{var e;null===(e=window)||void 0===e||e.removeEventListener("resize",re)})),[Q,re,Z,z]);const oe=i(!1),ie=i(null);l((()=>{const e=()=>{oe.current=!0,null!==ie.current&&clearTimeout(ie.current),ie.current=window.setTimeout((()=>{oe.current=!1}),100)};return window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e),null!==ie.current&&clearTimeout(ie.current)}}),[]),l((()=>{const e=({relatedTarget:e,target:r})=>{R.current&&(R.current.contains(e)||null===e&&r!==I.current&&setTimeout((()=>{B||oe.current||V(!1)}),10))},r=e=>{"Escape"===e.key&&(e.preventDefault(),V(!1))},n=R.current;return Q&&!z&&(document.addEventListener("keydown",r),window.addEventListener("click",ne),null==n||n.addEventListener("focusout",e)),()=>{document.removeEventListener("keydown",r),window.removeEventListener("click",ne),null==n||n.removeEventListener("focusout",e)}}),[Q,B,I,R,ne,z]),l((()=>{null==A||A(Y),null==q||q(!F)}),[F,Y,A,q]);const ce=c((e=>{if(!e)return 0;if(t.isValidElement(e))return 1+ce(e.props.children);const r=t.Children.toArray(e);return r.length?r.reduce(((e,r)=>t.isValidElement(r)?e+1+ce(r.props.children):e),0):0}),[]);return l((()=>{const e=$,r=ce(E);e!==r&&(G(r),D(null))}),[$,E,ce,D]),r("div",{ref:R,children:[e(u,{active:Q,"aria-controls":"responsive-vertical-menu-primary","aria-expanded":Q,"aria-label":null===(g=T.verticalMenu.ariaLabels)||void 0===g?void 0:g.responsiveMenuLauncher(),buttonType:"tertiary","data-component":"responsive-vertical-menu-launcher","data-role":"responsive-vertical-menu-launcher",iconType:"squares_nine",id:"responsive-vertical-menu-launcher",onClick:te,ref:I}),z?e(f,{open:Q,children:r(v,{position:"fixed",top:0,width:K,children:[e(v,{display:"flex",justifyContent:"flex-end",width:"100%",backgroundColor:"var(--colorsGray850)",p:1,children:e(d,{"aria-label":null===(j=T.verticalMenu.ariaLabels)||void 0===j?void 0:j.responsiveMenuCloseButton(),"data-component":"responsive-vertical-menu-close","data-role":"responsive-vertical-menu-close",iconType:"close",size:"small",buttonType:"tertiary",onClick:()=>{V(!1),D(null)}})}),e(p,{height:L,id:"responsive-vertical-menu-primary",menu:"primary",reduceMotion:Y,ref:S,responsive:!0,tabIndex:-1,top:"48px",width:P,children:E})]})}):e(m,x(_({},C,b("responsive-vertical-menu",C)),{children:Q&&r(n,{children:[e(p,{childOpen:!!B,"data-component":"responsive-vertical-menu-primary","data-role":"responsive-vertical-menu-primary",height:L||"100%",id:"responsive-vertical-menu-primary",menu:"primary",reduceMotion:Y,ref:S,responsive:!1,tabIndex:-1,top:U,width:P,children:E}),B?e(p,{"data-component":"responsive-vertical-menu-secondary","data-role":"responsive-vertical-menu-secondary",height:L||"100%",id:"responsive-vertical-menu-secondary",left:H,menu:"secondary",reduceMotion:Y,ref:X,responsive:!1,tabIndex:-1,top:U,width:P,children:B.children}):null]})}))]})},L=r=>{var{children:n}=r,t=k(r,["children"]);return e(w,{children:e(g,{children:e(E,x(_({},t),{children:n}))})})};export{L as ResponsiveVerticalMenu,L as default};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { RefObject } from "react";
|
|
2
2
|
import { Strategy, Middleware, Placement } from "@floating-ui/dom";
|
|
3
|
-
type CustomRefObject<T> = {
|
|
4
|
-
current?: T | null;
|
|
5
|
-
};
|
|
6
3
|
export interface UseFloatingProps {
|
|
7
4
|
isOpen?: boolean;
|
|
8
|
-
reference:
|
|
5
|
+
reference: RefObject<HTMLElement | null>;
|
|
9
6
|
floating: React.RefObject<HTMLElement | null>;
|
|
10
7
|
strategy?: Strategy;
|
|
11
8
|
middleware?: Middleware[];
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
current?: T | null;
|
|
3
|
-
};
|
|
1
|
+
import { RefObject } from "react";
|
|
4
2
|
declare const defaultFocusableSelectors = "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
|
|
5
3
|
declare const setElementFocus: (element: HTMLElement) => void;
|
|
6
4
|
declare const getNextElement: (element: HTMLElement, focusableElements: HTMLElement[], shiftKey: boolean) => HTMLElement | undefined;
|
|
7
|
-
declare const onTabGuardFocus: (trapWrappers:
|
|
5
|
+
declare const onTabGuardFocus: (trapWrappers: RefObject<HTMLElement>[], focusableSelectors: string | undefined, position: "top" | "bottom") => (guardWrapperRef: RefObject<HTMLElement>) => () => void;
|
|
8
6
|
declare const trapFunction: (ev: KeyboardEvent, defaultFocusableElements: HTMLElement[], isWrapperFocused: boolean, focusableSelectors?: string, bespokeTrap?: ((event: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void) | undefined) => void;
|
|
9
7
|
export { defaultFocusableSelectors, getNextElement, setElementFocus, onTabGuardFocus, trapFunction, };
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
export declare const TAB_GUARD_TOP = "tab-guard-top";
|
|
3
3
|
export declare const TAB_GUARD_BOTTOM = "tab-guard-bottom";
|
|
4
|
-
export type CustomRefObject<T> = {
|
|
5
|
-
current?: T | null;
|
|
6
|
-
};
|
|
7
4
|
export interface FocusTrapProps {
|
|
8
5
|
children: React.ReactNode;
|
|
9
6
|
autoFocus?: boolean;
|
|
10
7
|
/** provide a custom first element to focus */
|
|
11
|
-
focusFirstElement?:
|
|
8
|
+
focusFirstElement?: RefObject<HTMLElement> | HTMLElement | null;
|
|
12
9
|
/** a custom callback that will override the default focus trap behaviour */
|
|
13
10
|
bespokeTrap?: (ev: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void;
|
|
14
11
|
/** optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
15
12
|
focusableSelectors?: string;
|
|
16
13
|
/** a ref to the container wrapping the focusable elements */
|
|
17
|
-
wrapperRef:
|
|
14
|
+
wrapperRef: RefObject<HTMLElement>;
|
|
18
15
|
isOpen?: boolean;
|
|
19
16
|
/** an optional array of refs to containers whose content should also be reachable from the FocusTrap */
|
|
20
|
-
additionalWrapperRefs?:
|
|
17
|
+
additionalWrapperRefs?: RefObject<HTMLElement>[];
|
|
21
18
|
}
|
|
22
19
|
declare const FocusTrap: ({ children, autoFocus, focusableSelectors, focusFirstElement, bespokeTrap, wrapperRef, isOpen, additionalWrapperRefs, }: FocusTrapProps) => React.JSX.Element;
|
|
23
20
|
export default FocusTrap;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from "./focus-trap.component";
|
|
2
|
-
export type {
|
|
2
|
+
export type { FocusTrapProps } from "./focus-trap.component";
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import React, { MutableRefObject } from "react";
|
|
1
|
+
import React, { MutableRefObject, RefObject } from "react";
|
|
2
2
|
import { Placement, Middleware } from "@floating-ui/dom";
|
|
3
|
-
type CustomRefObject<T> = {
|
|
4
|
-
current?: T | null;
|
|
5
|
-
};
|
|
6
3
|
export interface PopoverProps {
|
|
7
4
|
/**
|
|
8
5
|
* Element to be positioned, has to be a single node and has to accept `ref` and `style` props.
|
|
@@ -28,7 +25,7 @@ export interface PopoverProps {
|
|
|
28
25
|
/**
|
|
29
26
|
* Reference element, children will be positioned in relation to this element - should be a ref shaped object.
|
|
30
27
|
*/
|
|
31
|
-
reference:
|
|
28
|
+
reference: RefObject<HTMLElement>;
|
|
32
29
|
/**
|
|
33
30
|
* Determines if the popover is currently open/visible or not. Defaults to true.
|
|
34
31
|
*/
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { DayPickerProps, Modifiers } from "react-day-picker";
|
|
3
|
-
type CustomRefObject<T> = {
|
|
4
|
-
current?: T | null;
|
|
5
|
-
};
|
|
6
3
|
export interface PickerProps extends Omit<DayPickerProps, "mode" | "modifiers"> {
|
|
7
4
|
modifiers?: Partial<Modifiers>;
|
|
8
5
|
}
|
|
@@ -19,7 +16,7 @@ export interface DatePickerProps {
|
|
|
19
16
|
* */
|
|
20
17
|
pickerProps?: PickerProps;
|
|
21
18
|
/** Element that the DatePicker will be displayed under */
|
|
22
|
-
inputElement:
|
|
19
|
+
inputElement: RefObject<HTMLElement>;
|
|
23
20
|
/** Currently selected date */
|
|
24
21
|
selectedDays?: Date | undefined;
|
|
25
22
|
/** Callback to handle mousedown event on picker container */
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { ModalProps } from "../modal";
|
|
3
3
|
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
4
4
|
import { DialogSizes } from "./dialog.config";
|
|
5
|
-
import { CustomRefObject } from "../../__internal__/focus-trap";
|
|
6
5
|
declare const PADDING_VALUES: readonly [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
|
7
6
|
type PaddingValues = (typeof PADDING_VALUES)[number];
|
|
8
7
|
export interface ContentPaddingInterface {
|
|
@@ -39,7 +38,7 @@ export interface DialogProps extends ModalProps, TagProps {
|
|
|
39
38
|
*/
|
|
40
39
|
bespokeFocusTrap?: (ev: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void;
|
|
41
40
|
/** Optional reference to an element meant to be focused on open */
|
|
42
|
-
focusFirstElement?:
|
|
41
|
+
focusFirstElement?: RefObject<HTMLElement> | HTMLElement | null;
|
|
43
42
|
/** Optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
44
43
|
focusableSelectors?: string;
|
|
45
44
|
/** Allows developers to specify a specific height for the dialog. */
|
|
@@ -66,7 +65,7 @@ export interface DialogProps extends ModalProps, TagProps {
|
|
|
66
65
|
/** Change the background color of the content to grey */
|
|
67
66
|
greyBackground?: boolean;
|
|
68
67
|
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
69
|
-
focusableContainers?:
|
|
68
|
+
focusableContainers?: RefObject<HTMLElement>[];
|
|
70
69
|
/** @private @internal @ignore */
|
|
71
70
|
"data-component"?: string;
|
|
72
71
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { ModalProps } from "../modal";
|
|
3
|
-
import { CustomRefObject } from "../../__internal__/focus-trap";
|
|
4
3
|
import { TagProps } from "../../__internal__/utils/helpers/tags";
|
|
5
4
|
export interface DialogFullScreenProps extends Omit<ModalProps, "disableClose"> {
|
|
6
5
|
/** Prop to specify the aria-describedby property of the DialogFullscreen component */
|
|
@@ -25,7 +24,7 @@ export interface DialogFullScreenProps extends Omit<ModalProps, "disableClose">
|
|
|
25
24
|
/** remove padding from content */
|
|
26
25
|
disableContentPadding?: boolean;
|
|
27
26
|
/** Optional reference to an element meant to be focused on open */
|
|
28
|
-
focusFirstElement?:
|
|
27
|
+
focusFirstElement?: RefObject<HTMLElement> | HTMLElement | null;
|
|
29
28
|
/**
|
|
30
29
|
* Function to replace focus trap
|
|
31
30
|
* @ignore
|
|
@@ -49,7 +48,7 @@ export interface DialogFullScreenProps extends Omit<ModalProps, "disableClose">
|
|
|
49
48
|
/** The ARIA role to be applied to the DialogFullscreen container */
|
|
50
49
|
role?: string;
|
|
51
50
|
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
52
|
-
focusableContainers?:
|
|
51
|
+
focusableContainers?: RefObject<HTMLElement>[];
|
|
53
52
|
/** Optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
54
53
|
focusableSelectors?: string;
|
|
55
54
|
/** A custom close event handler */
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { RefObject } from "react";
|
|
2
2
|
import { PaddingProps, WidthProps } from "styled-system";
|
|
3
3
|
import { ModalProps } from "../modal";
|
|
4
4
|
import { TagProps } from "../../__internal__/utils/helpers/tags/tags";
|
|
5
|
-
type CustomRefObject<T> = {
|
|
6
|
-
current?: T | null;
|
|
7
|
-
};
|
|
8
5
|
export interface SidebarProps extends PaddingProps, TagProps, WidthProps, Pick<ModalProps, "topModalOverride" | "restoreFocusOnClose"> {
|
|
9
6
|
/** Prop to specify the aria-describedby property of the component */
|
|
10
7
|
"aria-describedby"?: string;
|
|
@@ -47,7 +44,7 @@ export interface SidebarProps extends PaddingProps, TagProps, WidthProps, Pick<M
|
|
|
47
44
|
/** Sets the size of the sidebar when open. */
|
|
48
45
|
size?: "extra-small" | "small" | "medium-small" | "medium" | "medium-large" | "large" | "extra-large";
|
|
49
46
|
/** an optional array of refs to containers whose content should also be reachable by tabbing from the sidebar */
|
|
50
|
-
focusableContainers?:
|
|
47
|
+
focusableContainers?: RefObject<HTMLElement>[];
|
|
51
48
|
/** Optional selector to identify the focusable elements, if not provided a default selector is used */
|
|
52
49
|
focusableSelectors?: string;
|
|
53
50
|
/** Padding to be set on the Sidebar header */
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface CommonTextboxArgs {
|
|
2
|
+
prefix: string;
|
|
3
|
+
fieldHelp: string;
|
|
4
|
+
label: string;
|
|
5
|
+
labelHelp: string;
|
|
6
|
+
placeholder: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const getCommonTextboxArgs: (isNewValidation?: boolean, autoFocusDefault?: boolean, disabledDefault?: boolean) => {
|
|
9
|
+
size: string;
|
|
10
|
+
inputIcon: undefined;
|
|
11
|
+
required: boolean;
|
|
12
|
+
characterLimit: undefined;
|
|
13
|
+
error: string;
|
|
14
|
+
warning: string;
|
|
15
|
+
fieldHelp?: string | undefined;
|
|
16
|
+
labelInline?: boolean | undefined;
|
|
17
|
+
labelWidth?: number | undefined;
|
|
18
|
+
inputWidth?: number | undefined;
|
|
19
|
+
labelAlign?: undefined;
|
|
20
|
+
tooltipId?: string | undefined;
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
readOnly: boolean;
|
|
23
|
+
autoFocus: boolean;
|
|
24
|
+
prefix: string;
|
|
25
|
+
label: string;
|
|
26
|
+
labelHelp: string;
|
|
27
|
+
placeholder: string;
|
|
28
|
+
adaptiveLabelBreakpoint: undefined;
|
|
29
|
+
};
|
|
30
|
+
export declare const getCommonTextboxArgsWithSpecialCharacters: (args: CommonTextboxArgs) => {
|
|
31
|
+
prefix: string;
|
|
32
|
+
fieldHelp: string;
|
|
33
|
+
label: string;
|
|
34
|
+
labelHelp: string;
|
|
35
|
+
helpAriaLabel: string;
|
|
36
|
+
placeholder: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const commonTextboxArgTypes: (isNewValidation?: boolean) => {
|
|
39
|
+
adaptiveLabelBreakpoint: {
|
|
40
|
+
control: {
|
|
41
|
+
type: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
labelWidth?: {
|
|
45
|
+
control: {
|
|
46
|
+
type: string;
|
|
47
|
+
min: number;
|
|
48
|
+
max: number;
|
|
49
|
+
step: number;
|
|
50
|
+
};
|
|
51
|
+
} | undefined;
|
|
52
|
+
inputWidth?: {
|
|
53
|
+
control: {
|
|
54
|
+
type: string;
|
|
55
|
+
min: number;
|
|
56
|
+
max: number;
|
|
57
|
+
step: number;
|
|
58
|
+
};
|
|
59
|
+
} | undefined;
|
|
60
|
+
tooltipId?: {
|
|
61
|
+
control: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
} | undefined;
|
|
65
|
+
size: {
|
|
66
|
+
options: string[];
|
|
67
|
+
control: {
|
|
68
|
+
type: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
inputIcon: {
|
|
72
|
+
options: string[];
|
|
73
|
+
control: {
|
|
74
|
+
type: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
labelAlign: {
|
|
78
|
+
options: string[];
|
|
79
|
+
control: {
|
|
80
|
+
type: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("../icon/icon-config.js");function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{},l=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(l=l.concat(Object.getOwnPropertySymbols(o).filter((function(e){return Object.getOwnPropertyDescriptor(o,e).enumerable})))),l.forEach((function(r){t(e,r,o[r])}))}return e}function o(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}exports.commonTextboxArgTypes=t=>o(r({size:{options:["small","medium","large"],control:{type:"select"}},inputIcon:{options:["",...e.ICONS],control:{type:"select"}},labelAlign:{options:["left","right"],control:{type:"select"}}},!t&&{labelWidth:{control:{type:"range",min:0,max:100,step:1}},inputWidth:{control:{type:"range",min:0,max:100,step:1}},tooltipId:{control:{type:"text"}}}),{adaptiveLabelBreakpoint:{control:{type:"number"}}}),exports.getCommonTextboxArgs=(e=!1,t=!1,l=!1)=>o(r({disabled:l,readOnly:l,autoFocus:t,prefix:"",label:e?"Label - new validation":"Label",labelHelp:"",placeholder:"",adaptiveLabelBreakpoint:void 0},!e&&{fieldHelp:"",labelInline:!1,labelWidth:30,inputWidth:70,labelAlign:void 0,tooltipId:""}),{size:"medium",inputIcon:void 0,required:!1,characterLimit:void 0,error:"",warning:""}),exports.getCommonTextboxArgsWithSpecialCharacters=e=>{const{prefix:t,fieldHelp:l,label:n,labelHelp:i,placeholder:p}=e;return o(r({},e),{prefix:t,fieldHelp:l,label:n,labelHelp:i,helpAriaLabel:i,placeholder:p})};
|
package/lib/components/vertical-menu/responsive-vertical-menu/responsive-vertical-menu.component.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),t=require("./responsive-vertical-menu.context.js"),n=require("./responsive-vertical-menu.style.js"),i=require("../../box/box.component.js"),o=require("../../modal/modal.component.js"),s=require("../../../hooks/__internal__/useIsAboveBreakpoint/useIsAboveBreakpoint.js"),u=require("../../../hooks/useMediaQuery/useMediaQuery.js"),l=require("../../../__internal__/utils/helpers/tags/tags.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),t=require("./responsive-vertical-menu.context.js"),n=require("./responsive-vertical-menu.style.js"),i=require("../../box/box.component.js"),o=require("../../modal/modal.component.js"),s=require("../../../hooks/__internal__/useIsAboveBreakpoint/useIsAboveBreakpoint.js"),u=require("../../../hooks/useMediaQuery/useMediaQuery.js"),l=require("../../../__internal__/utils/helpers/tags/tags.js"),c=require("./__internal__/depth.context.js"),a=require("./__internal__/focus.context.js"),d=require("../../../hooks/__internal__/useLocale/useLocale.js");function p(e){return e&&e.__esModule?e:{default:e}}var v=p(r);function f(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function m(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),n.forEach((function(r){f(e,r,t[r])}))}return e}function y(e,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})),e}function h(e,r){if(null==e)return{};var t,n,i=function(e,r){if(null==e)return{};var t,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t=o[n],r.indexOf(t)>=0||(i[t]=e[t]);return i}(e,r);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)t=o[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}const b=c=>{var a,p,{children:f,height:b,responsiveBreakpoint:j=700,width:x}=c,w=h(c,["children","height","responsiveBreakpoint","width"]);const g=d.default(),{activeMenuItem:O,buttonRef:_,containerRef:M,menuRef:k,responsiveMode:E,setActiveMenuItem:S,setReducedMotion:L,setResponsiveMode:P}=t.useResponsiveVerticalMenu(),[R,q]=r.useState(!1),[C,B]=r.useState(0),T=s.default(j),[I,D]=r.useState("auto"),[z,V]=r.useState("100%"),[A,F]=r.useState("auto"),G=r.useRef(null),Q=!u.default("screen and (prefers-reduced-motion: no-preference)"),{current:$}=k,{current:W}=_,H=r.useCallback((()=>{if(R&&E){const e=$||document.querySelector("[id='responsive-vertical-menu-primary']");e&&V(e.getBoundingClientRect().width-16+"px")}D(O&&$?`${$.getBoundingClientRect().right}px`:"auto"),F(O&&W?`${W.getBoundingClientRect().bottom}px`:"auto")}),[R,$,E,O,W]),J=r.useCallback((e=>{M.current&&!M.current.contains(e.target)&&q(!1)}),[M]),K=r.useCallback((()=>{q((e=>!e)),S(null)}),[S]);r.useLayoutEffect((()=>(H(),window.addEventListener("resize",H),()=>{var e;null===(e=window)||void 0===e||e.removeEventListener("resize",H)})),[R,H,$,E]);const N=r.useRef(!1),U=r.useRef(null);r.useEffect((()=>{const e=()=>{N.current=!0,null!==U.current&&clearTimeout(U.current),U.current=window.setTimeout((()=>{N.current=!1}),100)};return window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e),null!==U.current&&clearTimeout(U.current)}}),[]),r.useEffect((()=>{const e=({relatedTarget:e,target:r})=>{M.current&&(M.current.contains(e)||null===e&&r!==_.current&&setTimeout((()=>{O||N.current||q(!1)}),10))},r=e=>{"Escape"===e.key&&(e.preventDefault(),q(!1))},t=M.current;return R&&!E&&(document.addEventListener("keydown",r),window.addEventListener("click",J),null==t||t.addEventListener("focusout",e)),()=>{document.removeEventListener("keydown",r),window.removeEventListener("click",J),null==t||t.removeEventListener("focusout",e)}}),[R,O,_,M,J,E]),r.useEffect((()=>{null==L||L(Q),null==P||P(!T)}),[T,Q,L,P]);const X=r.useCallback((e=>{if(!e)return 0;if(v.default.isValidElement(e))return 1+X(e.props.children);const r=v.default.Children.toArray(e);return r.length?r.reduce(((e,r)=>v.default.isValidElement(r)?e+1+X(r.props.children):e),0):0}),[]);return r.useEffect((()=>{const e=C,r=X(f);e!==r&&(B(r),S(null))}),[C,f,X,S]),e.jsxs("div",{ref:M,children:[e.jsx(n.StyledButton,{active:R,"aria-controls":"responsive-vertical-menu-primary","aria-expanded":R,"aria-label":null===(a=g.verticalMenu.ariaLabels)||void 0===a?void 0:a.responsiveMenuLauncher(),buttonType:"tertiary","data-component":"responsive-vertical-menu-launcher","data-role":"responsive-vertical-menu-launcher",iconType:"squares_nine",id:"responsive-vertical-menu-launcher",onClick:K,ref:_}),E?e.jsx(o.default,{open:R,children:e.jsxs(i.Box,{position:"fixed",top:0,width:z,children:[e.jsx(i.Box,{display:"flex",justifyContent:"flex-end",width:"100%",backgroundColor:"var(--colorsGray850)",p:1,children:e.jsx(n.StyledCloseButton,{"aria-label":null===(p=g.verticalMenu.ariaLabels)||void 0===p?void 0:p.responsiveMenuCloseButton(),"data-component":"responsive-vertical-menu-close","data-role":"responsive-vertical-menu-close",iconType:"close",size:"small",buttonType:"tertiary",onClick:()=>{q(!1),S(null)}})}),e.jsx(n.StyledResponsiveMenu,{height:b,id:"responsive-vertical-menu-primary",menu:"primary",reduceMotion:Q,ref:k,responsive:!0,tabIndex:-1,top:"48px",width:x,children:f})]})}):e.jsx(n.StyledGlobalVerticalMenuWrapper,y(m({},w,l.default("responsive-vertical-menu",w)),{children:R&&e.jsxs(e.Fragment,{children:[e.jsx(n.StyledResponsiveMenu,{childOpen:!!O,"data-component":"responsive-vertical-menu-primary","data-role":"responsive-vertical-menu-primary",height:b||"100%",id:"responsive-vertical-menu-primary",menu:"primary",reduceMotion:Q,ref:k,responsive:!1,tabIndex:-1,top:A,width:x,children:f}),O?e.jsx(n.StyledResponsiveMenu,{"data-component":"responsive-vertical-menu-secondary","data-role":"responsive-vertical-menu-secondary",height:b||"100%",id:"responsive-vertical-menu-secondary",left:I,menu:"secondary",reduceMotion:Q,ref:G,responsive:!1,tabIndex:-1,top:A,width:x,children:O.children}):null]})}))]})},j=r=>{var{children:t}=r,n=h(r,["children"]);return e.jsx(c.DepthProvider,{children:e.jsx(a.MenuFocusProvider,{children:e.jsx(b,y(m({},n),{children:t}))})})};exports.ResponsiveVerticalMenu=j,exports.default=j;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { RefObject } from "react";
|
|
2
2
|
import { Strategy, Middleware, Placement } from "@floating-ui/dom";
|
|
3
|
-
type CustomRefObject<T> = {
|
|
4
|
-
current?: T | null;
|
|
5
|
-
};
|
|
6
3
|
export interface UseFloatingProps {
|
|
7
4
|
isOpen?: boolean;
|
|
8
|
-
reference:
|
|
5
|
+
reference: RefObject<HTMLElement | null>;
|
|
9
6
|
floating: React.RefObject<HTMLElement | null>;
|
|
10
7
|
strategy?: Strategy;
|
|
11
8
|
middleware?: Middleware[];
|