@lumx/react 3.9.1 → 3.9.2-alpha.1
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/_internal/types.d.ts +8 -1
- package/index.d.ts +4 -9
- package/index.js +34 -18
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/popover/usePopoverStyle.tsx +2 -2
- package/src/components/side-navigation/SideNavigationItem.tsx +2 -7
- package/src/components/tooltip/Tooltip.stories.tsx +8 -0
- package/src/components/tooltip/Tooltip.test.tsx +23 -13
- package/src/components/tooltip/Tooltip.tsx +30 -15
- package/src/components/tooltip/useTooltipOpen.tsx +6 -3
- package/src/constants.ts +5 -0
- package/src/utils/type.ts +9 -0
package/_internal/types.d.ts
CHANGED
|
@@ -32,6 +32,13 @@ interface HasClassName {
|
|
|
32
32
|
*/
|
|
33
33
|
className?: string;
|
|
34
34
|
}
|
|
35
|
+
interface HasCloseMode {
|
|
36
|
+
/**
|
|
37
|
+
* Choose how the children are hidden when closed
|
|
38
|
+
* ('hide' keeps the children in DOM but hide them, 'unmount' remove the children from the DOM).
|
|
39
|
+
*/
|
|
40
|
+
closeMode?: 'hide' | 'unmount';
|
|
41
|
+
}
|
|
35
42
|
/**
|
|
36
43
|
* Define a generic props types.
|
|
37
44
|
*/
|
|
@@ -318,4 +325,4 @@ declare const ThumbnailObjectFit: {
|
|
|
318
325
|
};
|
|
319
326
|
type ThumbnailObjectFit = ValueOf<typeof ThumbnailObjectFit>;
|
|
320
327
|
|
|
321
|
-
export { Alignment as A, Comp as C, Emphasis as E, Falsy as F, GenericProps as G, HasTheme as H, Kind as K, Orientation as O, Size as S, Typography as T, ValueOf as V, WhiteSpace as W, HorizontalAlignment as a, ColorPalette as b, VerticalAlignment as c, ColorVariant as d, TextElement as e, HeadingElement as f, AspectRatio as g, FocusPoint as h, ThumbnailObjectFit as i, ThumbnailSize as j, ThumbnailVariant as k, HasClassName as l, HasAriaLabelOrLabelledBy as m, ComponentRef as n,
|
|
328
|
+
export { Alignment as A, Comp as C, Emphasis as E, Falsy as F, GenericProps as G, HasTheme as H, Kind as K, Orientation as O, Size as S, Typography as T, ValueOf as V, WhiteSpace as W, HorizontalAlignment as a, ColorPalette as b, VerticalAlignment as c, ColorVariant as d, TextElement as e, HeadingElement as f, AspectRatio as g, FocusPoint as h, ThumbnailObjectFit as i, ThumbnailSize as j, ThumbnailVariant as k, HasClassName as l, HasAriaLabelOrLabelledBy as m, ComponentRef as n, HasCloseMode as o, GlobalSize as p, TypographyInterface as q, Color as r, Theme as s, TypographyTitleCustom as t, TypographyCustom as u, Callback as v, ThumbnailAspectRatio as w };
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode, SyntheticEvent, ReactElement, MouseEventHandler, KeyboardEventHandler, AriaAttributes, DetailedHTMLProps, ButtonHTMLAttributes, InputHTMLAttributes, Ref, RefObject, ImgHTMLAttributes, CSSProperties, SetStateAction, Key } from 'react';
|
|
2
|
-
import { K as Kind, C as Comp, G as GenericProps, H as HasTheme, a as HorizontalAlignment, S as Size, b as ColorPalette, E as Emphasis, V as ValueOf, A as Alignment, c as VerticalAlignment, O as Orientation, d as ColorVariant, T as Typography, e as TextElement, W as WhiteSpace, f as HeadingElement, g as AspectRatio, F as Falsy, h as FocusPoint, i as ThumbnailObjectFit, j as ThumbnailSize, k as ThumbnailVariant, l as HasClassName, m as HasAriaLabelOrLabelledBy, n as ComponentRef, o as
|
|
3
|
-
export { A as Alignment, g as AspectRatio,
|
|
2
|
+
import { K as Kind, C as Comp, G as GenericProps, H as HasTheme, a as HorizontalAlignment, S as Size, b as ColorPalette, E as Emphasis, V as ValueOf, A as Alignment, c as VerticalAlignment, O as Orientation, d as ColorVariant, T as Typography, e as TextElement, W as WhiteSpace, f as HeadingElement, g as AspectRatio, F as Falsy, h as FocusPoint, i as ThumbnailObjectFit, j as ThumbnailSize, k as ThumbnailVariant, l as HasClassName, m as HasAriaLabelOrLabelledBy, n as ComponentRef, o as HasCloseMode, p as GlobalSize, q as TypographyInterface } from './_internal/types.js';
|
|
3
|
+
export { A as Alignment, g as AspectRatio, v as Callback, r as Color, b as ColorPalette, d as ColorVariant, E as Emphasis, h as FocusPoint, G as GenericProps, p as GlobalSize, f as HeadingElement, a as HorizontalAlignment, K as Kind, O as Orientation, S as Size, e as TextElement, s as Theme, w as ThumbnailAspectRatio, i as ThumbnailObjectFit, j as ThumbnailSize, k as ThumbnailVariant, T as Typography, u as TypographyCustom, q as TypographyInterface, t as TypographyTitleCustom, c as VerticalAlignment, W as WhiteSpace } from './_internal/types.js';
|
|
4
4
|
|
|
5
5
|
interface AlertDialogProps extends Omit<DialogProps, 'header' | 'footer'> {
|
|
6
6
|
/** Message variant. */
|
|
@@ -2209,7 +2209,7 @@ declare const SideNavigation: Comp<SideNavigationProps, HTMLUListElement>;
|
|
|
2209
2209
|
/**
|
|
2210
2210
|
* Defines the props of the component.
|
|
2211
2211
|
*/
|
|
2212
|
-
interface SideNavigationItemProps extends GenericProps {
|
|
2212
|
+
interface SideNavigationItemProps extends GenericProps, HasCloseMode {
|
|
2213
2213
|
/** SideNavigationItem elements. */
|
|
2214
2214
|
children?: ReactNode;
|
|
2215
2215
|
/** Emphasis variant. */
|
|
@@ -2228,11 +2228,6 @@ interface SideNavigationItemProps extends GenericProps {
|
|
|
2228
2228
|
linkProps?: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
|
|
2229
2229
|
/** Props to pass to the toggle button (minus those already set by the SideNavigationItem props). */
|
|
2230
2230
|
toggleButtonProps: Pick<IconButtonProps, 'label'> & Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color' | 'size'>;
|
|
2231
|
-
/**
|
|
2232
|
-
* Choose how the children are hidden when closed
|
|
2233
|
-
* ('hide' keeps the children in DOM but hide them, 'unmount' remove the children from the DOM).
|
|
2234
|
-
*/
|
|
2235
|
-
closeMode?: 'hide' | 'unmount';
|
|
2236
2231
|
/** On action button click callback. */
|
|
2237
2232
|
onActionClick?(evt: React.MouseEvent): void;
|
|
2238
2233
|
/** On click callback. */
|
|
@@ -2872,7 +2867,7 @@ type TooltipPlacement = Extract<Placement, 'top' | 'right' | 'bottom' | 'left'>;
|
|
|
2872
2867
|
/**
|
|
2873
2868
|
* Defines the props of the component.
|
|
2874
2869
|
*/
|
|
2875
|
-
interface TooltipProps extends GenericProps {
|
|
2870
|
+
interface TooltipProps extends GenericProps, HasCloseMode {
|
|
2876
2871
|
/** Anchor (element on which we activate the tooltip). */
|
|
2877
2872
|
children: ReactNode;
|
|
2878
2873
|
/** Delay (in ms) before closing the tooltip. */
|
package/index.js
CHANGED
|
@@ -383,6 +383,11 @@ const WINDOW = typeof window !== 'undefined' ? window : undefined;
|
|
|
383
383
|
*/
|
|
384
384
|
const DOCUMENT = typeof document !== 'undefined' ? document : undefined;
|
|
385
385
|
|
|
386
|
+
/**
|
|
387
|
+
* Check if we are running in the simulated DOM jsdom environment
|
|
388
|
+
*/
|
|
389
|
+
const IS_JSDOM_ENV = typeof navigator !== 'undefined' && navigator.userAgent.includes('jsdom');
|
|
390
|
+
|
|
386
391
|
const _excluded = ["prefix"];
|
|
387
392
|
|
|
388
393
|
/**
|
|
@@ -6477,7 +6482,7 @@ function usePopoverStyle(_ref5) {
|
|
|
6477
6482
|
zIndex
|
|
6478
6483
|
} = _ref5;
|
|
6479
6484
|
const [popperElement, setPopperElement] = useState(null);
|
|
6480
|
-
if (
|
|
6485
|
+
if (IS_JSDOM_ENV) {
|
|
6481
6486
|
// Skip all logic; we don't need popover positioning in jsdom.
|
|
6482
6487
|
return {
|
|
6483
6488
|
styles: {},
|
|
@@ -13984,9 +13989,11 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
13984
13989
|
// Run timer to defer updating the isOpen state.
|
|
13985
13990
|
const deferUpdate = duration => {
|
|
13986
13991
|
if (timer) clearTimeout(timer);
|
|
13987
|
-
|
|
13992
|
+
const update = () => {
|
|
13988
13993
|
setIsOpen(!!shouldOpen);
|
|
13989
|
-
}
|
|
13994
|
+
};
|
|
13995
|
+
// Skip timeout in jsdom env
|
|
13996
|
+
if (IS_JSDOM_ENV) update();else timer = setTimeout(update, duration);
|
|
13990
13997
|
};
|
|
13991
13998
|
const hoverNotSupported = browserDoesNotSupportHover();
|
|
13992
13999
|
const hasTouch = ('ontouchstart' in window);
|
|
@@ -14080,7 +14087,7 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
14080
14087
|
};
|
|
14081
14088
|
}
|
|
14082
14089
|
|
|
14083
|
-
const _excluded$1q = ["label", "children", "className", "delay", "placement", "forceOpen"];
|
|
14090
|
+
const _excluded$1q = ["label", "children", "className", "delay", "placement", "forceOpen", "closeMode"];
|
|
14084
14091
|
|
|
14085
14092
|
/** Position of the tooltip relative to the anchor element. */
|
|
14086
14093
|
|
|
@@ -14102,7 +14109,8 @@ const CLASSNAME$1h = getRootClassName(COMPONENT_NAME$1k);
|
|
|
14102
14109
|
* Component default props.
|
|
14103
14110
|
*/
|
|
14104
14111
|
const DEFAULT_PROPS$11 = {
|
|
14105
|
-
placement: Placement.BOTTOM
|
|
14112
|
+
placement: Placement.BOTTOM,
|
|
14113
|
+
closeMode: 'unmount'
|
|
14106
14114
|
};
|
|
14107
14115
|
|
|
14108
14116
|
/**
|
|
@@ -14110,6 +14118,9 @@ const DEFAULT_PROPS$11 = {
|
|
|
14110
14118
|
*/
|
|
14111
14119
|
const ARROW_SIZE$1 = 8;
|
|
14112
14120
|
|
|
14121
|
+
// Skip popper logic in jsdom env
|
|
14122
|
+
const usePopperHook = IS_JSDOM_ENV ? () => ({}) : usePopper;
|
|
14123
|
+
|
|
14113
14124
|
/**
|
|
14114
14125
|
* Tooltip component.
|
|
14115
14126
|
*
|
|
@@ -14125,20 +14136,21 @@ const Tooltip = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
14125
14136
|
className,
|
|
14126
14137
|
delay,
|
|
14127
14138
|
placement,
|
|
14128
|
-
forceOpen
|
|
14139
|
+
forceOpen,
|
|
14140
|
+
closeMode
|
|
14129
14141
|
} = props,
|
|
14130
14142
|
forwardedProps = _objectWithoutProperties(props, _excluded$1q);
|
|
14131
14143
|
// Disable in SSR.
|
|
14132
|
-
if (!DOCUMENT) {
|
|
14144
|
+
if (!DOCUMENT && closeMode === 'unmount') {
|
|
14133
14145
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
14134
14146
|
}
|
|
14135
14147
|
const id = useId();
|
|
14136
14148
|
const [popperElement, setPopperElement] = useState(null);
|
|
14137
14149
|
const [anchorElement, setAnchorElement] = useState(null);
|
|
14138
14150
|
const {
|
|
14139
|
-
styles,
|
|
14140
|
-
attributes
|
|
14141
|
-
} =
|
|
14151
|
+
styles = {},
|
|
14152
|
+
attributes = {}
|
|
14153
|
+
} = usePopperHook(anchorElement, popperElement, {
|
|
14142
14154
|
placement,
|
|
14143
14155
|
modifiers: [{
|
|
14144
14156
|
name: 'offset',
|
|
@@ -14153,25 +14165,29 @@ const Tooltip = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
14153
14165
|
onPopperMount
|
|
14154
14166
|
} = useTooltipOpen(delay, anchorElement);
|
|
14155
14167
|
const isOpen = (isActivated || forceOpen) && !!label;
|
|
14156
|
-
const
|
|
14157
|
-
|
|
14158
|
-
|
|
14168
|
+
const isMounted = isOpen || closeMode === 'hide';
|
|
14169
|
+
const wrappedChildren = useInjectTooltipRef(children, setAnchorElement, isMounted, id, label);
|
|
14170
|
+
const labelLines = label ? label.split('\n') : [];
|
|
14171
|
+
const tooltipRef = useMergeRefs(ref, setPopperElement, onPopperMount);
|
|
14172
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TooltipContextProvider, null, wrappedChildren), isMounted && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", _extends({
|
|
14173
|
+
ref: tooltipRef
|
|
14159
14174
|
}, forwardedProps, {
|
|
14160
14175
|
id: id,
|
|
14161
14176
|
role: "tooltip",
|
|
14162
|
-
"aria-label": label,
|
|
14177
|
+
"aria-label": label || '',
|
|
14163
14178
|
className: classnames(className, handleBasicClasses({
|
|
14164
14179
|
prefix: CLASSNAME$1h,
|
|
14165
|
-
position
|
|
14180
|
+
position,
|
|
14181
|
+
hidden: !isOpen && closeMode === 'hide'
|
|
14166
14182
|
})),
|
|
14167
14183
|
style: styles.popper
|
|
14168
14184
|
}, attributes.popper), /*#__PURE__*/React.createElement("div", {
|
|
14169
14185
|
className: `${CLASSNAME$1h}__arrow`
|
|
14170
14186
|
}), /*#__PURE__*/React.createElement("div", {
|
|
14171
14187
|
className: `${CLASSNAME$1h}__inner`
|
|
14172
|
-
},
|
|
14173
|
-
key:
|
|
14174
|
-
},
|
|
14188
|
+
}, labelLines.map(line => /*#__PURE__*/React.createElement("p", {
|
|
14189
|
+
key: line
|
|
14190
|
+
}, line)))), document.body));
|
|
14175
14191
|
});
|
|
14176
14192
|
Tooltip.displayName = COMPONENT_NAME$1k;
|
|
14177
14193
|
Tooltip.className = CLASSNAME$1h;
|