@lumx/react 2.2.16 → 2.2.18
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/FlexBox.js.map +1 -1
- package/esm/_internal/SideNavigationItem.js +8 -4
- package/esm/_internal/SideNavigationItem.js.map +1 -1
- package/esm/_internal/Tooltip2.js +7 -5
- package/esm/_internal/Tooltip2.js.map +1 -1
- package/esm/_internal/components.js +1 -0
- package/esm/_internal/components.js.map +1 -1
- package/esm/_internal/useFocusTrap.js +18 -12
- package/esm/_internal/useFocusTrap.js.map +1 -1
- package/package.json +4 -4
- package/src/components/dialog/Dialog.stories.tsx +3 -1
- package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +10 -0
- package/src/components/flex-box/FlexBox.stories.tsx +28 -2
- package/src/components/flex-box/FlexBox.tsx +1 -1
- package/src/components/flex-box/__snapshots__/FlexBox.test.tsx.snap +80 -0
- package/src/components/index.ts +1 -0
- package/src/components/side-navigation/SideNavigation.stories.tsx +26 -0
- package/src/components/side-navigation/SideNavigationItem.test.tsx +19 -2
- package/src/components/side-navigation/SideNavigationItem.tsx +10 -2
- package/src/components/side-navigation/__snapshots__/SideNavigationItem.test.tsx.snap +1 -1
- package/src/components/tooltip/useTooltipOpen.tsx +7 -4
- package/src/hooks/useFocusTrap.ts +32 -12
- package/types.d.ts +7 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlexBox.js","sources":["../../../src/components/flex-box/FlexBox.tsx"],"sourcesContent":["import { Alignment, HorizontalAlignment, Orientation, VerticalAlignment } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport classNames from 'classnames';\nimport castArray from 'lodash/castArray';\nimport React, { forwardRef, ReactNode } from 'react';\nimport { Size } from '..';\n\nexport type MarginAutoAlignment = Extract<Alignment, 'top' | 'bottom' | 'right' | 'left'>;\nexport type GapSize = Extract<Size, 'regular' | 'big' | 'huge'>;\n\n/**\n * Defines the props of the component.\n */\nexport interface FlexBoxProps extends GenericProps {\n /** Children elements. */\n children?: ReactNode;\n /** Whether the \"content filling space\" is enabled or not. */\n fillSpace?: boolean;\n /** Gap space between flexbox items. */\n gap?: GapSize;\n /** Flex horizontal alignment. */\n hAlign?: VerticalAlignment;\n /** Whether the \"auto margin\" is enabled all around or not. */\n marginAuto?: MarginAutoAlignment | MarginAutoAlignment[];\n /** Whether the \"content shrink\" is disabled or not. */\n noShrink?: boolean;\n /** Flex direction. */\n orientation?: Orientation;\n /** Flex vertical alignment. */\n vAlign?: HorizontalAlignment;\n /** Whether the \"flex wrap\" is enabled or not. */\n wrap?: boolean;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'FlexBox';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * FlexBox component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const FlexBox: Comp<FlexBoxProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n children,\n className,\n fillSpace,\n gap,\n hAlign,\n marginAuto,\n noShrink,\n orientation,\n vAlign,\n wrap,\n ...forwardedProps\n } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n orientation: orientation ?? (wrap || hAlign || vAlign ? Orientation.horizontal : null),\n vAlign,\n hAlign,\n gap,\n }),\n wrap && `${CLASSNAME}--wrap`,\n fillSpace && `${CLASSNAME}--fill-space`,\n noShrink && `${CLASSNAME}--no-shrink`,\n marginAuto && castArray(marginAuto).map((align) => `${CLASSNAME}--margin-auto-${align}`),\n )}\n >\n {children}\n </div>\n );\n});\nFlexBox.displayName = COMPONENT_NAME;\nFlexBox.className = CLASSNAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","FlexBox","forwardRef","props","ref","children","className","fillSpace","gap","hAlign","marginAuto","noShrink","orientation","vAlign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;AALe,KAAD,CAFD,EASjBM,IAAI,cAAOf,SAAP,WATa,EAUjBQ,SAAS,cAAOR,SAAP,iBAVQ,EAWjBY,QAAQ,cAAOZ,SAAP,gBAXS,EAYjBW,UAAU,IAAIW,SAAS,CAACX,UAAD,CAAT,CAAsBY,GAAtB,CAA0B,UAACC,KAAD;AAAA,uBAAcxB,SAAd,2BAAwCwB,KAAxC;AAAA,KAA1B,CAZG;AAHzB,MAkBKlB,QAlBL,CADJ;AAsBH,CArCoE;AAsCrEJ,OAAO,CAACuB,WAAR,GAAsB1B,cAAtB;AACAG,OAAO,CAACK,SAAR,GAAoBP,SAApB;;;;"}
|
|
1
|
+
{"version":3,"file":"FlexBox.js","sources":["../../../src/components/flex-box/FlexBox.tsx"],"sourcesContent":["import { Alignment, HorizontalAlignment, Orientation, VerticalAlignment } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport classNames from 'classnames';\nimport castArray from 'lodash/castArray';\nimport React, { forwardRef, ReactNode } from 'react';\nimport { Size } from '..';\n\nexport type MarginAutoAlignment = Extract<Alignment, 'top' | 'bottom' | 'right' | 'left'>;\nexport type GapSize = Extract<Size, 'regular' | 'medium' | 'big' | 'huge'>;\n\n/**\n * Defines the props of the component.\n */\nexport interface FlexBoxProps extends GenericProps {\n /** Children elements. */\n children?: ReactNode;\n /** Whether the \"content filling space\" is enabled or not. */\n fillSpace?: boolean;\n /** Gap space between flexbox items. */\n gap?: GapSize;\n /** Flex horizontal alignment. */\n hAlign?: VerticalAlignment;\n /** Whether the \"auto margin\" is enabled all around or not. */\n marginAuto?: MarginAutoAlignment | MarginAutoAlignment[];\n /** Whether the \"content shrink\" is disabled or not. */\n noShrink?: boolean;\n /** Flex direction. */\n orientation?: Orientation;\n /** Flex vertical alignment. */\n vAlign?: HorizontalAlignment;\n /** Whether the \"flex wrap\" is enabled or not. */\n wrap?: boolean;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'FlexBox';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * FlexBox component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const FlexBox: Comp<FlexBoxProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n children,\n className,\n fillSpace,\n gap,\n hAlign,\n marginAuto,\n noShrink,\n orientation,\n vAlign,\n wrap,\n ...forwardedProps\n } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n orientation: orientation ?? (wrap || hAlign || vAlign ? Orientation.horizontal : null),\n vAlign,\n hAlign,\n gap,\n }),\n wrap && `${CLASSNAME}--wrap`,\n fillSpace && `${CLASSNAME}--fill-space`,\n noShrink && `${CLASSNAME}--no-shrink`,\n marginAuto && castArray(marginAuto).map((align) => `${CLASSNAME}--margin-auto-${align}`),\n )}\n >\n {children}\n </div>\n );\n});\nFlexBox.displayName = COMPONENT_NAME;\nFlexBox.className = CLASSNAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","FlexBox","forwardRef","props","ref","children","className","fillSpace","gap","hAlign","marginAuto","noShrink","orientation","vAlign","wrap","forwardedProps","classNames","handleBasicClasses","prefix","Orientation","horizontal","castArray","map","align","displayName"],"mappings":";;;;;;AAkCA;;;AAGA,IAAMA,cAAc,GAAG,SAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;;;;;IAOaG,OAA2C,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAE9EC,QAF8E,GAa9EF,KAb8E,CAE9EE,QAF8E;AAAA,MAG9EC,SAH8E,GAa9EH,KAb8E,CAG9EG,SAH8E;AAAA,MAI9EC,SAJ8E,GAa9EJ,KAb8E,CAI9EI,SAJ8E;AAAA,MAK9EC,GAL8E,GAa9EL,KAb8E,CAK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
|
|
65
65
|
*/
|
|
66
66
|
|
|
67
67
|
var DEFAULT_PROPS = {
|
|
68
|
-
emphasis: Emphasis.high
|
|
68
|
+
emphasis: Emphasis.high,
|
|
69
|
+
closeMode: 'unmount'
|
|
69
70
|
};
|
|
70
71
|
/**
|
|
71
72
|
* SideNavigationItem component.
|
|
@@ -88,17 +89,20 @@ var SideNavigationItem = forwardRef(function (props, ref) {
|
|
|
88
89
|
onActionClick = props.onActionClick,
|
|
89
90
|
onClick = props.onClick,
|
|
90
91
|
toggleButtonProps = props.toggleButtonProps,
|
|
91
|
-
|
|
92
|
+
_props$closeMode = props.closeMode,
|
|
93
|
+
closeMode = _props$closeMode === void 0 ? 'unmount' : _props$closeMode,
|
|
94
|
+
forwardedProps = _objectWithoutProperties(props, ["children", "className", "emphasis", "icon", "isOpen", "isSelected", "label", "linkAs", "linkProps", "onActionClick", "onClick", "toggleButtonProps", "closeMode"]);
|
|
92
95
|
|
|
93
96
|
var content = children && Children.toArray(children).filter(isComponent(SideNavigationItem));
|
|
94
97
|
var hasContent = !isEmpty(content);
|
|
95
98
|
var shouldSplitActions = Boolean(onActionClick);
|
|
99
|
+
var showChildren = hasContent && isOpen;
|
|
96
100
|
return React.createElement("li", _extends({
|
|
97
101
|
ref: ref
|
|
98
102
|
}, forwardedProps, {
|
|
99
103
|
className: classnames(className, handleBasicClasses({
|
|
100
104
|
emphasis: emphasis,
|
|
101
|
-
isOpen:
|
|
105
|
+
isOpen: showChildren,
|
|
102
106
|
isSelected: isSelected,
|
|
103
107
|
prefix: CLASSNAME$1
|
|
104
108
|
}))
|
|
@@ -135,7 +139,7 @@ var SideNavigationItem = forwardRef(function (props, ref) {
|
|
|
135
139
|
className: "".concat(CLASSNAME$1, "__chevron"),
|
|
136
140
|
icon: isOpen ? mdiChevronUp : mdiChevronDown,
|
|
137
141
|
size: Size.xs
|
|
138
|
-
})),
|
|
142
|
+
})), (closeMode === 'hide' || showChildren) && React.createElement("ul", {
|
|
139
143
|
className: "".concat(CLASSNAME$1, "__children")
|
|
140
144
|
}, content));
|
|
141
145
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SideNavigationItem.js","sources":["../../../src/components/side-navigation/SideNavigation.tsx","../../../src/components/side-navigation/SideNavigationItem.tsx"],"sourcesContent":["import React, { Children, forwardRef, ReactNode } from 'react';\n\nimport classNames from 'classnames';\n\nimport { SideNavigationItem, Theme } from '@lumx/react';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface SideNavigationProps extends GenericProps {\n /** SideNavigationItem elements. */\n children: ReactNode;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SideNavigation';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * SideNavigation component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SideNavigation: Comp<SideNavigationProps, HTMLUListElement> = forwardRef((props, ref) => {\n const { children, className, theme, ...forwardedProps } = props;\n const content = Children.toArray(children).filter(isComponent(SideNavigationItem));\n\n return (\n <ul\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n theme === Theme.dark && 'lumx-color-font-light-N',\n handleBasicClasses({ prefix: CLASSNAME }),\n )}\n >\n {content}\n </ul>\n );\n});\nSideNavigation.displayName = COMPONENT_NAME;\nSideNavigation.className = CLASSNAME;\n","import React, { Children, forwardRef, ReactNode } from 'react';\n\nimport classNames from 'classnames';\nimport isEmpty from 'lodash/isEmpty';\n\nimport { mdiChevronDown, mdiChevronUp } from '@lumx/icons';\n\nimport { Emphasis, Icon, Size, IconButton, IconButtonProps } from '@lumx/react';\n\nimport {\n Callback,\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n onEnterPressed,\n} from '@lumx/react/utils';\nimport { renderLink } from '@lumx/react/utils/renderLink';\n\n/**\n * Defines the props of the component.\n */\nexport interface SideNavigationItemProps extends GenericProps {\n /** SideNavigationItem elements. */\n children?: ReactNode;\n /** Emphasis variant. */\n emphasis?: Emphasis;\n /** Label content. */\n label: string | ReactNode;\n /** Icon (SVG path). */\n icon?: string;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Whether the component is selected or not. */\n isSelected?: boolean;\n /** Custom react component for the link (can be used to inject react router Link). */\n linkAs?: 'a' | any;\n /** Props to pass to the link (minus those already set by the SideNavigationItem props). */\n linkProps?: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;\n /** Props to pass to the toggle button (minus those already set by the SideNavigationItem props). */\n toggleButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color' | 'size'>;\n /** On action button click callback. */\n onActionClick?(evt: React.MouseEvent): void;\n /** On click callback. */\n onClick?(evt: React.MouseEvent): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SideNavigationItem';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<SideNavigationItemProps> = {\n emphasis: Emphasis.high,\n};\n\n/**\n * SideNavigationItem component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SideNavigationItem: Comp<SideNavigationItemProps, HTMLLIElement> = forwardRef((props, ref) => {\n const {\n children,\n className,\n emphasis,\n icon,\n isOpen,\n isSelected,\n label,\n linkAs,\n linkProps,\n onActionClick,\n onClick,\n toggleButtonProps,\n ...forwardedProps\n } = props;\n\n const content = children && Children.toArray(children).filter(isComponent(SideNavigationItem));\n const hasContent = !isEmpty(content);\n const shouldSplitActions = Boolean(onActionClick);\n\n return (\n <li\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n emphasis,\n isOpen,\n isSelected,\n prefix: CLASSNAME,\n }),\n )}\n >\n {shouldSplitActions ? (\n <div className={`${CLASSNAME}__wrapper`}>\n {renderLink(\n {\n linkAs,\n ...linkProps,\n className: `${CLASSNAME}__link`,\n onClick,\n tabIndex: 0,\n },\n icon && <Icon className={`${CLASSNAME}__icon`} icon={icon} size={Size.xs} />,\n <span>{label}</span>,\n )}\n\n <IconButton\n {...toggleButtonProps}\n className={`${CLASSNAME}__toggle`}\n icon={isOpen ? mdiChevronUp : mdiChevronDown}\n size={Size.m}\n emphasis={Emphasis.low}\n onClick={onActionClick}\n />\n </div>\n ) : (\n renderLink(\n {\n linkAs,\n ...linkProps,\n className: `${CLASSNAME}__link`,\n tabIndex: 0,\n onClick,\n onKeyDown: onClick ? onEnterPressed(onClick as Callback) : undefined,\n },\n icon && <Icon className={`${CLASSNAME}__icon`} icon={icon} size={Size.xs} />,\n <span>{label}</span>,\n hasContent && (\n <Icon\n className={`${CLASSNAME}__chevron`}\n icon={isOpen ? mdiChevronUp : mdiChevronDown}\n size={Size.xs}\n />\n ),\n )\n )}\n\n {hasContent && isOpen && <ul className={`${CLASSNAME}__children`}>{content}</ul>}\n </li>\n );\n});\nSideNavigationItem.displayName = COMPONENT_NAME;\nSideNavigationItem.className = CLASSNAME;\nSideNavigationItem.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","SideNavigation","forwardRef","props","ref","children","className","theme","forwardedProps","content","Children","toArray","filter","isComponent","SideNavigationItem","classNames","Theme","dark","handleBasicClasses","prefix","displayName","DEFAULT_PROPS","emphasis","Emphasis","high","icon","isOpen","isSelected","label","linkAs","linkProps","onActionClick","onClick","toggleButtonProps","hasContent","isEmpty","shouldSplitActions","Boolean","renderLink","tabIndex","Size","xs","mdiChevronUp","mdiChevronDown","m","low","onKeyDown","onEnterPressed","undefined","defaultProps"],"mappings":";;;;;;;;;;AAQA;;;;AAUA;;;AAGA,IAAMA,cAAc,GAAG,gBA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;AAoF1FK,kBAAkB,CAACM,WAAnB,GAAiCtB,gBAAjC;AACAgB,kBAAkB,CAACR,SAAnB,GAA+BP,WAA/B;AACAe,kBAAkB,CAACmC,YAAnB,GAAkC5B,aAAlC;;;;"}
|
|
1
|
+
{"version":3,"file":"SideNavigationItem.js","sources":["../../../src/components/side-navigation/SideNavigation.tsx","../../../src/components/side-navigation/SideNavigationItem.tsx"],"sourcesContent":["import React, { Children, forwardRef, ReactNode } from 'react';\n\nimport classNames from 'classnames';\n\nimport { SideNavigationItem, Theme } from '@lumx/react';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface SideNavigationProps extends GenericProps {\n /** SideNavigationItem elements. */\n children: ReactNode;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SideNavigation';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * SideNavigation component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SideNavigation: Comp<SideNavigationProps, HTMLUListElement> = forwardRef((props, ref) => {\n const { children, className, theme, ...forwardedProps } = props;\n const content = Children.toArray(children).filter(isComponent(SideNavigationItem));\n\n return (\n <ul\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n theme === Theme.dark && 'lumx-color-font-light-N',\n handleBasicClasses({ prefix: CLASSNAME }),\n )}\n >\n {content}\n </ul>\n );\n});\nSideNavigation.displayName = COMPONENT_NAME;\nSideNavigation.className = CLASSNAME;\n","import React, { Children, forwardRef, ReactNode } from 'react';\n\nimport classNames from 'classnames';\nimport isEmpty from 'lodash/isEmpty';\n\nimport { mdiChevronDown, mdiChevronUp } from '@lumx/icons';\n\nimport { Emphasis, Icon, Size, IconButton, IconButtonProps } from '@lumx/react';\n\nimport {\n Callback,\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n onEnterPressed,\n} from '@lumx/react/utils';\nimport { renderLink } from '@lumx/react/utils/renderLink';\n\n/**\n * Defines the props of the component.\n */\nexport interface SideNavigationItemProps extends GenericProps {\n /** SideNavigationItem elements. */\n children?: ReactNode;\n /** Emphasis variant. */\n emphasis?: Emphasis;\n /** Label content. */\n label: string | ReactNode;\n /** Icon (SVG path). */\n icon?: string;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Whether the component is selected or not. */\n isSelected?: boolean;\n /** Custom react component for the link (can be used to inject react router Link). */\n linkAs?: 'a' | any;\n /** Props to pass to the link (minus those already set by the SideNavigationItem props). */\n linkProps?: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;\n /** Props to pass to the toggle button (minus those already set by the SideNavigationItem props). */\n toggleButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color' | 'size'>;\n /**\n * Choose how the children are hidden when closed\n * ('hide' keeps the children in DOM but hide them, 'unmount' remove the children from the DOM).\n */\n closeMode?: 'hide' | 'unmount';\n /** On action button click callback. */\n onActionClick?(evt: React.MouseEvent): void;\n /** On click callback. */\n onClick?(evt: React.MouseEvent): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SideNavigationItem';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<SideNavigationItemProps> = {\n emphasis: Emphasis.high,\n closeMode: 'unmount',\n};\n\n/**\n * SideNavigationItem component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SideNavigationItem: Comp<SideNavigationItemProps, HTMLLIElement> = forwardRef((props, ref) => {\n const {\n children,\n className,\n emphasis,\n icon,\n isOpen,\n isSelected,\n label,\n linkAs,\n linkProps,\n onActionClick,\n onClick,\n toggleButtonProps,\n closeMode = 'unmount',\n ...forwardedProps\n } = props;\n\n const content = children && Children.toArray(children).filter(isComponent(SideNavigationItem));\n const hasContent = !isEmpty(content);\n const shouldSplitActions = Boolean(onActionClick);\n const showChildren = hasContent && isOpen;\n\n return (\n <li\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n emphasis,\n isOpen: showChildren,\n isSelected,\n prefix: CLASSNAME,\n }),\n )}\n >\n {shouldSplitActions ? (\n <div className={`${CLASSNAME}__wrapper`}>\n {renderLink(\n {\n linkAs,\n ...linkProps,\n className: `${CLASSNAME}__link`,\n onClick,\n tabIndex: 0,\n },\n icon && <Icon className={`${CLASSNAME}__icon`} icon={icon} size={Size.xs} />,\n <span>{label}</span>,\n )}\n\n <IconButton\n {...toggleButtonProps}\n className={`${CLASSNAME}__toggle`}\n icon={isOpen ? mdiChevronUp : mdiChevronDown}\n size={Size.m}\n emphasis={Emphasis.low}\n onClick={onActionClick}\n />\n </div>\n ) : (\n renderLink(\n {\n linkAs,\n ...linkProps,\n className: `${CLASSNAME}__link`,\n tabIndex: 0,\n onClick,\n onKeyDown: onClick ? onEnterPressed(onClick as Callback) : undefined,\n },\n icon && <Icon className={`${CLASSNAME}__icon`} icon={icon} size={Size.xs} />,\n <span>{label}</span>,\n hasContent && (\n <Icon\n className={`${CLASSNAME}__chevron`}\n icon={isOpen ? mdiChevronUp : mdiChevronDown}\n size={Size.xs}\n />\n ),\n )\n )}\n\n {(closeMode === 'hide' || showChildren) && <ul className={`${CLASSNAME}__children`}>{content}</ul>}\n </li>\n );\n});\nSideNavigationItem.displayName = COMPONENT_NAME;\nSideNavigationItem.className = CLASSNAME;\nSideNavigationItem.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","SideNavigation","forwardRef","props","ref","children","className","theme","forwardedProps","content","Children","toArray","filter","isComponent","SideNavigationItem","classNames","Theme","dark","handleBasicClasses","prefix","displayName","DEFAULT_PROPS","emphasis","Emphasis","high","closeMode","icon","isOpen","isSelected","label","linkAs","linkProps","onActionClick","onClick","toggleButtonProps","hasContent","isEmpty","shouldSplitActions","Boolean","showChildren","renderLink","tabIndex","Size","xs","mdiChevronUp","mdiChevronDown","m","low","onKeyDown","onEnterPressed","undefined","defaultProps"],"mappings":";;;;;;;;;;AAQA;;;;AAUA;;;AAGA,IAAMA,cAAc,GAAG,gBAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;;;;;IAOaG,cAA2D,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAC1FC,QAD0F,GACxCF,KADwC,CAC1FE,QAD0F;AAAA,MAChFC,SADgF,GACxCH,KADwC,CAChFG,SADgF;AAAA,MACrEC,KADqE,GACxCJ,KADwC,CACrEI,KADqE;AAAA,MAC3DC,cAD2D,4BACxCL,KADwC;;AAElG,MAAMM,OAAO,GAAGC,QAAQ,CAACC,OAAT,CAAiBN,QAAjB,EAA2BO,MAA3B,CAAkCC,WAAW,CAACC,kBAAD,CAA7C,CAAhB;AAEA,SACI;AACI,IAAA,GAAG,EAAEV;AADT,KAEQI,cAFR;AAGI,IAAA,SAAS,EAAEO,UAAU,CACjBT,SADiB,EAEjBC,KAAK,KAAKS,KAAK,CAACC,IAAhB,IAAwB,yBAFP,EAGjBC,kBAAkB,CAAC;AAAEC,MAAAA,MAAM,EAAEpB;AAAV,KAAD,CAHD;AAHzB,MASKU,OATL,CADJ;AAaH,CAjBoF;AAkBrFR,cAAc,CAACmB,WAAf,GAA6BtB,cAA7B;AACAG,cAAc,CAACK,SAAf,GAA2BP,SAA3B;;AClCA;;;;AAkCA;;;AAGA,IAAMD,gBAAc,GAAG,oBAAvB;AAEA;;;;AAGA,IAAMC,WAAS,GAAGC,gBAAgB,CAACF,gBAAD,CAAlC;AAEA;;;;AAGA,IAAMuB,aAA+C,GAAG;AACpDC,EAAAA,QAAQ,EAAEC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,oBAAC,IAAD;AAAM,IAAA,SAAS,YAAK3B,WAAL,WAAf;AAAuC,IAAA,IAAI,EAAE2B,IAA7C;AAAmD,IAAA,IAAI,EAAEgB,IAAI,CAACC;AAA9D,IATF,EAUN,kCAAOd,KAAP,CAVM,EAWNM,UAAU,IACN,oBAAC,IAAD;AACI,IAAA,SAAS,YAAKpC,WAAL,cADb;AAEI,IAAA,IAAI,EAAE4B,MAAM,GAAGiB,YAAH,GAAkBC,cAFlC;AAGI,IAAA,IAAI,EAAEH,IAAI,CAACC;AAHf,IAZE,CArClB,EA0DK,CAAClB,SAAS,KAAK,MAAd,IAAwBc,YAAzB,KAA0C;AAAI,IAAA,SAAS,YAAKxC,WAAL;AAAb,KAA0CU,OAA1C,CA1D/C,CADJ;AA8DH,CArFyF;AAsF1FK,kBAAkB,CAACM,WAAnB,GAAiCtB,gBAAjC;AACAgB,kBAAkB,CAACR,SAAnB,GAA+BP,WAA/B;AACAe,kBAAkB,CAACqC,YAAnB,GAAkC9B,aAAlC;;;;"}
|
|
@@ -136,13 +136,15 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
136
136
|
var _events$_i = _slicedToArray(_events[_i], 3),
|
|
137
137
|
node = _events$_i[0],
|
|
138
138
|
eventType = _events$_i[1],
|
|
139
|
-
|
|
139
|
+
eventHandler = _events$_i[2];
|
|
140
140
|
|
|
141
|
-
node.addEventListener(eventType,
|
|
141
|
+
node.addEventListener(eventType, eventHandler);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
return function () {
|
|
145
|
-
//
|
|
145
|
+
// Clear pending timers.
|
|
146
|
+
if (timer) clearTimeout(timer); // Detach events.
|
|
147
|
+
|
|
146
148
|
var _iteratorNormalCompletion = true;
|
|
147
149
|
var _didIteratorError = false;
|
|
148
150
|
var _iteratorError = undefined;
|
|
@@ -152,9 +154,9 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
152
154
|
var _step$value = _slicedToArray(_step.value, 3),
|
|
153
155
|
node = _step$value[0],
|
|
154
156
|
eventType = _step$value[1],
|
|
155
|
-
|
|
157
|
+
eventHandler = _step$value[2];
|
|
156
158
|
|
|
157
|
-
node.removeEventListener(eventType,
|
|
159
|
+
node.removeEventListener(eventType, eventHandler);
|
|
158
160
|
}
|
|
159
161
|
} catch (err) {
|
|
160
162
|
_didIteratorError = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip2.js","sources":["../../../src/components/tooltip/useInjectTooltipRef.tsx","../../../src/utils/browserDoesNotSupportHover.ts","../../../src/components/tooltip/useTooltipOpen.tsx","../../../src/components/tooltip/Tooltip.tsx"],"sourcesContent":["import { mergeRefs } from '@lumx/react/utils/mergeRefs';\nimport get from 'lodash/get';\nimport React, { cloneElement, ReactNode, useMemo } from 'react';\n\n/**\n * Add ref and ARIA attribute(s) in tooltip children or wrapped children.\n * Button, IconButton, Icon and React HTML elements don't need to be wrapped but any other kind of children (array, fragment, custom components)\n * will be wrapped in a <span>.\n *\n * @param children Original tooltip anchor.\n * @param setAnchorElement Set tooltip anchor element.\n * @param isOpen Whether the tooltip is open or not.\n * @param id Tooltip id.\n * @return tooltip anchor.\n */\nexport const useInjectTooltipRef = (\n children: ReactNode,\n setAnchorElement: (e: HTMLDivElement) => void,\n isOpen: boolean,\n id: string,\n): ReactNode => {\n return useMemo(() => {\n const ariaProps = { 'aria-describedby': isOpen ? id : undefined };\n if (\n children &&\n get(children, '$$typeof') &&\n get(children, 'props.disabled') !== true &&\n get(children, 'props.isDisabled') !== true\n ) {\n const element = children as any;\n\n return cloneElement(element, {\n ...element.props,\n ...ariaProps,\n ref: mergeRefs(element.ref, setAnchorElement),\n });\n }\n return (\n <div className=\"lumx-tooltip-anchor-wrapper\" ref={setAnchorElement} {...ariaProps}>\n {children}\n </div>\n );\n }, [isOpen, id, children, setAnchorElement]);\n};\n","/** Return true if the browser does not support pointer hover */\nexport const browserDoesNotSupportHover = (): boolean => !!window.matchMedia?.('(hover: none)').matches;\n","import { onEscapePressed } from '@lumx/react/utils';\nimport { useEffect, useState } from 'react';\nimport { browserDoesNotSupportHover } from '@lumx/react/utils/browserDoesNotSupportHover';\nimport { TOOLTIP_HOVER_DELAY, TOOLTIP_LONG_PRESS_DELAY } from '@lumx/react/constants';\n\n/**\n * Hook controlling tooltip visibility using mouse hover the anchor and delay.\n *\n * @param delay Delay in millisecond to display the tooltip.\n * @param anchorElement Tooltip anchor element.\n * @return whether or not to show the tooltip.\n */\nexport function useTooltipOpen(delay: number | undefined, anchorElement: HTMLElement | null): boolean {\n const [isOpen, setIsOpen] = useState(false);\n\n useEffect(() => {\n if (!anchorElement) {\n return undefined;\n }\n let timer: number | undefined;\n let openStartTime: number | undefined;\n let shouldOpen: boolean | undefined;\n\n // Run timer to defer updating the isOpen state.\n const deferUpdate = (duration: number) => {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => {\n setIsOpen(!!shouldOpen);\n }, duration) as any;\n };\n\n const hoverNotSupported = browserDoesNotSupportHover();\n const hasTouch = 'ontouchstart' in window;\n\n // Adapt open/close delay\n const openDelay = delay || (hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.open : TOOLTIP_HOVER_DELAY.open);\n const closeDelay = hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.close : TOOLTIP_HOVER_DELAY.close;\n\n // Open (or/and cancel closing) of tooltip.\n const open = () => {\n if (shouldOpen && !timer) return;\n shouldOpen = true;\n openStartTime = Date.now();\n deferUpdate(openDelay);\n };\n\n // Close or cancel opening of tooltip\n const close = (overrideDelay = closeDelay) => {\n if (!shouldOpen && !timer) return;\n shouldOpen = false;\n deferUpdate(overrideDelay);\n };\n const closeImmediately = () => close(0);\n\n /**\n * Handle touchend event\n * If `touchend` comes before the open delay => cancel tooltip (close immediate).\n * Else if `touchend` comes after the open delay => tooltip takes priority, the anchor's default touch end event is prevented.\n */\n const touchEnd = (evt: Event) => {\n if (!openStartTime) return;\n if (Date.now() - openStartTime >= openDelay) {\n // Tooltip take priority, event prevented.\n evt.stopPropagation();\n evt.preventDefault();\n anchorElement.focus();\n // Close with delay.\n close();\n } else {\n // Close immediately.\n closeImmediately();\n }\n };\n\n // Adapt event to browsers with or without `hover` support.\n const events: Array<[Node, Event['type'], any]> = hoverNotSupported\n ? [\n [anchorElement, hasTouch ? 'touchstart' : 'mousedown', open],\n [anchorElement, hasTouch ? 'touchend' : 'mouseup', touchEnd],\n ]\n : [\n [anchorElement, 'mouseenter', open],\n [anchorElement, 'mouseleave', close],\n [anchorElement, 'mouseup', closeImmediately],\n ];\n\n // Events always applied no matter the browser:.\n events.push(\n // Open on focus.\n [anchorElement, 'focusin', open],\n // Close on lost focus.\n [anchorElement, 'focusout', closeImmediately],\n // Close on ESC keydown\n [anchorElement, 'keydown', onEscapePressed(closeImmediately)],\n );\n\n // Attach events\n for (const [node, eventType, evenHandler] of events) {\n node.addEventListener(eventType, evenHandler);\n }\n return () => {\n // Detach events.\n for (const [node, eventType, evenHandler] of events) {\n node.removeEventListener(eventType, evenHandler);\n }\n };\n }, [anchorElement, delay]);\n\n return isOpen;\n}\n","/* eslint-disable react-hooks/rules-of-hooks */\nimport React, { forwardRef, ReactNode, useMemo, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { usePopper } from 'react-popper';\nimport { uid } from 'uid';\n\nimport classNames from 'classnames';\n\nimport { Placement } from '@lumx/react/components/popover/Popover';\n\nimport { DOCUMENT } from '@lumx/react/constants';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\nimport { useInjectTooltipRef } from './useInjectTooltipRef';\nimport { useTooltipOpen } from './useTooltipOpen';\n\n/** Position of the tooltip relative to the anchor element. */\nexport type TooltipPlacement = Extract<Placement, 'top' | 'right' | 'bottom' | 'left'>;\n\n/**\n * Defines the props of the component.\n */\nexport interface TooltipProps extends GenericProps {\n /** Anchor (element on which we activate the tooltip). */\n children: ReactNode;\n /** Delay (in ms) before closing the tooltip. */\n delay?: number;\n /** Whether the tooltip is displayed even without the mouse hovering the anchor. */\n forceOpen?: boolean;\n /** Label text. */\n label?: string | null | false;\n /** Placement of the tooltip relative to the anchor. */\n placement?: TooltipPlacement;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Tooltip';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<TooltipProps> = {\n placement: Placement.BOTTOM,\n};\n\n/**\n * Arrow size (in pixel).\n */\nconst ARROW_SIZE = 8;\n\n/**\n * Tooltip component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, ref) => {\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n const { label, children, className, delay, placement, forceOpen, ...forwardedProps } = props;\n if (!label) {\n return <>{children}</>;\n }\n\n const id = useMemo(() => `tooltip-${uid()}`, []);\n\n const [popperElement, setPopperElement] = useState<null | HTMLElement>(null);\n const [anchorElement, setAnchorElement] = useState<null | HTMLElement>(null);\n const { styles, attributes } = usePopper(anchorElement, popperElement, {\n placement,\n modifiers: [\n {\n name: 'offset',\n options: { offset: [0, ARROW_SIZE] },\n },\n ],\n });\n\n const position = attributes?.popper?.['data-popper-placement'] ?? placement;\n const isOpen = useTooltipOpen(delay, anchorElement) || forceOpen;\n const wrappedChildren = useInjectTooltipRef(children, setAnchorElement, isOpen as boolean, id);\n\n return (\n <>\n {wrappedChildren}\n {isOpen &&\n createPortal(\n <div\n ref={mergeRefs(ref, setPopperElement)}\n {...forwardedProps}\n id={id}\n role=\"tooltip\"\n aria-label={label}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, position }))}\n style={styles.popper}\n {...attributes.popper}\n >\n <div className={`${CLASSNAME}__arrow`} />\n <div className={`${CLASSNAME}__inner`}>\n {label.indexOf('\\n') !== -1\n ? label.split('\\n').map((sentence: string) => <p key={sentence}>{sentence}</p>)\n : label}\n </div>\n </div>,\n document.body,\n )}\n </>\n );\n});\nTooltip.displayName = COMPONENT_NAME;\nTooltip.className = CLASSNAME;\nTooltip.defaultProps = DEFAULT_PROPS;\n"],"names":["useInjectTooltipRef","children","setAnchorElement","isOpen","id","useMemo","ariaProps","undefined","get","element","cloneElement","props","ref","mergeRefs","browserDoesNotSupportHover","window","matchMedia","matches","useTooltipOpen","delay","anchorElement","useState","setIsOpen","useEffect","timer","openStartTime","shouldOpen","deferUpdate","duration","clearTimeout","setTimeout","hoverNotSupported","hasTouch","openDelay","TOOLTIP_LONG_PRESS_DELAY","open","TOOLTIP_HOVER_DELAY","closeDelay","close","Date","now","overrideDelay","closeImmediately","touchEnd","evt","stopPropagation","preventDefault","focus","events","push","onEscapePressed","node","eventType","evenHandler","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","placement","Placement","BOTTOM","ARROW_SIZE","Tooltip","forwardRef","DOCUMENT","label","className","forceOpen","forwardedProps","uid","popperElement","setPopperElement","usePopper","modifiers","name","options","offset","styles","attributes","position","popper","wrappedChildren","createPortal","classNames","handleBasicClasses","prefix","indexOf","split","map","sentence","document","body","displayName","defaultProps"],"mappings":";;;;;;;;;;AAIA;;;;;;;;;;;;AAWO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,CAC/BC,QAD+B,EAE/BC,gBAF+B,EAG/BC,MAH+B,EAI/BC,EAJ+B,EAKnB;AACZ,SAAOC,OAAO,CAAC,YAAM;AACjB,QAAMC,SAAS,GAAG;AAAE,0BAAoBH,MAAM,GAAGC,EAAH,GAAQG;AAApC,KAAlB;;AACA,QACIN,QAAQ,IACRO,GAAG,CAACP,QAAD,EAAW,UAAX,CADH,IAEAO,GAAG,CAACP,QAAD,EAAW,gBAAX,CAAH,KAAoC,IAFpC,IAGAO,GAAG,CAACP,QAAD,EAAW,kBAAX,CAAH,KAAsC,IAJ1C,EA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,QAAQ,CAACC,IAlBD,CAHpB,CADJ;AA0BH,CAtDoE;AAuDrE7B,OAAO,CAAC8B,WAAR,GAAsBtC,cAAtB;AACAQ,OAAO,CAACI,SAAR,GAAoBX,SAApB;AACAO,OAAO,CAAC+B,YAAR,GAAuBpC,aAAvB;;;;"}
|
|
1
|
+
{"version":3,"file":"Tooltip2.js","sources":["../../../src/components/tooltip/useInjectTooltipRef.tsx","../../../src/utils/browserDoesNotSupportHover.ts","../../../src/components/tooltip/useTooltipOpen.tsx","../../../src/components/tooltip/Tooltip.tsx"],"sourcesContent":["import { mergeRefs } from '@lumx/react/utils/mergeRefs';\nimport get from 'lodash/get';\nimport React, { cloneElement, ReactNode, useMemo } from 'react';\n\n/**\n * Add ref and ARIA attribute(s) in tooltip children or wrapped children.\n * Button, IconButton, Icon and React HTML elements don't need to be wrapped but any other kind of children (array, fragment, custom components)\n * will be wrapped in a <span>.\n *\n * @param children Original tooltip anchor.\n * @param setAnchorElement Set tooltip anchor element.\n * @param isOpen Whether the tooltip is open or not.\n * @param id Tooltip id.\n * @return tooltip anchor.\n */\nexport const useInjectTooltipRef = (\n children: ReactNode,\n setAnchorElement: (e: HTMLDivElement) => void,\n isOpen: boolean,\n id: string,\n): ReactNode => {\n return useMemo(() => {\n const ariaProps = { 'aria-describedby': isOpen ? id : undefined };\n if (\n children &&\n get(children, '$$typeof') &&\n get(children, 'props.disabled') !== true &&\n get(children, 'props.isDisabled') !== true\n ) {\n const element = children as any;\n\n return cloneElement(element, {\n ...element.props,\n ...ariaProps,\n ref: mergeRefs(element.ref, setAnchorElement),\n });\n }\n return (\n <div className=\"lumx-tooltip-anchor-wrapper\" ref={setAnchorElement} {...ariaProps}>\n {children}\n </div>\n );\n }, [isOpen, id, children, setAnchorElement]);\n};\n","/** Return true if the browser does not support pointer hover */\nexport const browserDoesNotSupportHover = (): boolean => !!window.matchMedia?.('(hover: none)').matches;\n","import { onEscapePressed } from '@lumx/react/utils';\nimport { useEffect, useState } from 'react';\nimport { browserDoesNotSupportHover } from '@lumx/react/utils/browserDoesNotSupportHover';\nimport { TOOLTIP_HOVER_DELAY, TOOLTIP_LONG_PRESS_DELAY } from '@lumx/react/constants';\n\n/**\n * Hook controlling tooltip visibility using mouse hover the anchor and delay.\n *\n * @param delay Delay in millisecond to display the tooltip.\n * @param anchorElement Tooltip anchor element.\n * @return whether or not to show the tooltip.\n */\nexport function useTooltipOpen(delay: number | undefined, anchorElement: HTMLElement | null): boolean {\n const [isOpen, setIsOpen] = useState(false);\n\n useEffect(() => {\n if (!anchorElement) {\n return undefined;\n }\n let timer: number | undefined;\n let openStartTime: number | undefined;\n let shouldOpen: boolean | undefined;\n\n // Run timer to defer updating the isOpen state.\n const deferUpdate = (duration: number) => {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => {\n setIsOpen(!!shouldOpen);\n }, duration) as any;\n };\n\n const hoverNotSupported = browserDoesNotSupportHover();\n const hasTouch = 'ontouchstart' in window;\n\n // Adapt open/close delay\n const openDelay = delay || (hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.open : TOOLTIP_HOVER_DELAY.open);\n const closeDelay = hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.close : TOOLTIP_HOVER_DELAY.close;\n\n // Open (or/and cancel closing) of tooltip.\n const open = () => {\n if (shouldOpen && !timer) return;\n shouldOpen = true;\n openStartTime = Date.now();\n deferUpdate(openDelay);\n };\n\n // Close or cancel opening of tooltip\n const close = (overrideDelay = closeDelay) => {\n if (!shouldOpen && !timer) return;\n shouldOpen = false;\n deferUpdate(overrideDelay);\n };\n const closeImmediately = () => close(0);\n\n /**\n * Handle touchend event\n * If `touchend` comes before the open delay => cancel tooltip (close immediate).\n * Else if `touchend` comes after the open delay => tooltip takes priority, the anchor's default touch end event is prevented.\n */\n const touchEnd = (evt: Event) => {\n if (!openStartTime) return;\n if (Date.now() - openStartTime >= openDelay) {\n // Tooltip take priority, event prevented.\n evt.stopPropagation();\n evt.preventDefault();\n anchorElement.focus();\n // Close with delay.\n close();\n } else {\n // Close immediately.\n closeImmediately();\n }\n };\n\n // Adapt event to browsers with or without `hover` support.\n const events: Array<[Node, Event['type'], any]> = hoverNotSupported\n ? [\n [anchorElement, hasTouch ? 'touchstart' : 'mousedown', open],\n [anchorElement, hasTouch ? 'touchend' : 'mouseup', touchEnd],\n ]\n : [\n [anchorElement, 'mouseenter', open],\n [anchorElement, 'mouseleave', close],\n [anchorElement, 'mouseup', closeImmediately],\n ];\n\n // Events always applied no matter the browser:.\n events.push(\n // Open on focus.\n [anchorElement, 'focusin', open],\n // Close on lost focus.\n [anchorElement, 'focusout', closeImmediately],\n // Close on ESC keydown\n [anchorElement, 'keydown', onEscapePressed(closeImmediately)],\n );\n\n // Attach events\n for (const [node, eventType, eventHandler] of events) {\n node.addEventListener(eventType, eventHandler);\n }\n return () => {\n // Clear pending timers.\n if (timer) clearTimeout(timer);\n\n // Detach events.\n for (const [node, eventType, eventHandler] of events) {\n node.removeEventListener(eventType, eventHandler);\n }\n };\n }, [anchorElement, delay]);\n\n return isOpen;\n}\n","/* eslint-disable react-hooks/rules-of-hooks */\nimport React, { forwardRef, ReactNode, useMemo, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { usePopper } from 'react-popper';\nimport { uid } from 'uid';\n\nimport classNames from 'classnames';\n\nimport { Placement } from '@lumx/react/components/popover/Popover';\n\nimport { DOCUMENT } from '@lumx/react/constants';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\nimport { useInjectTooltipRef } from './useInjectTooltipRef';\nimport { useTooltipOpen } from './useTooltipOpen';\n\n/** Position of the tooltip relative to the anchor element. */\nexport type TooltipPlacement = Extract<Placement, 'top' | 'right' | 'bottom' | 'left'>;\n\n/**\n * Defines the props of the component.\n */\nexport interface TooltipProps extends GenericProps {\n /** Anchor (element on which we activate the tooltip). */\n children: ReactNode;\n /** Delay (in ms) before closing the tooltip. */\n delay?: number;\n /** Whether the tooltip is displayed even without the mouse hovering the anchor. */\n forceOpen?: boolean;\n /** Label text. */\n label?: string | null | false;\n /** Placement of the tooltip relative to the anchor. */\n placement?: TooltipPlacement;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Tooltip';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<TooltipProps> = {\n placement: Placement.BOTTOM,\n};\n\n/**\n * Arrow size (in pixel).\n */\nconst ARROW_SIZE = 8;\n\n/**\n * Tooltip component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, ref) => {\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n const { label, children, className, delay, placement, forceOpen, ...forwardedProps } = props;\n if (!label) {\n return <>{children}</>;\n }\n\n const id = useMemo(() => `tooltip-${uid()}`, []);\n\n const [popperElement, setPopperElement] = useState<null | HTMLElement>(null);\n const [anchorElement, setAnchorElement] = useState<null | HTMLElement>(null);\n const { styles, attributes } = usePopper(anchorElement, popperElement, {\n placement,\n modifiers: [\n {\n name: 'offset',\n options: { offset: [0, ARROW_SIZE] },\n },\n ],\n });\n\n const position = attributes?.popper?.['data-popper-placement'] ?? placement;\n const isOpen = useTooltipOpen(delay, anchorElement) || forceOpen;\n const wrappedChildren = useInjectTooltipRef(children, setAnchorElement, isOpen as boolean, id);\n\n return (\n <>\n {wrappedChildren}\n {isOpen &&\n createPortal(\n <div\n ref={mergeRefs(ref, setPopperElement)}\n {...forwardedProps}\n id={id}\n role=\"tooltip\"\n aria-label={label}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, position }))}\n style={styles.popper}\n {...attributes.popper}\n >\n <div className={`${CLASSNAME}__arrow`} />\n <div className={`${CLASSNAME}__inner`}>\n {label.indexOf('\\n') !== -1\n ? label.split('\\n').map((sentence: string) => <p key={sentence}>{sentence}</p>)\n : label}\n </div>\n </div>,\n document.body,\n )}\n </>\n );\n});\nTooltip.displayName = COMPONENT_NAME;\nTooltip.className = CLASSNAME;\nTooltip.defaultProps = DEFAULT_PROPS;\n"],"names":["useInjectTooltipRef","children","setAnchorElement","isOpen","id","useMemo","ariaProps","undefined","get","element","cloneElement","props","ref","mergeRefs","browserDoesNotSupportHover","window","matchMedia","matches","useTooltipOpen","delay","anchorElement","useState","setIsOpen","useEffect","timer","openStartTime","shouldOpen","deferUpdate","duration","clearTimeout","setTimeout","hoverNotSupported","hasTouch","openDelay","TOOLTIP_LONG_PRESS_DELAY","open","TOOLTIP_HOVER_DELAY","closeDelay","close","Date","now","overrideDelay","closeImmediately","touchEnd","evt","stopPropagation","preventDefault","focus","events","push","onEscapePressed","node","eventType","eventHandler","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","placement","Placement","BOTTOM","ARROW_SIZE","Tooltip","forwardRef","DOCUMENT","label","className","forceOpen","forwardedProps","uid","popperElement","setPopperElement","usePopper","modifiers","name","options","offset","styles","attributes","position","popper","wrappedChildren","createPortal","classNames","handleBasicClasses","prefix","indexOf","split","map","sentence","document","body","displayName","defaultProps"],"mappings":";;;;;;;;;;AAIA;;;;;;;;;;;;AAWO,IAAMA,mBAAmB,GAAG,SAAtBA,mBAAsB,CAC/BC,QAD+B,EAE/BC,gBAF+B,EAG/BC,MAH+B,EAI/BC,EAJ+B,EAKnB;AACZ,SAAOC,OAAO,CAAC,YAAM;AACjB,QAAMC,SAAS,GAAG;AAAE,0BAAoBH,MAAM,GAAGC,EAAH,GAAQG;AAApC,KAAlB;;AACA,QACIN,QAAQ,IACRO,GAAG,CAACP,QAAD,EAAW,UAAX,CADH,IAEAO,GAAG,CAACP,QAAD,EAAW,gBAAX,CAAH,KAAoC,IAFpC,IAGAO,GAAG,CAACP,QAAD,EAAW,kBAAX,CAAH,KAAsC,IAJ1C,EAKE;AAC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AAAA,GAAtB,CADL,GAEKxB,KAHV,CAXJ,CADQ,EAkBRyB,QAAQ,CAACC,IAlBD,CAHpB,CADJ;AA0BH,CAtDoE;AAuDrE7B,OAAO,CAAC8B,WAAR,GAAsBtC,cAAtB;AACAQ,OAAO,CAACI,SAAR,GAAoBX,SAApB;AACAO,OAAO,CAAC+B,YAAR,GAAuBpC,aAAvB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../../src/components/index.ts"],"sourcesContent":["import { ValueOf } from '@lumx/react/utils';\n\n/**\n * Alignments.\n */\nexport const Alignment = {\n bottom: 'bottom',\n center: 'center',\n end: 'end',\n left: 'left',\n right: 'right',\n spaceAround: 'space-around',\n spaceBetween: 'space-between',\n start: 'start',\n top: 'top',\n} as const;\nexport type Alignment = ValueOf<typeof Alignment>;\nexport type VerticalAlignment = Extract<Alignment, 'top' | 'center' | 'bottom'>;\nexport type HorizontalAlignment = Extract<Alignment, 'right' | 'center' | 'left'>;\n\n/**\n * See SCSS variable $lumx-color-palette\n */\nexport const ColorPalette = {\n primary: 'primary',\n secondary: 'secondary',\n blue: 'blue',\n dark: 'dark',\n green: 'green',\n yellow: 'yellow',\n red: 'red',\n light: 'light',\n grey: 'grey',\n} as const;\nexport type ColorPalette = ValueOf<typeof ColorPalette>;\nexport type Color = ColorPalette | string;\n\n/**\n * See SCSS variable $lumx-color-variants\n */\nexport const ColorVariant = {\n D1: 'D1',\n D2: 'D2',\n L1: 'L1',\n L2: 'L2',\n L3: 'L3',\n L4: 'L4',\n L5: 'L5',\n L6: 'L6',\n N: 'N',\n} as const;\nexport type ColorVariant = ValueOf<typeof ColorVariant>;\n\nexport const Theme = {\n light: 'light',\n dark: 'dark',\n} as const;\nexport type Theme = ValueOf<typeof Theme>;\n\nexport const Size = {\n xxs: 'xxs',\n xs: 'xs',\n s: 's',\n m: 'm',\n l: 'l',\n xl: 'xl',\n xxl: 'xxl',\n tiny: 'tiny',\n regular: 'regular',\n big: 'big',\n huge: 'huge',\n} as const;\nexport type Size = ValueOf<typeof Size>;\nexport type GlobalSize = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;\n\nexport const Orientation = {\n horizontal: 'horizontal',\n vertical: 'vertical',\n} as const;\nexport type Orientation = ValueOf<typeof Orientation>;\n\nexport const Emphasis = {\n low: 'low',\n medium: 'medium',\n high: 'high',\n} as const;\nexport type Emphasis = ValueOf<typeof Emphasis>;\n\n/**\n * List of typographies that can't be customized.\n */\nexport const TypographyInterface = {\n overline: 'overline',\n caption: 'caption',\n body1: 'body1',\n body2: 'body2',\n subtitle1: 'subtitle1',\n subtitle2: 'subtitle2',\n title: 'title',\n headline: 'headline',\n display1: 'display1',\n} as const;\nexport type TypographyInterface = ValueOf<typeof TypographyInterface>;\n\n/**\n * List of title typographies that can be customized (via CSS variables).\n */\nexport const TypographyTitleCustom = {\n title1: 'custom-title1',\n title2: 'custom-title2',\n title3: 'custom-title3',\n title4: 'custom-title4',\n title5: 'custom-title5',\n title6: 'custom-title6',\n} as const;\nexport type TypographyTitleCustom = ValueOf<typeof TypographyTitleCustom>;\n\n/**\n * List of typographies that can be customized (via CSS variables).\n */\nconst TypographyCustom = {\n ...TypographyTitleCustom,\n intro: 'intro',\n 'body-large': 'body-large',\n body: 'body',\n quote: 'quote',\n 'publish-info': 'publish-info',\n button: 'button',\n} as const;\nexport type TypographyCustom = ValueOf<typeof TypographyCustom>;\n\n/**\n * List of all typographies.\n */\nexport const Typography = {\n ...TypographyInterface,\n custom: TypographyCustom,\n} as const;\nexport type Typography = TypographyInterface | TypographyCustom;\n\n/**\n * All available aspect ratios.\n */\nexport const AspectRatio = {\n /** Intrinsic content ratio. */\n original: 'original',\n /** Ratio 16:9 */\n wide: 'wide',\n /** Ratio 3:2 */\n horizontal: 'horizontal',\n /** Ratio 3:2 */\n vertical: 'vertical',\n /** Ratio 1:1 */\n square: 'square',\n /** Ratio constrained by the parent. */\n free: 'free',\n} as const;\nexport type AspectRatio = ValueOf<typeof AspectRatio>;\n\n/**\n * Semantic info about the purpose of the component\n */\nexport const Kind = {\n info: 'info',\n success: 'success',\n warning: 'warning',\n error: 'error',\n} as const;\nexport type Kind = ValueOf<typeof Kind>;\n"],"names":["Alignment","bottom","center","end","left","right","spaceAround","spaceBetween","start","top","ColorPalette","primary","secondary","blue","dark","green","yellow","red","light","grey","ColorVariant","D1","D2","L1","L2","L3","L4","L5","L6","N","Theme","Size","xxs","xs","s","m","l","xl","xxl","tiny","regular","big","huge","Orientation","horizontal","vertical","Emphasis","low","
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../src/components/index.ts"],"sourcesContent":["import { ValueOf } from '@lumx/react/utils';\n\n/**\n * Alignments.\n */\nexport const Alignment = {\n bottom: 'bottom',\n center: 'center',\n end: 'end',\n left: 'left',\n right: 'right',\n spaceAround: 'space-around',\n spaceBetween: 'space-between',\n start: 'start',\n top: 'top',\n} as const;\nexport type Alignment = ValueOf<typeof Alignment>;\nexport type VerticalAlignment = Extract<Alignment, 'top' | 'center' | 'bottom'>;\nexport type HorizontalAlignment = Extract<Alignment, 'right' | 'center' | 'left'>;\n\n/**\n * See SCSS variable $lumx-color-palette\n */\nexport const ColorPalette = {\n primary: 'primary',\n secondary: 'secondary',\n blue: 'blue',\n dark: 'dark',\n green: 'green',\n yellow: 'yellow',\n red: 'red',\n light: 'light',\n grey: 'grey',\n} as const;\nexport type ColorPalette = ValueOf<typeof ColorPalette>;\nexport type Color = ColorPalette | string;\n\n/**\n * See SCSS variable $lumx-color-variants\n */\nexport const ColorVariant = {\n D1: 'D1',\n D2: 'D2',\n L1: 'L1',\n L2: 'L2',\n L3: 'L3',\n L4: 'L4',\n L5: 'L5',\n L6: 'L6',\n N: 'N',\n} as const;\nexport type ColorVariant = ValueOf<typeof ColorVariant>;\n\nexport const Theme = {\n light: 'light',\n dark: 'dark',\n} as const;\nexport type Theme = ValueOf<typeof Theme>;\n\nexport const Size = {\n xxs: 'xxs',\n xs: 'xs',\n s: 's',\n m: 'm',\n l: 'l',\n xl: 'xl',\n xxl: 'xxl',\n tiny: 'tiny',\n regular: 'regular',\n medium: 'medium',\n big: 'big',\n huge: 'huge',\n} as const;\nexport type Size = ValueOf<typeof Size>;\nexport type GlobalSize = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;\n\nexport const Orientation = {\n horizontal: 'horizontal',\n vertical: 'vertical',\n} as const;\nexport type Orientation = ValueOf<typeof Orientation>;\n\nexport const Emphasis = {\n low: 'low',\n medium: 'medium',\n high: 'high',\n} as const;\nexport type Emphasis = ValueOf<typeof Emphasis>;\n\n/**\n * List of typographies that can't be customized.\n */\nexport const TypographyInterface = {\n overline: 'overline',\n caption: 'caption',\n body1: 'body1',\n body2: 'body2',\n subtitle1: 'subtitle1',\n subtitle2: 'subtitle2',\n title: 'title',\n headline: 'headline',\n display1: 'display1',\n} as const;\nexport type TypographyInterface = ValueOf<typeof TypographyInterface>;\n\n/**\n * List of title typographies that can be customized (via CSS variables).\n */\nexport const TypographyTitleCustom = {\n title1: 'custom-title1',\n title2: 'custom-title2',\n title3: 'custom-title3',\n title4: 'custom-title4',\n title5: 'custom-title5',\n title6: 'custom-title6',\n} as const;\nexport type TypographyTitleCustom = ValueOf<typeof TypographyTitleCustom>;\n\n/**\n * List of typographies that can be customized (via CSS variables).\n */\nconst TypographyCustom = {\n ...TypographyTitleCustom,\n intro: 'intro',\n 'body-large': 'body-large',\n body: 'body',\n quote: 'quote',\n 'publish-info': 'publish-info',\n button: 'button',\n} as const;\nexport type TypographyCustom = ValueOf<typeof TypographyCustom>;\n\n/**\n * List of all typographies.\n */\nexport const Typography = {\n ...TypographyInterface,\n custom: TypographyCustom,\n} as const;\nexport type Typography = TypographyInterface | TypographyCustom;\n\n/**\n * All available aspect ratios.\n */\nexport const AspectRatio = {\n /** Intrinsic content ratio. */\n original: 'original',\n /** Ratio 16:9 */\n wide: 'wide',\n /** Ratio 3:2 */\n horizontal: 'horizontal',\n /** Ratio 3:2 */\n vertical: 'vertical',\n /** Ratio 1:1 */\n square: 'square',\n /** Ratio constrained by the parent. */\n free: 'free',\n} as const;\nexport type AspectRatio = ValueOf<typeof AspectRatio>;\n\n/**\n * Semantic info about the purpose of the component\n */\nexport const Kind = {\n info: 'info',\n success: 'success',\n warning: 'warning',\n error: 'error',\n} as const;\nexport type Kind = ValueOf<typeof Kind>;\n"],"names":["Alignment","bottom","center","end","left","right","spaceAround","spaceBetween","start","top","ColorPalette","primary","secondary","blue","dark","green","yellow","red","light","grey","ColorVariant","D1","D2","L1","L2","L3","L4","L5","L6","N","Theme","Size","xxs","xs","s","m","l","xl","xxl","tiny","regular","medium","big","huge","Orientation","horizontal","vertical","Emphasis","low","high","TypographyInterface","overline","caption","body1","body2","subtitle1","subtitle2","title","headline","display1","TypographyTitleCustom","title1","title2","title3","title4","title5","title6","TypographyCustom","intro","body","quote","button","Typography","custom","AspectRatio","original","wide","square","free","Kind","info","success","warning","error"],"mappings":";;AAEA;;;IAGaA,SAAS,GAAG;AACrBC,EAAAA,MAAM,EAAE,QADa;AAErBC,EAAAA,MAAM,EAAE,QAFa;AAGrBC,EAAAA,GAAG,EAAE,KAHgB;AAIrBC,EAAAA,IAAI,EAAE,MAJe;AAKrBC,EAAAA,KAAK,EAAE,OALc;AAMrBC,EAAAA,WAAW,EAAE,cANQ;AAOrBC,EAAAA,YAAY,EAAE,eAPO;AAQrBC,EAAAA,KAAK,EAAE,OARc;AASrBC,EAAAA,GAAG,EAAE;AATgB;;AAezB;;;IAGaC,YAAY,GAAG;AACxBC,EAAAA,OAAO,EAAE,SADe;AAExBC,EAAAA,SAAS,EAAE,WAFa;AAGxBC,EAAAA,IAAI,EAAE,MAHkB;AAIxBC,EAAAA,IAAI,EAAE,MAJkB;AAKxBC,EAAAA,KAAK,EAAE,OALiB;AAMxBC,EAAAA,MAAM,EAAE,QANgB;AAOxBC,EAAAA,GAAG,EAAE,KAPmB;AAQxBC,EAAA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Effect } from 'react';
|
|
2
2
|
import { D as DOCUMENT } from './constants.js';
|
|
3
3
|
|
|
4
|
+
/** CSS selector listing all tabbable elements. */
|
|
5
|
+
|
|
6
|
+
var TABBABLE_ELEMENTS_SELECTOR = "a[href]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\nbutton:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ntextarea:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"text\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"radio\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"checkbox\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\n[tabindex]:not([tabindex=\"-1\"], [disabled], [aria-disabled])";
|
|
4
7
|
/**
|
|
5
8
|
* Get first and last elements focusable in an element.
|
|
6
9
|
*
|
|
@@ -9,7 +12,7 @@ import { D as DOCUMENT } from './constants.js';
|
|
|
9
12
|
*/
|
|
10
13
|
|
|
11
14
|
function getFocusable(parentElement) {
|
|
12
|
-
var focusableElements = parentElement.querySelectorAll(
|
|
15
|
+
var focusableElements = parentElement.querySelectorAll(TABBABLE_ELEMENTS_SELECTOR);
|
|
13
16
|
|
|
14
17
|
if (focusableElements.length <= 0) {
|
|
15
18
|
return {};
|
|
@@ -52,23 +55,26 @@ function useFocusTrap(focusZoneElement, focusElement) {
|
|
|
52
55
|
return;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
var
|
|
56
|
-
first = _getFocusable.first,
|
|
57
|
-
last = _getFocusable.last; // Prevent focus switch if no focusable available.
|
|
58
|
+
var focusable = getFocusable(focusZoneElement); // Prevent focus switch if no focusable available.
|
|
58
59
|
|
|
60
|
+
if (!focusable.first) {
|
|
61
|
+
evt.preventDefault();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
59
64
|
|
|
60
|
-
if (
|
|
65
|
+
if ( // No previous focus
|
|
66
|
+
!document.activeElement || // Previous focus is at the end of the focus zone.
|
|
67
|
+
!evt.shiftKey && document.activeElement === focusable.last || // Previous focus is outside the focus zone
|
|
68
|
+
!focusZoneElement.contains(document.activeElement)) {
|
|
69
|
+
focusable.first.focus();
|
|
61
70
|
evt.preventDefault();
|
|
62
71
|
return;
|
|
63
72
|
}
|
|
64
73
|
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
} else if (document.activeElement === last) {
|
|
71
|
-
first === null || first === void 0 ? void 0 : first.focus();
|
|
74
|
+
if ( // Focus order reversed
|
|
75
|
+
evt.shiftKey && // Previous focus is at the start of the focus zone.
|
|
76
|
+
document.activeElement === focusable.first) {
|
|
77
|
+
focusable.last.focus();
|
|
72
78
|
evt.preventDefault();
|
|
73
79
|
}
|
|
74
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusTrap.js","sources":["../../../src/hooks/useFocusTrap.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { DOCUMENT } from '@lumx/react/constants';\n\n
|
|
1
|
+
{"version":3,"file":"useFocusTrap.js","sources":["../../../src/hooks/useFocusTrap.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { DOCUMENT } from '@lumx/react/constants';\n\n/** CSS selector listing all tabbable elements. */\nconst TABBABLE_ELEMENTS_SELECTOR = `a[href]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\nbutton:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ntextarea:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"text\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"radio\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\ninput[type=\"checkbox\"]:not([tabindex=\"-1\"], [disabled], [aria-disabled]),\n[tabindex]:not([tabindex=\"-1\"], [disabled], [aria-disabled])`;\n\n/**\n * Get first and last elements focusable in an element.\n *\n * @param parentElement The element in which to search focusable elements.\n * @return first and last focusable elements\n */\nfunction getFocusable(parentElement: HTMLElement) {\n const focusableElements = parentElement.querySelectorAll<HTMLElement>(TABBABLE_ELEMENTS_SELECTOR);\n\n if (focusableElements.length <= 0) {\n return {};\n }\n\n const first = focusableElements[0];\n const last = focusableElements[focusableElements.length - 1];\n return { first, last };\n}\n\n/**\n * Add a key down event handler to the given root element (document.body by default) to trap the move of focus\n * (TAB and SHIFT-TAB keys) inside the given focusZoneElement.\n * Will focus the given focus element when activating the focus trap.\n *\n * @param focusZoneElement The element in which to trap the focus.\n * @param focusElement The element to focus when the focus trap is activated.\n * @param rootElement The element on which the key down event will be placed.\n */\nexport function useFocusTrap(\n focusZoneElement: HTMLElement | null,\n focusElement?: HTMLElement | null,\n rootElement = DOCUMENT?.body,\n): void {\n useEffect(() => {\n if (rootElement && focusZoneElement) {\n (document.activeElement as HTMLElement)?.blur();\n if (focusElement) {\n focusElement.focus();\n }\n\n const onKeyDown = (evt: KeyboardEvent) => {\n const { key } = evt;\n if (key !== 'Tab') {\n return;\n }\n const focusable = getFocusable(focusZoneElement);\n\n // Prevent focus switch if no focusable available.\n if (!focusable.first) {\n evt.preventDefault();\n return;\n }\n\n if (\n // No previous focus\n !document.activeElement ||\n // Previous focus is at the end of the focus zone.\n (!evt.shiftKey && document.activeElement === focusable.last) ||\n // Previous focus is outside the focus zone\n !focusZoneElement.contains(document.activeElement)\n ) {\n focusable.first.focus();\n evt.preventDefault();\n return;\n }\n\n if (\n // Focus order reversed\n evt.shiftKey &&\n // Previous focus is at the start of the focus zone.\n document.activeElement === focusable.first\n ) {\n focusable.last.focus();\n evt.preventDefault();\n }\n };\n rootElement.addEventListener('keydown', onKeyDown);\n return () => rootElement.removeEventListener('keydown', onKeyDown);\n }\n return undefined;\n }, [focusElement, focusZoneElement, rootElement]);\n}\n"],"names":["TABBABLE_ELEMENTS_SELECTOR","getFocusable","parentElement","focusableElements","querySelectorAll","length","first","last","useFocusTrap","focusZoneElement","focusElement","rootElement","DOCUMENT","body","useEffect","document","activeElement","blur","focus","onKeyDown","evt","key","focusable","preventDefault","shiftKey","contains","addEventListener","removeEventListener","undefined"],"mappings":";;;AAIA;;AACA,IAAMA,0BAA0B,meAAhC;AAQA;;;;;;;AAMA,SAASC,YAAT,CAAsBC,aAAtB,EAAkD;AAC9C,MAAMC,iBAAiB,GAAGD,aAAa,CAACE,gBAAd,CAA4CJ,0BAA5C,CAA1B;;AAEA,MAAIG,iBAAiB,CAACE,MAAlB,IAA4B,CAAhC,EAAmC;AAC/B,WAAO,EAAP;AACH;;AAED,MAAMC,KAAK,GAAGH,iBAAiB,CAAC,CAAD,CAA/B;AACA,MAAMI,IAAI,GAAGJ,iBAAiB,CAACA,iBAAiB,CAACE,MAAlB,GAA2B,CAA5B,CAA9B;AACA,SAAO;AAAEC,IAAAA,KAAK,EAALA,KAAF;AAASC,IAAAA,IAAI,EAAJA;AAAT,GAAP;AACH;AAED;;;;;;;;;;;AASO,SAASC,YAAT,CACHC,gBADG,EAEHC,YAFG,EAIC;AAAA,MADJC,WACI,uEADUC,QACV,aADUA,QACV,uBADUA,QAAQ,CAAEC,IACpB;AACJC,EAAAA,SAAS,CAAC,YAAM;AACZ,QAAIH,WAAW,IAAIF,gBAAnB,EAAqC;AAAA;;AACjC,cAACM,QAAQ,CAACC,aAAV,8CAAyCC,IAAzC;;AACA,UAAIP,YAAJ,EAAkB;AACdA,QAAAA,YAAY,CAACQ,KAAb;AACH;;AAED,UAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,GAAD,EAAwB;AAAA,YAC9BC,GAD8B,GACtBD,GADsB,CAC9BC,GAD8B;;AAEtC,YAAIA,GAAG,KAAK,KAAZ,EAAmB;AACf;AACH;;AACD,YAAMC,SAAS,GAAGrB,YAAY,CAACQ,gBAAD,CAA9B,CALsC;;AAQtC,YAAI,CAACa,SAAS,CAAChB,KAAf,EAAsB;AAClBc,UAAAA,GAAG,CAACG,cAAJ;AACA;AACH;;AAED;AAEI,SAACR,QAAQ,CAACC,aAAV;AAEC,SAACI,GAAG,CAACI,QAAL,IAAiBT,QAAQ,CAACC,aAAT,KAA2BM,SAAS,CAACf,IAFvD;AAIA,SAACE,gBAAgB,CAACgB,QAAjB,CAA0BV,QAAQ,CAACC,aAAnC,CANL,EAOE;AACEM,UAAAA,SAAS,CAAChB,KAAV,CAAgBY,KAAhB;AACAE,UAAAA,GAAG,CAACG,cAAJ;AACA;AACH;;AAED;AAEIH,QAAAA,GAAG,CAACI,QAAJ;AAEAT,QAAAA,QAAQ,CAACC,aAAT,KAA2BM,SAAS,CAAChB,KAJzC,EAKE;AACEgB,UAAAA,SAAS,CAACf,IAAV,CAAeW,KAAf;AACAE,UAAAA,GAAG,CAACG,cAAJ;AACH;AACJ,OAnCD;;AAoCAZ,MAAAA,WAAW,CAACe,gBAAZ,CAA6B,SAA7B,EAAwCP,SAAxC;AACA,aAAO;AAAA,eAAMR,WAAW,CAACgB,mBAAZ,CAAgC,SAAhC,EAA2CR,SAA3C,CAAN;AAAA,OAAP;AACH;;AACD,WAAOS,SAAP;AACH,GA/CQ,EA+CN,CAAClB,YAAD,EAAeD,gBAAf,EAAiCE,WAAjC,CA/CM,CAAT;AAgDH;;;;"}
|
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@juggle/resize-observer": "^3.2.0",
|
|
10
|
-
"@lumx/core": "^2.2.
|
|
11
|
-
"@lumx/icons": "^2.2.
|
|
10
|
+
"@lumx/core": "^2.2.18",
|
|
11
|
+
"@lumx/icons": "^2.2.18",
|
|
12
12
|
"@popperjs/core": "^2.5.4",
|
|
13
13
|
"body-scroll-lock": "^3.1.5",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
@@ -120,6 +120,6 @@
|
|
|
120
120
|
"build:storybook": "cd storybook && ./build"
|
|
121
121
|
},
|
|
122
122
|
"sideEffects": false,
|
|
123
|
-
"version": "2.2.
|
|
124
|
-
"gitHead": "
|
|
123
|
+
"version": "2.2.18",
|
|
124
|
+
"gitHead": "76dbe9453429551c6332560fc8cdb7abab8eeb04"
|
|
125
125
|
}
|
|
@@ -333,7 +333,7 @@ export const DialogWithFocusableElements = ({ theme }: any) => {
|
|
|
333
333
|
label="Checkbox input"
|
|
334
334
|
/>
|
|
335
335
|
|
|
336
|
-
<FlexBox orientation="horizontal">
|
|
336
|
+
<FlexBox orientation="horizontal" hAlign="bottom" gap="regular">
|
|
337
337
|
<DatePickerField
|
|
338
338
|
locale="fr"
|
|
339
339
|
label="Start date"
|
|
@@ -366,6 +366,8 @@ export const DialogWithFocusableElements = ({ theme }: any) => {
|
|
|
366
366
|
))}
|
|
367
367
|
</List>
|
|
368
368
|
</Select>
|
|
369
|
+
|
|
370
|
+
<Button isDisabled>Disabled button (focus ignored)</Button>
|
|
369
371
|
</FlexBox>
|
|
370
372
|
|
|
371
373
|
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */}
|
|
@@ -152,6 +152,8 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithFocusabl
|
|
|
152
152
|
theme="light"
|
|
153
153
|
/>
|
|
154
154
|
<FlexBox
|
|
155
|
+
gap="regular"
|
|
156
|
+
hAlign="bottom"
|
|
155
157
|
orientation="horizontal"
|
|
156
158
|
>
|
|
157
159
|
<DatePickerField
|
|
@@ -210,6 +212,14 @@ exports[`<Dialog> Snapshots and structure should render story DialogWithFocusabl
|
|
|
210
212
|
</ListItem>
|
|
211
213
|
</List>
|
|
212
214
|
</Select>
|
|
215
|
+
<Button
|
|
216
|
+
emphasis="high"
|
|
217
|
+
isDisabled={true}
|
|
218
|
+
size="m"
|
|
219
|
+
theme="light"
|
|
220
|
+
>
|
|
221
|
+
Disabled button (focus ignored)
|
|
222
|
+
</Button>
|
|
213
223
|
</FlexBox>
|
|
214
224
|
<div
|
|
215
225
|
tabIndex={0}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mdiPencil } from '@lumx/icons';
|
|
2
|
-
import { Alignment, Button, Icon, Orientation } from '@lumx/react';
|
|
2
|
+
import { Alignment, Button, Icon, Orientation, Size } from '@lumx/react';
|
|
3
3
|
import { boolean, number, select, text } from '@storybook/addon-knobs';
|
|
4
4
|
import fromPairs from 'lodash/fromPairs';
|
|
5
5
|
import React from 'react';
|
|
@@ -18,6 +18,7 @@ const flexViewKnobConfigs: Array<
|
|
|
18
18
|
['fillSpace', boolean],
|
|
19
19
|
['noShrink', boolean],
|
|
20
20
|
['wrap', boolean],
|
|
21
|
+
['gap', select, [DEFAULT_PROPS.gap, Size.regular, Size.medium, Size.big, Size.huge]],
|
|
21
22
|
['hAlign', select, [DEFAULT_PROPS.hAlign, Alignment.center, Alignment.top, Alignment.bottom]],
|
|
22
23
|
['vAlign', select, [DEFAULT_PROPS.vAlign, Alignment.center, Alignment.right, Alignment.left]],
|
|
23
24
|
['orientation', select, [undefined, Orientation.horizontal, Orientation.vertical]],
|
|
@@ -52,7 +53,7 @@ const setupFlexBoxKnobs = (group: string, knobs: FlexBoxPropName[] = []) =>
|
|
|
52
53
|
const flexChildKnobs: FlexBoxPropName[] = ['fillSpace', 'noShrink', 'marginAuto'];
|
|
53
54
|
|
|
54
55
|
export const Flex = () => (
|
|
55
|
-
<FlexBox {...setupFlexBoxKnobs('-flex container', ['orientation', 'hAlign', 'vAlign', 'wrap'])}>
|
|
56
|
+
<FlexBox {...setupFlexBoxKnobs('-flex container', ['orientation', 'hAlign', 'vAlign', 'wrap', 'gap'])}>
|
|
56
57
|
<FlexBox {...setupFlexBoxKnobs('start', flexChildKnobs)}>
|
|
57
58
|
<Icon icon={mdiPencil} />
|
|
58
59
|
</FlexBox>
|
|
@@ -78,6 +79,16 @@ const vAlign = (prefix?: string) =>
|
|
|
78
79
|
Alignment.center,
|
|
79
80
|
);
|
|
80
81
|
|
|
82
|
+
const orientation = (prefix?: string) =>
|
|
83
|
+
select(
|
|
84
|
+
`${prefix ? `${prefix}: ` : ''}Set orientation`,
|
|
85
|
+
[Orientation.vertical, Orientation.horizontal],
|
|
86
|
+
Orientation.vertical,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const gapSize = (prefix?: string) =>
|
|
90
|
+
select(`${prefix ? `${prefix}: ` : ''}Gap size`, [Size.regular, Size.medium, Size.big, Size.huge], Size.regular);
|
|
91
|
+
|
|
81
92
|
export const HorizontalFlex = () => (
|
|
82
93
|
<FlexBox
|
|
83
94
|
orientation={Orientation.horizontal}
|
|
@@ -122,6 +133,21 @@ export const VerticalFlex = () => (
|
|
|
122
133
|
</FlexBox>
|
|
123
134
|
);
|
|
124
135
|
|
|
136
|
+
export const GapSizeFlex = () => (
|
|
137
|
+
<FlexBox orientation={orientation()} gap={gapSize()}>
|
|
138
|
+
<Button>Item 1</Button>
|
|
139
|
+
<FlexBox vAlign={Alignment.left}>
|
|
140
|
+
<Button>Item 2</Button>
|
|
141
|
+
</FlexBox>
|
|
142
|
+
<FlexBox>
|
|
143
|
+
<Button>Item 3</Button>
|
|
144
|
+
</FlexBox>
|
|
145
|
+
<FlexBox vAlign={Alignment.right}>
|
|
146
|
+
<Button>Item 4</Button>
|
|
147
|
+
</FlexBox>
|
|
148
|
+
</FlexBox>
|
|
149
|
+
);
|
|
150
|
+
|
|
125
151
|
export const WrapFlex = () => (
|
|
126
152
|
<FlexBox
|
|
127
153
|
orientation={Orientation.horizontal}
|
|
@@ -6,7 +6,7 @@ import React, { forwardRef, ReactNode } from 'react';
|
|
|
6
6
|
import { Size } from '..';
|
|
7
7
|
|
|
8
8
|
export type MarginAutoAlignment = Extract<Alignment, 'top' | 'bottom' | 'right' | 'left'>;
|
|
9
|
-
export type GapSize = Extract<Size, 'regular' | 'big' | 'huge'>;
|
|
9
|
+
export type GapSize = Extract<Size, 'regular' | 'medium' | 'big' | 'huge'>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Defines the props of the component.
|
|
@@ -89,6 +89,86 @@ Array [
|
|
|
89
89
|
]
|
|
90
90
|
`;
|
|
91
91
|
|
|
92
|
+
exports[`<FlexBox> Snapshots and structure should render story 'GapSizeFlex' 1`] = `
|
|
93
|
+
Array [
|
|
94
|
+
<div
|
|
95
|
+
className="lumx-flex-box lumx-flex-box--orientation-vertical lumx-flex-box--gap-regular"
|
|
96
|
+
>
|
|
97
|
+
<Button
|
|
98
|
+
emphasis="high"
|
|
99
|
+
size="m"
|
|
100
|
+
theme="light"
|
|
101
|
+
>
|
|
102
|
+
Item 1
|
|
103
|
+
</Button>
|
|
104
|
+
<FlexBox
|
|
105
|
+
vAlign="left"
|
|
106
|
+
>
|
|
107
|
+
<Button
|
|
108
|
+
emphasis="high"
|
|
109
|
+
size="m"
|
|
110
|
+
theme="light"
|
|
111
|
+
>
|
|
112
|
+
Item 2
|
|
113
|
+
</Button>
|
|
114
|
+
</FlexBox>
|
|
115
|
+
<FlexBox>
|
|
116
|
+
<Button
|
|
117
|
+
emphasis="high"
|
|
118
|
+
size="m"
|
|
119
|
+
theme="light"
|
|
120
|
+
>
|
|
121
|
+
Item 3
|
|
122
|
+
</Button>
|
|
123
|
+
</FlexBox>
|
|
124
|
+
<FlexBox
|
|
125
|
+
vAlign="right"
|
|
126
|
+
>
|
|
127
|
+
<Button
|
|
128
|
+
emphasis="high"
|
|
129
|
+
size="m"
|
|
130
|
+
theme="light"
|
|
131
|
+
>
|
|
132
|
+
Item 4
|
|
133
|
+
</Button>
|
|
134
|
+
</FlexBox>
|
|
135
|
+
</div>,
|
|
136
|
+
<div
|
|
137
|
+
className="lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-left"
|
|
138
|
+
>
|
|
139
|
+
<Button
|
|
140
|
+
emphasis="high"
|
|
141
|
+
size="m"
|
|
142
|
+
theme="light"
|
|
143
|
+
>
|
|
144
|
+
Item 2
|
|
145
|
+
</Button>
|
|
146
|
+
</div>,
|
|
147
|
+
<div
|
|
148
|
+
className="lumx-flex-box"
|
|
149
|
+
>
|
|
150
|
+
<Button
|
|
151
|
+
emphasis="high"
|
|
152
|
+
size="m"
|
|
153
|
+
theme="light"
|
|
154
|
+
>
|
|
155
|
+
Item 3
|
|
156
|
+
</Button>
|
|
157
|
+
</div>,
|
|
158
|
+
<div
|
|
159
|
+
className="lumx-flex-box lumx-flex-box--orientation-horizontal lumx-flex-box--v-align-right"
|
|
160
|
+
>
|
|
161
|
+
<Button
|
|
162
|
+
emphasis="high"
|
|
163
|
+
size="m"
|
|
164
|
+
theme="light"
|
|
165
|
+
>
|
|
166
|
+
Item 4
|
|
167
|
+
</Button>
|
|
168
|
+
</div>,
|
|
169
|
+
]
|
|
170
|
+
`;
|
|
171
|
+
|
|
92
172
|
exports[`<FlexBox> Snapshots and structure should render story 'HorizontalFlex' 1`] = `
|
|
93
173
|
Array [
|
|
94
174
|
<div
|
package/src/components/index.ts
CHANGED
|
@@ -163,3 +163,29 @@ export const With3LevelsAndMultiActions = () => {
|
|
|
163
163
|
</SideNavigation>
|
|
164
164
|
);
|
|
165
165
|
};
|
|
166
|
+
|
|
167
|
+
/** Using closeMode="hide" keeps children in DOM on close */
|
|
168
|
+
export const CloseModeHide = () => {
|
|
169
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
170
|
+
const toggleL1 = () => setIsOpen(!isOpen);
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<SideNavigation>
|
|
174
|
+
<SideNavigationItem
|
|
175
|
+
closeMode="hide"
|
|
176
|
+
label="Level 1"
|
|
177
|
+
emphasis={Emphasis.high}
|
|
178
|
+
isOpen={isOpen}
|
|
179
|
+
onClick={toggleL1}
|
|
180
|
+
toggleButtonProps={{ label: 'Toggle' }}
|
|
181
|
+
>
|
|
182
|
+
<SideNavigationItem
|
|
183
|
+
closeMode="hide"
|
|
184
|
+
label="Level 2"
|
|
185
|
+
emphasis={Emphasis.medium}
|
|
186
|
+
toggleButtonProps={{ label: 'Toggle' }}
|
|
187
|
+
/>
|
|
188
|
+
</SideNavigationItem>
|
|
189
|
+
</SideNavigation>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
@@ -2,6 +2,7 @@ import React, { ReactElement } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { mount, shallow } from 'enzyme';
|
|
4
4
|
import 'jest-enzyme';
|
|
5
|
+
import without from 'lodash/without';
|
|
5
6
|
|
|
6
7
|
import { commonTestsSuite, Wrapper } from '@lumx/react/testing/utils';
|
|
7
8
|
import { getBasicClass } from '@lumx/react/utils';
|
|
@@ -51,13 +52,28 @@ describe(`<${SideNavigationItem.displayName}>`, () => {
|
|
|
51
52
|
expect(root).toHaveClassName(CLASSNAME);
|
|
52
53
|
});
|
|
53
54
|
|
|
54
|
-
it('should render correctly with
|
|
55
|
+
it('should render correctly with split actions', () => {
|
|
55
56
|
const { root, wrapper } = setup({ linkProps: { href: 'http://toto.com' }, onClick: () => null });
|
|
56
57
|
expect(wrapper).toMatchSnapshot();
|
|
57
58
|
|
|
58
59
|
expect(root).toExist();
|
|
59
60
|
expect(root).toHaveClassName(CLASSNAME);
|
|
60
61
|
});
|
|
62
|
+
|
|
63
|
+
it('should unmount children by default when closed', () => {
|
|
64
|
+
const { children } = setup({
|
|
65
|
+
children: <SideNavigationItem label="Child 1" toggleButtonProps={{ label: 'Toggle' }} />,
|
|
66
|
+
});
|
|
67
|
+
expect(children).not.toExist();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should keep children in DOM when closed and with closeMode="hide"', () => {
|
|
71
|
+
const { children } = setup({
|
|
72
|
+
closeMode: 'hide',
|
|
73
|
+
children: <SideNavigationItem key="1" label="Child 1" toggleButtonProps={{ label: 'Toggle' }} />,
|
|
74
|
+
});
|
|
75
|
+
expect(children).toExist();
|
|
76
|
+
});
|
|
61
77
|
});
|
|
62
78
|
|
|
63
79
|
// 2. Test defaultProps value and important props custom values.
|
|
@@ -67,7 +83,8 @@ describe(`<${SideNavigationItem.displayName}>`, () => {
|
|
|
67
83
|
it('should use default props', () => {
|
|
68
84
|
const { root } = setup();
|
|
69
85
|
|
|
70
|
-
|
|
86
|
+
const propNames = without(Object.keys(DEFAULT_PROPS), 'closeMode');
|
|
87
|
+
for (const prop of propNames) {
|
|
71
88
|
const className = getBasicClass({ prefix: CLASSNAME, type: prop, value: DEFAULT_PROPS[prop] });
|
|
72
89
|
if (className) {
|
|
73
90
|
expect(root).toHaveClassName(className);
|
|
@@ -41,6 +41,11 @@ export interface SideNavigationItemProps extends GenericProps {
|
|
|
41
41
|
/** Props to pass to the toggle button (minus those already set by the SideNavigationItem props). */
|
|
42
42
|
toggleButtonProps: Pick<IconButtonProps, 'label'> &
|
|
43
43
|
Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color' | 'size'>;
|
|
44
|
+
/**
|
|
45
|
+
* Choose how the children are hidden when closed
|
|
46
|
+
* ('hide' keeps the children in DOM but hide them, 'unmount' remove the children from the DOM).
|
|
47
|
+
*/
|
|
48
|
+
closeMode?: 'hide' | 'unmount';
|
|
44
49
|
/** On action button click callback. */
|
|
45
50
|
onActionClick?(evt: React.MouseEvent): void;
|
|
46
51
|
/** On click callback. */
|
|
@@ -62,6 +67,7 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
|
|
|
62
67
|
*/
|
|
63
68
|
const DEFAULT_PROPS: Partial<SideNavigationItemProps> = {
|
|
64
69
|
emphasis: Emphasis.high,
|
|
70
|
+
closeMode: 'unmount',
|
|
65
71
|
};
|
|
66
72
|
|
|
67
73
|
/**
|
|
@@ -85,12 +91,14 @@ export const SideNavigationItem: Comp<SideNavigationItemProps, HTMLLIElement> =
|
|
|
85
91
|
onActionClick,
|
|
86
92
|
onClick,
|
|
87
93
|
toggleButtonProps,
|
|
94
|
+
closeMode = 'unmount',
|
|
88
95
|
...forwardedProps
|
|
89
96
|
} = props;
|
|
90
97
|
|
|
91
98
|
const content = children && Children.toArray(children).filter(isComponent(SideNavigationItem));
|
|
92
99
|
const hasContent = !isEmpty(content);
|
|
93
100
|
const shouldSplitActions = Boolean(onActionClick);
|
|
101
|
+
const showChildren = hasContent && isOpen;
|
|
94
102
|
|
|
95
103
|
return (
|
|
96
104
|
<li
|
|
@@ -100,7 +108,7 @@ export const SideNavigationItem: Comp<SideNavigationItemProps, HTMLLIElement> =
|
|
|
100
108
|
className,
|
|
101
109
|
handleBasicClasses({
|
|
102
110
|
emphasis,
|
|
103
|
-
isOpen,
|
|
111
|
+
isOpen: showChildren,
|
|
104
112
|
isSelected,
|
|
105
113
|
prefix: CLASSNAME,
|
|
106
114
|
}),
|
|
@@ -151,7 +159,7 @@ export const SideNavigationItem: Comp<SideNavigationItemProps, HTMLLIElement> =
|
|
|
151
159
|
)
|
|
152
160
|
)}
|
|
153
161
|
|
|
154
|
-
{
|
|
162
|
+
{(closeMode === 'hide' || showChildren) && <ul className={`${CLASSNAME}__children`}>{content}</ul>}
|
|
155
163
|
</li>
|
|
156
164
|
);
|
|
157
165
|
});
|
|
@@ -13,7 +13,7 @@ exports[`<SideNavigationItem> Snapshots and structure should render correctly 1`
|
|
|
13
13
|
</li>
|
|
14
14
|
`;
|
|
15
15
|
|
|
16
|
-
exports[`<SideNavigationItem> Snapshots and structure should render correctly with
|
|
16
|
+
exports[`<SideNavigationItem> Snapshots and structure should render correctly with split actions 1`] = `
|
|
17
17
|
<li
|
|
18
18
|
className="lumx-side-navigation-item lumx-side-navigation-item--emphasis-high"
|
|
19
19
|
>
|
|
@@ -95,13 +95,16 @@ export function useTooltipOpen(delay: number | undefined, anchorElement: HTMLEle
|
|
|
95
95
|
);
|
|
96
96
|
|
|
97
97
|
// Attach events
|
|
98
|
-
for (const [node, eventType,
|
|
99
|
-
node.addEventListener(eventType,
|
|
98
|
+
for (const [node, eventType, eventHandler] of events) {
|
|
99
|
+
node.addEventListener(eventType, eventHandler);
|
|
100
100
|
}
|
|
101
101
|
return () => {
|
|
102
|
+
// Clear pending timers.
|
|
103
|
+
if (timer) clearTimeout(timer);
|
|
104
|
+
|
|
102
105
|
// Detach events.
|
|
103
|
-
for (const [node, eventType,
|
|
104
|
-
node.removeEventListener(eventType,
|
|
106
|
+
for (const [node, eventType, eventHandler] of events) {
|
|
107
|
+
node.removeEventListener(eventType, eventHandler);
|
|
105
108
|
}
|
|
106
109
|
};
|
|
107
110
|
}, [anchorElement, delay]);
|
|
@@ -2,6 +2,15 @@ import { useEffect } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { DOCUMENT } from '@lumx/react/constants';
|
|
4
4
|
|
|
5
|
+
/** CSS selector listing all tabbable elements. */
|
|
6
|
+
const TABBABLE_ELEMENTS_SELECTOR = `a[href]:not([tabindex="-1"], [disabled], [aria-disabled]),
|
|
7
|
+
button:not([tabindex="-1"], [disabled], [aria-disabled]),
|
|
8
|
+
textarea:not([tabindex="-1"], [disabled], [aria-disabled]),
|
|
9
|
+
input[type="text"]:not([tabindex="-1"], [disabled], [aria-disabled]),
|
|
10
|
+
input[type="radio"]:not([tabindex="-1"], [disabled], [aria-disabled]),
|
|
11
|
+
input[type="checkbox"]:not([tabindex="-1"], [disabled], [aria-disabled]),
|
|
12
|
+
[tabindex]:not([tabindex="-1"], [disabled], [aria-disabled])`;
|
|
13
|
+
|
|
5
14
|
/**
|
|
6
15
|
* Get first and last elements focusable in an element.
|
|
7
16
|
*
|
|
@@ -9,9 +18,7 @@ import { DOCUMENT } from '@lumx/react/constants';
|
|
|
9
18
|
* @return first and last focusable elements
|
|
10
19
|
*/
|
|
11
20
|
function getFocusable(parentElement: HTMLElement) {
|
|
12
|
-
const focusableElements = parentElement.querySelectorAll<HTMLElement>(
|
|
13
|
-
'a[href]:not([tabindex="-1"]), button:not([tabindex="-1"]), textarea:not([tabindex="-1"]), input[type="text"]:not([tabindex="-1"]), input[type="radio"]:not([tabindex="-1"]), input[type="checkbox"]:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"])',
|
|
14
|
-
);
|
|
21
|
+
const focusableElements = parentElement.querySelectorAll<HTMLElement>(TABBABLE_ELEMENTS_SELECTOR);
|
|
15
22
|
|
|
16
23
|
if (focusableElements.length <= 0) {
|
|
17
24
|
return {};
|
|
@@ -48,21 +55,34 @@ export function useFocusTrap(
|
|
|
48
55
|
if (key !== 'Tab') {
|
|
49
56
|
return;
|
|
50
57
|
}
|
|
51
|
-
const
|
|
58
|
+
const focusable = getFocusable(focusZoneElement);
|
|
52
59
|
|
|
53
60
|
// Prevent focus switch if no focusable available.
|
|
54
|
-
if (!first) {
|
|
61
|
+
if (!focusable.first) {
|
|
62
|
+
evt.preventDefault();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
// No previous focus
|
|
68
|
+
!document.activeElement ||
|
|
69
|
+
// Previous focus is at the end of the focus zone.
|
|
70
|
+
(!evt.shiftKey && document.activeElement === focusable.last) ||
|
|
71
|
+
// Previous focus is outside the focus zone
|
|
72
|
+
!focusZoneElement.contains(document.activeElement)
|
|
73
|
+
) {
|
|
74
|
+
focusable.first.focus();
|
|
55
75
|
evt.preventDefault();
|
|
56
76
|
return;
|
|
57
77
|
}
|
|
58
78
|
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
if (
|
|
80
|
+
// Focus order reversed
|
|
81
|
+
evt.shiftKey &&
|
|
82
|
+
// Previous focus is at the start of the focus zone.
|
|
83
|
+
document.activeElement === focusable.first
|
|
84
|
+
) {
|
|
85
|
+
focusable.last.focus();
|
|
66
86
|
evt.preventDefault();
|
|
67
87
|
}
|
|
68
88
|
};
|
package/types.d.ts
CHANGED
|
@@ -95,6 +95,7 @@ export declare const Size: {
|
|
|
95
95
|
readonly xxl: "xxl";
|
|
96
96
|
readonly tiny: "tiny";
|
|
97
97
|
readonly regular: "regular";
|
|
98
|
+
readonly medium: "medium";
|
|
98
99
|
readonly big: "big";
|
|
99
100
|
readonly huge: "huge";
|
|
100
101
|
};
|
|
@@ -1091,7 +1092,7 @@ export interface FlagProps extends GenericProps {
|
|
|
1091
1092
|
*/
|
|
1092
1093
|
export declare const Flag: Comp<FlagProps, HTMLDivElement>;
|
|
1093
1094
|
export declare type MarginAutoAlignment = Extract<Alignment, "top" | "bottom" | "right" | "left">;
|
|
1094
|
-
export declare type GapSize = Extract<Size, "regular" | "big" | "huge">;
|
|
1095
|
+
export declare type GapSize = Extract<Size, "regular" | "medium" | "big" | "huge">;
|
|
1095
1096
|
/**
|
|
1096
1097
|
* Defines the props of the component.
|
|
1097
1098
|
*/
|
|
@@ -1956,6 +1957,11 @@ export interface SideNavigationItemProps extends GenericProps {
|
|
|
1956
1957
|
linkProps?: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
|
|
1957
1958
|
/** Props to pass to the toggle button (minus those already set by the SideNavigationItem props). */
|
|
1958
1959
|
toggleButtonProps: Pick<IconButtonProps, "label"> & Omit<IconButtonProps, "label" | "onClick" | "icon" | "emphasis" | "color" | "size">;
|
|
1960
|
+
/**
|
|
1961
|
+
* Choose how the children are hidden when closed
|
|
1962
|
+
* ('hide' keeps the children in DOM but hide them, 'unmount' remove the children from the DOM).
|
|
1963
|
+
*/
|
|
1964
|
+
closeMode?: "hide" | "unmount";
|
|
1959
1965
|
/** On action button click callback. */
|
|
1960
1966
|
onActionClick?(evt: React.MouseEvent): void;
|
|
1961
1967
|
/** On click callback. */
|