@lumx/react 3.6.0 → 3.6.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +18 -2
- package/index.js +108 -70
- package/index.js.map +1 -1
- package/package.json +13 -15
- package/src/components/lightbox/Lightbox.stories.tsx +61 -5
- package/src/components/lightbox/Lightbox.tsx +21 -4
- package/src/components/navigation/NavigationItem.tsx +2 -2
- package/src/components/tooltip/Tooltip.stories.tsx +3 -2
- package/src/components/tooltip/Tooltip.test.tsx +32 -0
- package/src/components/tooltip/Tooltip.tsx +4 -3
- package/src/components/tooltip/useInjectTooltipRef.tsx +1 -1
- package/src/components/tooltip/useTooltipOpen.tsx +56 -38
- package/src/components/uploader/Uploader.test.tsx +1 -1
- package/src/stories/controls/image.ts +6 -0
- package/src/utils/forwardRefPolymorphic.ts +2 -2
package/index.d.ts
CHANGED
|
@@ -1422,13 +1422,15 @@ declare const InputLabel: Comp<InputLabelProps, HTMLLabelElement>;
|
|
|
1422
1422
|
/**
|
|
1423
1423
|
* Defines the props of the component.
|
|
1424
1424
|
*/
|
|
1425
|
-
interface LightboxProps extends GenericProps, HasTheme {
|
|
1425
|
+
interface LightboxProps extends GenericProps, HasTheme, Pick<AriaAttributes, 'aria-label' | 'aria-labelledby'> {
|
|
1426
1426
|
/** Props to pass to the close button (minus those already set by the Lightbox props). */
|
|
1427
1427
|
closeButtonProps?: Pick<IconButtonProps, 'label'> & Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;
|
|
1428
1428
|
/** Whether the component is open or not. */
|
|
1429
1429
|
isOpen?: boolean;
|
|
1430
1430
|
/** Reference to the element that triggered modal opening to set focus on. */
|
|
1431
1431
|
parentElement: RefObject<any>;
|
|
1432
|
+
/** Reference to the element that should get the focus when the lightbox opens. By default, the close button or the lightbox itself will take focus. */
|
|
1433
|
+
focusElement?: RefObject<HTMLElement>;
|
|
1432
1434
|
/** Whether to keep the dialog open on clickaway or escape press. */
|
|
1433
1435
|
preventAutoClose?: boolean;
|
|
1434
1436
|
/** Z-axis position. */
|
|
@@ -1676,7 +1678,21 @@ declare type NavigationProps = React.ComponentProps<'nav'> & HasClassName & HasT
|
|
|
1676
1678
|
children?: ReactNode;
|
|
1677
1679
|
orientation?: Orientation;
|
|
1678
1680
|
} & HasAriaLabelOrLabelledBy;
|
|
1679
|
-
declare const Navigation: React.ForwardRefExoticComponent<
|
|
1681
|
+
declare const Navigation: React.ForwardRefExoticComponent<(Omit<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & HasClassName & HasTheme & {
|
|
1682
|
+
/** Content of the navigation. These components should be of type NavigationItem to be rendered */
|
|
1683
|
+
children?: ReactNode;
|
|
1684
|
+
orientation?: Orientation | undefined;
|
|
1685
|
+
} & {
|
|
1686
|
+
'aria-label': string;
|
|
1687
|
+
'aria-labelledby'?: undefined;
|
|
1688
|
+
}, "ref"> | Omit<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & HasClassName & HasTheme & {
|
|
1689
|
+
/** Content of the navigation. These components should be of type NavigationItem to be rendered */
|
|
1690
|
+
children?: ReactNode;
|
|
1691
|
+
orientation?: Orientation | undefined;
|
|
1692
|
+
} & {
|
|
1693
|
+
'aria-labelledby': string;
|
|
1694
|
+
'aria-label'?: undefined;
|
|
1695
|
+
}, "ref">) & React.RefAttributes<HTMLElement>> & {
|
|
1680
1696
|
displayName: string;
|
|
1681
1697
|
className: string;
|
|
1682
1698
|
defaultProps: {
|
package/index.js
CHANGED
|
@@ -25,26 +25,40 @@ import chunk from 'lodash/chunk';
|
|
|
25
25
|
import isUndefined from 'lodash/isUndefined';
|
|
26
26
|
import set from 'lodash/set';
|
|
27
27
|
|
|
28
|
-
function ownKeys(
|
|
29
|
-
var
|
|
28
|
+
function ownKeys(e, r) {
|
|
29
|
+
var t = Object.keys(e);
|
|
30
30
|
if (Object.getOwnPropertySymbols) {
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
return Object.getOwnPropertyDescriptor(
|
|
34
|
-
})),
|
|
31
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
32
|
+
r && (o = o.filter(function (r) {
|
|
33
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
34
|
+
})), t.push.apply(t, o);
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return t;
|
|
37
37
|
}
|
|
38
|
-
function _objectSpread2(
|
|
39
|
-
for (var
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
_defineProperty(
|
|
43
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(
|
|
44
|
-
Object.defineProperty(
|
|
38
|
+
function _objectSpread2(e) {
|
|
39
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
40
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
41
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
42
|
+
_defineProperty(e, r, t[r]);
|
|
43
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
44
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
return
|
|
47
|
+
return e;
|
|
48
|
+
}
|
|
49
|
+
function _toPrimitive(t, r) {
|
|
50
|
+
if ("object" != typeof t || !t) return t;
|
|
51
|
+
var e = t[Symbol.toPrimitive];
|
|
52
|
+
if (void 0 !== e) {
|
|
53
|
+
var i = e.call(t, r || "default");
|
|
54
|
+
if ("object" != typeof i) return i;
|
|
55
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
56
|
+
}
|
|
57
|
+
return ("string" === r ? String : Number)(t);
|
|
58
|
+
}
|
|
59
|
+
function _toPropertyKey(t) {
|
|
60
|
+
var i = _toPrimitive(t, "string");
|
|
61
|
+
return "symbol" == typeof i ? i : String(i);
|
|
48
62
|
}
|
|
49
63
|
function _defineProperty(obj, key, value) {
|
|
50
64
|
key = _toPropertyKey(key);
|
|
@@ -101,20 +115,6 @@ function _objectWithoutProperties(source, excluded) {
|
|
|
101
115
|
}
|
|
102
116
|
return target;
|
|
103
117
|
}
|
|
104
|
-
function _toPrimitive(input, hint) {
|
|
105
|
-
if (typeof input !== "object" || input === null) return input;
|
|
106
|
-
var prim = input[Symbol.toPrimitive];
|
|
107
|
-
if (prim !== undefined) {
|
|
108
|
-
var res = prim.call(input, hint || "default");
|
|
109
|
-
if (typeof res !== "object") return res;
|
|
110
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
111
|
-
}
|
|
112
|
-
return (hint === "string" ? String : Number)(input);
|
|
113
|
-
}
|
|
114
|
-
function _toPropertyKey(arg) {
|
|
115
|
-
var key = _toPrimitive(arg, "string");
|
|
116
|
-
return typeof key === "symbol" ? key : String(key);
|
|
117
|
-
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* Alignments.
|
|
@@ -378,7 +378,7 @@ const CSS_PREFIX = 'lumx';
|
|
|
378
378
|
*/
|
|
379
379
|
const TOOLTIP_HOVER_DELAY = {
|
|
380
380
|
open: 500,
|
|
381
|
-
close:
|
|
381
|
+
close: 500
|
|
382
382
|
};
|
|
383
383
|
|
|
384
384
|
/**
|
|
@@ -3477,7 +3477,7 @@ const ListItem = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
3477
3477
|
}), isClickable({
|
|
3478
3478
|
linkProps,
|
|
3479
3479
|
onItemSelected
|
|
3480
|
-
}) ? /* Clickable list item */
|
|
3480
|
+
}) ? ( /* Clickable list item */
|
|
3481
3481
|
renderLink(_objectSpread2(_objectSpread2({
|
|
3482
3482
|
linkAs,
|
|
3483
3483
|
tabIndex: !isDisabled && role === 'button' ? 0 : undefined,
|
|
@@ -3494,7 +3494,7 @@ const ListItem = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
3494
3494
|
onClick: isDisabled ? undefined : onItemSelected,
|
|
3495
3495
|
onKeyDown,
|
|
3496
3496
|
ref: linkRef
|
|
3497
|
-
}), content) :
|
|
3497
|
+
}), content)) :
|
|
3498
3498
|
/*#__PURE__*/
|
|
3499
3499
|
/* Non clickable list item */
|
|
3500
3500
|
React.createElement("div", {
|
|
@@ -7740,7 +7740,7 @@ InputLabel.displayName = COMPONENT_NAME$A;
|
|
|
7740
7740
|
InputLabel.className = CLASSNAME$x;
|
|
7741
7741
|
InputLabel.defaultProps = DEFAULT_PROPS$t;
|
|
7742
7742
|
|
|
7743
|
-
const _excluded$C = ["ariaLabel", "children", "className", "closeButtonProps", "isOpen", "onClose", "parentElement", "preventAutoClose", "theme", "zIndex"];
|
|
7743
|
+
const _excluded$C = ["aria-labelledby", "ariaLabelledBy", "aria-label", "ariaLabel", "children", "className", "closeButtonProps", "isOpen", "onClose", "parentElement", "focusElement", "preventAutoClose", "theme", "zIndex"];
|
|
7744
7744
|
|
|
7745
7745
|
/**
|
|
7746
7746
|
* Defines the props of the component.
|
|
@@ -7764,15 +7764,18 @@ const CLASSNAME$y = getRootClassName(COMPONENT_NAME$B);
|
|
|
7764
7764
|
* @return React element.
|
|
7765
7765
|
*/
|
|
7766
7766
|
const Lightbox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
7767
|
-
var _childrenRef$current;
|
|
7768
7767
|
const {
|
|
7769
|
-
|
|
7768
|
+
'aria-labelledby': propAriaLabelledBy,
|
|
7769
|
+
ariaLabelledBy = propAriaLabelledBy,
|
|
7770
|
+
'aria-label': propAriaLabel,
|
|
7771
|
+
ariaLabel = propAriaLabel,
|
|
7770
7772
|
children,
|
|
7771
7773
|
className,
|
|
7772
7774
|
closeButtonProps,
|
|
7773
7775
|
isOpen,
|
|
7774
7776
|
onClose,
|
|
7775
7777
|
parentElement,
|
|
7778
|
+
focusElement,
|
|
7776
7779
|
preventAutoClose,
|
|
7777
7780
|
theme,
|
|
7778
7781
|
zIndex
|
|
@@ -7787,6 +7790,8 @@ const Lightbox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
7787
7790
|
const childrenRef = useRef(null);
|
|
7788
7791
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
7789
7792
|
const wrapperRef = useRef(null);
|
|
7793
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
7794
|
+
const closeButtonRef = useRef(null);
|
|
7790
7795
|
|
|
7791
7796
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
7792
7797
|
useDisableBodyScroll(isOpen && wrapperRef.current);
|
|
@@ -7796,7 +7801,11 @@ const Lightbox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
7796
7801
|
|
|
7797
7802
|
// Handle focus trap.
|
|
7798
7803
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
7799
|
-
useFocusTrap(
|
|
7804
|
+
useFocusTrap(
|
|
7805
|
+
// Focus trap zone
|
|
7806
|
+
isOpen && wrapperRef.current,
|
|
7807
|
+
// Focus element (fallback on close button and then on the dialog)
|
|
7808
|
+
(focusElement === null || focusElement === void 0 ? void 0 : focusElement.current) || closeButtonRef.current || wrapperRef.current);
|
|
7800
7809
|
|
|
7801
7810
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
7802
7811
|
const previousOpen = useRef(isOpen);
|
|
@@ -7827,7 +7836,10 @@ const Lightbox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
7827
7836
|
ref: mergeRefs(ref, wrapperRef)
|
|
7828
7837
|
}, forwardedProps, {
|
|
7829
7838
|
"aria-label": ariaLabel,
|
|
7839
|
+
"aria-labelledby": ariaLabelledBy,
|
|
7830
7840
|
"aria-modal": "true",
|
|
7841
|
+
role: "dialog",
|
|
7842
|
+
tabIndex: -1,
|
|
7831
7843
|
className: classnames(className, handleBasicClasses({
|
|
7832
7844
|
prefix: CLASSNAME$y,
|
|
7833
7845
|
isHidden: !isOpen,
|
|
@@ -7838,6 +7850,7 @@ const Lightbox = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
7838
7850
|
zIndex
|
|
7839
7851
|
}
|
|
7840
7852
|
}), closeButtonProps && /*#__PURE__*/React.createElement(IconButton, _extends({}, closeButtonProps, {
|
|
7853
|
+
ref: closeButtonRef,
|
|
7841
7854
|
className: `${CLASSNAME$y}__close`,
|
|
7842
7855
|
color: ColorPalette.light,
|
|
7843
7856
|
emphasis: Emphasis.low,
|
|
@@ -11873,15 +11886,16 @@ const TabProvider = props => {
|
|
|
11873
11886
|
TabProvider.defaultProps = DEFAULT_PROPS$W;
|
|
11874
11887
|
|
|
11875
11888
|
const _excluded$1i = ["aria-label", "children", "className", "layout", "position", "theme"];
|
|
11876
|
-
let TabListLayout
|
|
11889
|
+
let TabListLayout = /*#__PURE__*/function (TabListLayout) {
|
|
11890
|
+
TabListLayout["clustered"] = "clustered";
|
|
11891
|
+
TabListLayout["fixed"] = "fixed";
|
|
11892
|
+
return TabListLayout;
|
|
11893
|
+
}({});
|
|
11877
11894
|
|
|
11878
11895
|
/**
|
|
11879
11896
|
* Defines the props of the component.
|
|
11880
11897
|
*/
|
|
11881
|
-
|
|
11882
|
-
TabListLayout["clustered"] = "clustered";
|
|
11883
|
-
TabListLayout["fixed"] = "fixed";
|
|
11884
|
-
})(TabListLayout || (TabListLayout = {}));
|
|
11898
|
+
|
|
11885
11899
|
/**
|
|
11886
11900
|
* Component display name.
|
|
11887
11901
|
*/
|
|
@@ -12828,6 +12842,11 @@ const browserDoesNotSupportHover = () => {
|
|
|
12828
12842
|
*/
|
|
12829
12843
|
function useTooltipOpen(delay, anchorElement) {
|
|
12830
12844
|
const [isOpen, setIsOpen] = useState(false);
|
|
12845
|
+
const onPopperMount = useRef(null);
|
|
12846
|
+
|
|
12847
|
+
// Global close on escape
|
|
12848
|
+
const [closeCallback, setCloseCallback] = useState(undefined);
|
|
12849
|
+
useCallbackOnEscape(closeCallback);
|
|
12831
12850
|
useEffect(() => {
|
|
12832
12851
|
if (!anchorElement) {
|
|
12833
12852
|
return undefined;
|
|
@@ -12859,45 +12878,57 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
12859
12878
|
};
|
|
12860
12879
|
|
|
12861
12880
|
// Close or cancel opening of tooltip
|
|
12862
|
-
const
|
|
12881
|
+
const getClose = function () {
|
|
12863
12882
|
let overrideDelay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : closeDelay;
|
|
12864
12883
|
if (!shouldOpen && !timer) return;
|
|
12865
12884
|
shouldOpen = false;
|
|
12866
12885
|
deferUpdate(overrideDelay);
|
|
12867
12886
|
};
|
|
12868
|
-
const
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
* Handle touchend event
|
|
12872
|
-
* If `touchend` comes before the open delay => cancel tooltip (close immediate).
|
|
12873
|
-
* Else if `touchend` comes after the open delay => tooltip takes priority, the anchor's default touch end event is prevented.
|
|
12874
|
-
*/
|
|
12875
|
-
const touchEnd = evt => {
|
|
12876
|
-
if (!openStartTime) return;
|
|
12877
|
-
if (Date.now() - openStartTime >= openDelay) {
|
|
12878
|
-
// Tooltip take priority, event prevented.
|
|
12879
|
-
evt.stopPropagation();
|
|
12880
|
-
evt.preventDefault();
|
|
12881
|
-
anchorElement.focus();
|
|
12882
|
-
// Close with delay.
|
|
12883
|
-
close();
|
|
12884
|
-
} else {
|
|
12885
|
-
// Close immediately.
|
|
12886
|
-
closeImmediately();
|
|
12887
|
-
}
|
|
12888
|
-
};
|
|
12887
|
+
const close = () => getClose(closeDelay);
|
|
12888
|
+
const closeImmediately = () => getClose(0);
|
|
12889
|
+
setCloseCallback(() => closeImmediately);
|
|
12889
12890
|
|
|
12890
12891
|
// Adapt event to browsers with or without `hover` support.
|
|
12891
|
-
const events =
|
|
12892
|
+
const events = [];
|
|
12893
|
+
if (hoverNotSupported) {
|
|
12894
|
+
/**
|
|
12895
|
+
* Handle touchend event
|
|
12896
|
+
* If end comes before the open delay => cancel tooltip (close immediate).
|
|
12897
|
+
* Else if end comes after the open delay => tooltip takes priority, the anchor's default touch end event is prevented.
|
|
12898
|
+
*/
|
|
12899
|
+
const longPressEnd = evt => {
|
|
12900
|
+
if (!openStartTime) return;
|
|
12901
|
+
if (Date.now() - openStartTime >= openDelay) {
|
|
12902
|
+
// Tooltip take priority, event prevented.
|
|
12903
|
+
evt.stopPropagation();
|
|
12904
|
+
evt.preventDefault();
|
|
12905
|
+
anchorElement.focus();
|
|
12906
|
+
// Close with delay.
|
|
12907
|
+
close();
|
|
12908
|
+
} else {
|
|
12909
|
+
// Close immediately.
|
|
12910
|
+
closeImmediately();
|
|
12911
|
+
}
|
|
12912
|
+
};
|
|
12913
|
+
events.push([anchorElement, hasTouch ? 'touchstart' : 'mousedown', open], [anchorElement, hasTouch ? 'touchend' : 'mouseup', longPressEnd]);
|
|
12914
|
+
} else {
|
|
12915
|
+
events.push([anchorElement, 'mouseenter', open], [anchorElement, 'mouseleave', close], [anchorElement, 'mouseup', closeImmediately]);
|
|
12916
|
+
onPopperMount.current = popperElement => {
|
|
12917
|
+
if (!popperElement) return;
|
|
12918
|
+
// Popper element hover
|
|
12919
|
+
popperElement.addEventListener('mouseenter', open);
|
|
12920
|
+
popperElement.addEventListener('mouseleave', close);
|
|
12921
|
+
// Add to event list to remove on unmount
|
|
12922
|
+
events.push([popperElement, 'mouseenter', open], [popperElement, 'mouseleave', close]);
|
|
12923
|
+
};
|
|
12924
|
+
}
|
|
12892
12925
|
|
|
12893
12926
|
// Events always applied no matter the browser:.
|
|
12894
12927
|
events.push(
|
|
12895
12928
|
// Open on focus.
|
|
12896
12929
|
[anchorElement, 'focusin', open],
|
|
12897
12930
|
// Close on lost focus.
|
|
12898
|
-
[anchorElement, 'focusout', closeImmediately]
|
|
12899
|
-
// Close on ESC keydown
|
|
12900
|
-
[anchorElement, 'keydown', onEscapePressed(closeImmediately)]);
|
|
12931
|
+
[anchorElement, 'focusout', closeImmediately]);
|
|
12901
12932
|
|
|
12902
12933
|
// Attach events
|
|
12903
12934
|
for (const [node, eventType, eventHandler] of events) {
|
|
@@ -12913,7 +12944,10 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
12913
12944
|
}
|
|
12914
12945
|
};
|
|
12915
12946
|
}, [anchorElement, delay]);
|
|
12916
|
-
return
|
|
12947
|
+
return {
|
|
12948
|
+
isOpen,
|
|
12949
|
+
onPopperMount: onPopperMount.current
|
|
12950
|
+
};
|
|
12917
12951
|
}
|
|
12918
12952
|
|
|
12919
12953
|
const _excluded$1o = ["label", "children", "className", "delay", "placement", "forceOpen"];
|
|
@@ -12984,10 +13018,14 @@ const Tooltip = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
12984
13018
|
}]
|
|
12985
13019
|
});
|
|
12986
13020
|
const position = (_attributes$popper$da = attributes === null || attributes === void 0 ? void 0 : (_attributes$popper = attributes.popper) === null || _attributes$popper === void 0 ? void 0 : _attributes$popper['data-popper-placement']) !== null && _attributes$popper$da !== void 0 ? _attributes$popper$da : placement;
|
|
12987
|
-
const
|
|
13021
|
+
const {
|
|
13022
|
+
isOpen: isActivated,
|
|
13023
|
+
onPopperMount
|
|
13024
|
+
} = useTooltipOpen(delay, anchorElement);
|
|
13025
|
+
const isOpen = isActivated || forceOpen;
|
|
12988
13026
|
const wrappedChildren = useInjectTooltipRef(children, setAnchorElement, isOpen, id);
|
|
12989
13027
|
return /*#__PURE__*/React.createElement(React.Fragment, null, wrappedChildren, isOpen && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", _extends({
|
|
12990
|
-
ref: mergeRefs(ref, setPopperElement)
|
|
13028
|
+
ref: mergeRefs(ref, setPopperElement, onPopperMount)
|
|
12991
13029
|
}, forwardedProps, {
|
|
12992
13030
|
id: id,
|
|
12993
13031
|
role: "tooltip",
|