@lumx/react 4.4.1-alpha.1 → 4.4.1-alpha.3
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/{DpdvhbTO.js → BfgxEBp6.js} +61 -28
- package/_internal/BfgxEBp6.js.map +1 -0
- package/index.d.ts +26 -10
- package/index.js +291 -181
- package/index.js.map +1 -1
- package/package.json +4 -6
- package/utils/index.d.ts +22 -5
- package/utils/index.js +1 -1
- package/_internal/DpdvhbTO.js.map +0 -1
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Kind as Kind$1, Size as Size$1, ColorPalette as ColorPalette$1, Emphasis as Emphasis$1, ColorVariant, Theme as Theme$1, AspectRatio as AspectRatio$1, DIALOG_TRANSITION_DURATION, Orientation as Orientation$1, Alignment, NOTIFICATION_TRANSITION_DURATION
|
|
1
|
+
import { Kind as Kind$1, Size as Size$1, ColorPalette as ColorPalette$1, Emphasis as Emphasis$1, ColorVariant, VISUALLY_HIDDEN, Theme as Theme$1, AspectRatio as AspectRatio$1, DOCUMENT, WINDOW, DIALOG_TRANSITION_DURATION, IS_BROWSER as IS_BROWSER$1, Orientation as Orientation$1, Alignment, NOTIFICATION_TRANSITION_DURATION } from '@lumx/core/js/constants';
|
|
2
2
|
export * from '@lumx/core/js/constants';
|
|
3
3
|
export * from '@lumx/core/js/types';
|
|
4
4
|
import * as React from 'react';
|
|
@@ -16,7 +16,7 @@ import concat from 'lodash/concat.js';
|
|
|
16
16
|
import dropRight from 'lodash/dropRight.js';
|
|
17
17
|
import partition from 'lodash/partition.js';
|
|
18
18
|
import reduce from 'lodash/reduce.js';
|
|
19
|
-
import { u as useDisabledStateContext, P as Portal, C as ClickAwayProvider } from './_internal/
|
|
19
|
+
import { u as useDisabledStateContext, P as Portal, C as ClickAwayProvider } from './_internal/BfgxEBp6.js';
|
|
20
20
|
import isEmpty from 'lodash/isEmpty.js';
|
|
21
21
|
import { getDisabledState } from '@lumx/core/js/utils/disabledState';
|
|
22
22
|
import { mdiCloseCircle } from '@lumx/icons/esm/close-circle.js';
|
|
@@ -676,6 +676,12 @@ function typography(typo) {
|
|
|
676
676
|
return `lumx-typography-${typo}`;
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Visually hidden class name.
|
|
681
|
+
* Used to hide elements from view but keep them readable from screen readers
|
|
682
|
+
*/
|
|
683
|
+
const visuallyHidden = () => VISUALLY_HIDDEN;
|
|
684
|
+
|
|
679
685
|
/**
|
|
680
686
|
* Modifier
|
|
681
687
|
* @example { 'is-disabled': true, 'is-selected': false }
|
|
@@ -778,6 +784,29 @@ function bem(baseName) {
|
|
|
778
784
|
};
|
|
779
785
|
}
|
|
780
786
|
|
|
787
|
+
/**
|
|
788
|
+
* Animation duration constants. Take into consideration that if you change one of these variables,
|
|
789
|
+
* you need to update their scss counterpart as well
|
|
790
|
+
*/
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Delay on hover after which we open or close the tooltip.
|
|
794
|
+
* Only applies to devices supporting pointer hover.
|
|
795
|
+
*/
|
|
796
|
+
const TOOLTIP_HOVER_DELAY = {
|
|
797
|
+
open: 500,
|
|
798
|
+
close: 500
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Delay on long press after which we open or close the tooltip.
|
|
803
|
+
* Only applies to devices not supporting pointer hover.
|
|
804
|
+
*/
|
|
805
|
+
const TOOLTIP_LONG_PRESS_DELAY = {
|
|
806
|
+
open: 250,
|
|
807
|
+
close: 3000
|
|
808
|
+
};
|
|
809
|
+
|
|
781
810
|
/**
|
|
782
811
|
* Alignments.
|
|
783
812
|
*/
|
|
@@ -844,6 +873,11 @@ const ColorPalette = {
|
|
|
844
873
|
red: 'red',
|
|
845
874
|
light: 'light'};
|
|
846
875
|
|
|
876
|
+
/**
|
|
877
|
+
* Check if we are running in a true browser (not SSR and not jsdom test environment).
|
|
878
|
+
*/
|
|
879
|
+
const IS_BROWSER = typeof window !== 'undefined' && !window.navigator.userAgent.includes('jsdom');
|
|
880
|
+
|
|
847
881
|
/**
|
|
848
882
|
* Component display name.
|
|
849
883
|
*/
|
|
@@ -2985,21 +3019,6 @@ const DatePickerField = forwardRef((props, ref) => {
|
|
|
2985
3019
|
});
|
|
2986
3020
|
DatePickerField.displayName = COMPONENT_NAME$11;
|
|
2987
3021
|
|
|
2988
|
-
/**
|
|
2989
|
-
* Optional global `window` instance (not defined when running SSR).
|
|
2990
|
-
*/
|
|
2991
|
-
const WINDOW = typeof window !== 'undefined' ? window : undefined;
|
|
2992
|
-
|
|
2993
|
-
/**
|
|
2994
|
-
* Optional global `document` instance (not defined when running SSR).
|
|
2995
|
-
*/
|
|
2996
|
-
const DOCUMENT = typeof document !== 'undefined' ? document : undefined;
|
|
2997
|
-
|
|
2998
|
-
/**
|
|
2999
|
-
* Check if we are running in a true browser
|
|
3000
|
-
*/
|
|
3001
|
-
const IS_BROWSER = typeof navigator !== 'undefined' && !navigator.userAgent.includes('jsdom');
|
|
3002
|
-
|
|
3003
3022
|
/**
|
|
3004
3023
|
* Keep track of listeners, only the last registered listener gets activated at any point (previously registered
|
|
3005
3024
|
* listener are disabled).
|
|
@@ -6398,12 +6417,16 @@ function usePopoverStyle({
|
|
|
6398
6417
|
middlewareData
|
|
6399
6418
|
} = useFloating({
|
|
6400
6419
|
placement: floatingPlacement,
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6420
|
+
// Disable autoUpdate and element refs in non-browser environments (e.g. jsdom) to avoid
|
|
6421
|
+
// flushSync act() warnings from @floating-ui/react-dom (positioning is not meaningful in jsdom anyway).
|
|
6422
|
+
...(IS_BROWSER$1 ? {
|
|
6423
|
+
whileElementsMounted: autoUpdate,
|
|
6424
|
+
elements: {
|
|
6425
|
+
reference: anchorElement,
|
|
6426
|
+
floating: popperElement
|
|
6427
|
+
}
|
|
6428
|
+
} : {}),
|
|
6429
|
+
middleware
|
|
6407
6430
|
});
|
|
6408
6431
|
const position = resolvedPlacement ?? placement;
|
|
6409
6432
|
|
|
@@ -6804,7 +6827,7 @@ const ExpansionPanel = forwardRef((props, ref) => {
|
|
|
6804
6827
|
React__default.useEffect(() => {
|
|
6805
6828
|
if (isOpen || closeMode === 'hide') {
|
|
6806
6829
|
setChildrenVisible(true);
|
|
6807
|
-
} else if (!IS_BROWSER) {
|
|
6830
|
+
} else if (!IS_BROWSER$1) {
|
|
6808
6831
|
// Outside a browser we can't wait for the transition
|
|
6809
6832
|
setChildrenVisible(false);
|
|
6810
6833
|
}
|
|
@@ -6816,7 +6839,7 @@ const ExpansionPanel = forwardRef((props, ref) => {
|
|
|
6816
6839
|
const {
|
|
6817
6840
|
current: wrapper
|
|
6818
6841
|
} = wrapperRef;
|
|
6819
|
-
if (!IS_BROWSER || !wrapper) {
|
|
6842
|
+
if (!IS_BROWSER$1 || !wrapper) {
|
|
6820
6843
|
return undefined;
|
|
6821
6844
|
}
|
|
6822
6845
|
const onTransitionEnd = () => {
|
|
@@ -14826,10 +14849,90 @@ Toolbar.displayName = TOOLBAR_NAME;
|
|
|
14826
14849
|
Toolbar.className = CLASSNAME$3;
|
|
14827
14850
|
Toolbar.defaultProps = DEFAULT_PROPS$3;
|
|
14828
14851
|
|
|
14852
|
+
/**
|
|
14853
|
+
* Arrow size (in pixel).
|
|
14854
|
+
*/
|
|
14855
|
+
const ARROW_SIZE = 8;
|
|
14856
|
+
|
|
14829
14857
|
/**
|
|
14830
14858
|
* Make sure tooltip appear above popovers.
|
|
14859
|
+
* Hardcoded as POPOVER_ZINDEX (9999) + 1.
|
|
14860
|
+
*/
|
|
14861
|
+
const TOOLTIP_ZINDEX = 10000;
|
|
14862
|
+
|
|
14863
|
+
/**
|
|
14864
|
+
* Component default props.
|
|
14865
|
+
*/
|
|
14866
|
+
const DEFAULT_PROPS$2 = {
|
|
14867
|
+
placement: 'bottom',
|
|
14868
|
+
closeMode: 'unmount',
|
|
14869
|
+
ariaLinkMode: 'aria-describedby',
|
|
14870
|
+
zIndex: TOOLTIP_ZINDEX
|
|
14871
|
+
};
|
|
14872
|
+
|
|
14873
|
+
/**
|
|
14874
|
+
* Component display name.
|
|
14875
|
+
*/
|
|
14876
|
+
const COMPONENT_NAME$2 = 'Tooltip';
|
|
14877
|
+
|
|
14878
|
+
/**
|
|
14879
|
+
* Component default class name and class prefix.
|
|
14880
|
+
*/
|
|
14881
|
+
const CLASSNAME$2 = 'lumx-tooltip';
|
|
14882
|
+
const {
|
|
14883
|
+
block: block$2,
|
|
14884
|
+
element: element$2
|
|
14885
|
+
} = bem(CLASSNAME$2);
|
|
14886
|
+
|
|
14887
|
+
/**
|
|
14888
|
+
* Props for the TooltipPopup rendering component.
|
|
14831
14889
|
*/
|
|
14832
|
-
|
|
14890
|
+
|
|
14891
|
+
/**
|
|
14892
|
+
* Tooltip popup rendering component.
|
|
14893
|
+
* Pure JSX template for the tooltip popup element (arrow + inner text + BEM classes).
|
|
14894
|
+
*
|
|
14895
|
+
* @param props Component props.
|
|
14896
|
+
* @return JSX element.
|
|
14897
|
+
*/
|
|
14898
|
+
const TooltipPopup = props => {
|
|
14899
|
+
const {
|
|
14900
|
+
id,
|
|
14901
|
+
label,
|
|
14902
|
+
position,
|
|
14903
|
+
isHidden,
|
|
14904
|
+
style,
|
|
14905
|
+
zIndex = TOOLTIP_ZINDEX,
|
|
14906
|
+
className,
|
|
14907
|
+
ref,
|
|
14908
|
+
...forwardedProps
|
|
14909
|
+
} = props;
|
|
14910
|
+
const labelLines = label ? label.split('\n') : [];
|
|
14911
|
+
return /*#__PURE__*/jsxs("div", {
|
|
14912
|
+
ref: ref,
|
|
14913
|
+
...forwardedProps,
|
|
14914
|
+
id: id,
|
|
14915
|
+
role: "tooltip",
|
|
14916
|
+
className: classnames(className, block$2({
|
|
14917
|
+
[`position-${position}`]: Boolean(position)
|
|
14918
|
+
}), isHidden && visuallyHidden()),
|
|
14919
|
+
style: {
|
|
14920
|
+
...(isHidden ? undefined : style),
|
|
14921
|
+
zIndex
|
|
14922
|
+
},
|
|
14923
|
+
"data-popper-placement": position,
|
|
14924
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
14925
|
+
className: element$2('arrow')
|
|
14926
|
+
}), /*#__PURE__*/jsx("div", {
|
|
14927
|
+
className: element$2('inner'),
|
|
14928
|
+
children: labelLines.map((line, index) => /*#__PURE__*/jsx("p", {
|
|
14929
|
+
children: line
|
|
14930
|
+
}, index))
|
|
14931
|
+
})]
|
|
14932
|
+
});
|
|
14933
|
+
};
|
|
14934
|
+
TooltipPopup.displayName = COMPONENT_NAME$2;
|
|
14935
|
+
TooltipPopup.className = CLASSNAME$2;
|
|
14833
14936
|
|
|
14834
14937
|
/**
|
|
14835
14938
|
* Add ref and ARIA attribute(s) in tooltip children or wrapped children.
|
|
@@ -14877,9 +14980,6 @@ const useInjectTooltipRef = options => {
|
|
|
14877
14980
|
}, [label, children, setAnchorElement, linkId, ariaLinkMode]);
|
|
14878
14981
|
};
|
|
14879
14982
|
|
|
14880
|
-
/** Return true if the browser does not support pointer hover */
|
|
14881
|
-
const isHoverNotSupported = () => !!window.matchMedia?.('(hover: none)').matches;
|
|
14882
|
-
|
|
14883
14983
|
/** Check if the focus is visible on the given element */
|
|
14884
14984
|
const isFocusVisible = element => {
|
|
14885
14985
|
try {
|
|
@@ -14890,6 +14990,140 @@ const isFocusVisible = element => {
|
|
|
14890
14990
|
}
|
|
14891
14991
|
};
|
|
14892
14992
|
|
|
14993
|
+
/** Return true if the browser does not support pointer hover */
|
|
14994
|
+
const isHoverNotSupported = () => !!window.matchMedia?.('(hover: none)').matches;
|
|
14995
|
+
|
|
14996
|
+
/**
|
|
14997
|
+
* Framework-agnostic open/close state machine for tooltip.
|
|
14998
|
+
* Manages hover, touch, focus, timers, and escape key behavior.
|
|
14999
|
+
*/
|
|
15000
|
+
function createTooltipOpenManager(options) {
|
|
15001
|
+
const {
|
|
15002
|
+
delay,
|
|
15003
|
+
onStateChange
|
|
15004
|
+
} = options;
|
|
15005
|
+
let timer;
|
|
15006
|
+
let openStartTime;
|
|
15007
|
+
let shouldOpen;
|
|
15008
|
+
let anchorController;
|
|
15009
|
+
let popperController;
|
|
15010
|
+
|
|
15011
|
+
// Run timer to defer updating the isOpen state.
|
|
15012
|
+
const deferUpdate = duration => {
|
|
15013
|
+
if (timer) clearTimeout(timer);
|
|
15014
|
+
const update = () => {
|
|
15015
|
+
onStateChange(!!shouldOpen);
|
|
15016
|
+
};
|
|
15017
|
+
// Skip timeout in fake browsers
|
|
15018
|
+
if (!IS_BROWSER) update();else timer = setTimeout(update, duration);
|
|
15019
|
+
};
|
|
15020
|
+
const hoverNotSupported = isHoverNotSupported();
|
|
15021
|
+
const hasTouch = typeof window !== 'undefined' && 'ontouchstart' in window;
|
|
15022
|
+
|
|
15023
|
+
// Adapt open/close delay
|
|
15024
|
+
const openDelay = delay || (hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.open : TOOLTIP_HOVER_DELAY.open);
|
|
15025
|
+
const closeDelay = hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.close : TOOLTIP_HOVER_DELAY.close;
|
|
15026
|
+
|
|
15027
|
+
// Open (or/and cancel closing) of tooltip.
|
|
15028
|
+
const open = () => {
|
|
15029
|
+
if (shouldOpen && !timer) return;
|
|
15030
|
+
shouldOpen = true;
|
|
15031
|
+
openStartTime = Date.now();
|
|
15032
|
+
deferUpdate(openDelay);
|
|
15033
|
+
};
|
|
15034
|
+
|
|
15035
|
+
// Close or cancel opening of tooltip
|
|
15036
|
+
const getClose = overrideDelay => {
|
|
15037
|
+
if (!shouldOpen && !timer) return;
|
|
15038
|
+
shouldOpen = false;
|
|
15039
|
+
deferUpdate(overrideDelay);
|
|
15040
|
+
};
|
|
15041
|
+
const close = () => getClose(closeDelay);
|
|
15042
|
+
const closeImmediately = () => getClose(0);
|
|
15043
|
+
return {
|
|
15044
|
+
attachAnchor(anchorElement) {
|
|
15045
|
+
anchorController = new AbortController();
|
|
15046
|
+
const {
|
|
15047
|
+
signal
|
|
15048
|
+
} = anchorController;
|
|
15049
|
+
if (hoverNotSupported) {
|
|
15050
|
+
/**
|
|
15051
|
+
* Handle touchend event.
|
|
15052
|
+
* If end comes before the open delay => cancel tooltip (close immediate).
|
|
15053
|
+
* Else if end comes after the open delay => tooltip takes priority, the anchor's default touch end event is prevented.
|
|
15054
|
+
*/
|
|
15055
|
+
const longPressEnd = evt => {
|
|
15056
|
+
if (!openStartTime) return;
|
|
15057
|
+
if (Date.now() - openStartTime >= openDelay) {
|
|
15058
|
+
// Tooltip take priority, event prevented.
|
|
15059
|
+
evt.stopPropagation();
|
|
15060
|
+
evt.preventDefault();
|
|
15061
|
+
anchorElement.focus();
|
|
15062
|
+
// Close with delay.
|
|
15063
|
+
close();
|
|
15064
|
+
} else {
|
|
15065
|
+
// Close immediately.
|
|
15066
|
+
closeImmediately();
|
|
15067
|
+
}
|
|
15068
|
+
};
|
|
15069
|
+
anchorElement.addEventListener(hasTouch ? 'touchstart' : 'mousedown', open, {
|
|
15070
|
+
signal
|
|
15071
|
+
});
|
|
15072
|
+
anchorElement.addEventListener(hasTouch ? 'touchend' : 'mouseup', longPressEnd, {
|
|
15073
|
+
signal
|
|
15074
|
+
});
|
|
15075
|
+
} else {
|
|
15076
|
+
anchorElement.addEventListener('mouseenter', open, {
|
|
15077
|
+
signal
|
|
15078
|
+
});
|
|
15079
|
+
anchorElement.addEventListener('mouseleave', close, {
|
|
15080
|
+
signal
|
|
15081
|
+
});
|
|
15082
|
+
anchorElement.addEventListener('mouseup', closeImmediately, {
|
|
15083
|
+
signal
|
|
15084
|
+
});
|
|
15085
|
+
}
|
|
15086
|
+
|
|
15087
|
+
// Events always applied no matter the browser:
|
|
15088
|
+
// Open on focus (only if focus is visible).
|
|
15089
|
+
anchorElement.addEventListener('focusin', e => {
|
|
15090
|
+
// Skip if focus is not visible
|
|
15091
|
+
if (!isFocusVisible(e.target)) return;
|
|
15092
|
+
open();
|
|
15093
|
+
}, {
|
|
15094
|
+
signal
|
|
15095
|
+
});
|
|
15096
|
+
// Close on lost focus.
|
|
15097
|
+
anchorElement.addEventListener('focusout', closeImmediately, {
|
|
15098
|
+
signal
|
|
15099
|
+
});
|
|
15100
|
+
},
|
|
15101
|
+
attachPopper(popperElement) {
|
|
15102
|
+
popperController?.abort();
|
|
15103
|
+
if (!popperElement || hoverNotSupported) return;
|
|
15104
|
+
popperController = new AbortController();
|
|
15105
|
+
const {
|
|
15106
|
+
signal
|
|
15107
|
+
} = popperController;
|
|
15108
|
+
// Popper element hover
|
|
15109
|
+
popperElement.addEventListener('mouseenter', open, {
|
|
15110
|
+
signal
|
|
15111
|
+
});
|
|
15112
|
+
popperElement.addEventListener('mouseleave', close, {
|
|
15113
|
+
signal
|
|
15114
|
+
});
|
|
15115
|
+
},
|
|
15116
|
+
close() {
|
|
15117
|
+
closeImmediately();
|
|
15118
|
+
},
|
|
15119
|
+
destroy() {
|
|
15120
|
+
if (timer) clearTimeout(timer);
|
|
15121
|
+
anchorController?.abort();
|
|
15122
|
+
popperController?.abort();
|
|
15123
|
+
}
|
|
15124
|
+
};
|
|
15125
|
+
}
|
|
15126
|
+
|
|
14893
15127
|
/**
|
|
14894
15128
|
* Hook controlling tooltip visibility using mouse hover the anchor and delay.
|
|
14895
15129
|
*
|
|
@@ -14900,110 +15134,23 @@ const isFocusVisible = element => {
|
|
|
14900
15134
|
function useTooltipOpen(delay, anchorElement) {
|
|
14901
15135
|
const [isOpen, setIsOpen] = useState(false);
|
|
14902
15136
|
const onPopperMount = useRef(null);
|
|
15137
|
+
const managerRef = useRef(null);
|
|
14903
15138
|
|
|
14904
15139
|
// Global close on escape
|
|
14905
|
-
|
|
14906
|
-
useCallbackOnEscape(isOpen ? closeCallback : undefined);
|
|
15140
|
+
useCallbackOnEscape(isOpen ? () => managerRef.current?.close() : undefined);
|
|
14907
15141
|
useEffect(() => {
|
|
14908
15142
|
if (!anchorElement) {
|
|
14909
15143
|
return undefined;
|
|
14910
15144
|
}
|
|
14911
|
-
|
|
14912
|
-
|
|
14913
|
-
|
|
14914
|
-
|
|
14915
|
-
|
|
14916
|
-
|
|
14917
|
-
|
|
14918
|
-
const update = () => {
|
|
14919
|
-
setIsOpen(!!shouldOpen);
|
|
14920
|
-
};
|
|
14921
|
-
// Skip timeout in fake browsers
|
|
14922
|
-
if (!IS_BROWSER) update();else timer = setTimeout(update, duration);
|
|
14923
|
-
};
|
|
14924
|
-
const hoverNotSupported = isHoverNotSupported();
|
|
14925
|
-
const hasTouch = 'ontouchstart' in window;
|
|
14926
|
-
|
|
14927
|
-
// Adapt open/close delay
|
|
14928
|
-
const openDelay = delay || (hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.open : TOOLTIP_HOVER_DELAY.open);
|
|
14929
|
-
const closeDelay = hoverNotSupported ? TOOLTIP_LONG_PRESS_DELAY.close : TOOLTIP_HOVER_DELAY.close;
|
|
14930
|
-
|
|
14931
|
-
// Open (or/and cancel closing) of tooltip.
|
|
14932
|
-
const open = () => {
|
|
14933
|
-
if (shouldOpen && !timer) return;
|
|
14934
|
-
shouldOpen = true;
|
|
14935
|
-
openStartTime = Date.now();
|
|
14936
|
-
deferUpdate(openDelay);
|
|
14937
|
-
};
|
|
14938
|
-
|
|
14939
|
-
// Close or cancel opening of tooltip
|
|
14940
|
-
const getClose = (overrideDelay = closeDelay) => {
|
|
14941
|
-
if (!shouldOpen && !timer) return;
|
|
14942
|
-
shouldOpen = false;
|
|
14943
|
-
deferUpdate(overrideDelay);
|
|
14944
|
-
};
|
|
14945
|
-
const close = () => getClose(closeDelay);
|
|
14946
|
-
const closeImmediately = () => getClose(0);
|
|
14947
|
-
setCloseCallback(() => closeImmediately);
|
|
14948
|
-
|
|
14949
|
-
// Adapt event to browsers with or without `hover` support.
|
|
14950
|
-
const events = [];
|
|
14951
|
-
if (hoverNotSupported) {
|
|
14952
|
-
/**
|
|
14953
|
-
* Handle touchend event
|
|
14954
|
-
* If end comes before the open delay => cancel tooltip (close immediate).
|
|
14955
|
-
* Else if end comes after the open delay => tooltip takes priority, the anchor's default touch end event is prevented.
|
|
14956
|
-
*/
|
|
14957
|
-
const longPressEnd = evt => {
|
|
14958
|
-
if (!openStartTime) return;
|
|
14959
|
-
if (Date.now() - openStartTime >= openDelay) {
|
|
14960
|
-
// Tooltip take priority, event prevented.
|
|
14961
|
-
evt.stopPropagation();
|
|
14962
|
-
evt.preventDefault();
|
|
14963
|
-
anchorElement.focus();
|
|
14964
|
-
// Close with delay.
|
|
14965
|
-
close();
|
|
14966
|
-
} else {
|
|
14967
|
-
// Close immediately.
|
|
14968
|
-
closeImmediately();
|
|
14969
|
-
}
|
|
14970
|
-
};
|
|
14971
|
-
events.push([anchorElement, hasTouch ? 'touchstart' : 'mousedown', open], [anchorElement, hasTouch ? 'touchend' : 'mouseup', longPressEnd]);
|
|
14972
|
-
} else {
|
|
14973
|
-
events.push([anchorElement, 'mouseenter', open], [anchorElement, 'mouseleave', close], [anchorElement, 'mouseup', closeImmediately]);
|
|
14974
|
-
onPopperMount.current = popperElement => {
|
|
14975
|
-
if (!popperElement) return;
|
|
14976
|
-
// Popper element hover
|
|
14977
|
-
popperElement.addEventListener('mouseenter', open);
|
|
14978
|
-
popperElement.addEventListener('mouseleave', close);
|
|
14979
|
-
// Add to event list to remove on unmount
|
|
14980
|
-
events.push([popperElement, 'mouseenter', open], [popperElement, 'mouseleave', close]);
|
|
14981
|
-
};
|
|
14982
|
-
}
|
|
14983
|
-
|
|
14984
|
-
// Events always applied no matter the browser:.
|
|
14985
|
-
events.push(
|
|
14986
|
-
// Open on focus (only if focus is visible).
|
|
14987
|
-
[anchorElement, 'focusin', e => {
|
|
14988
|
-
// Skip if focus is not visible
|
|
14989
|
-
if (!isFocusVisible(e.target)) return;
|
|
14990
|
-
open();
|
|
14991
|
-
}],
|
|
14992
|
-
// Close on lost focus.
|
|
14993
|
-
[anchorElement, 'focusout', closeImmediately]);
|
|
14994
|
-
|
|
14995
|
-
// Attach events
|
|
14996
|
-
for (const [node, eventType, eventHandler] of events) {
|
|
14997
|
-
node.addEventListener(eventType, eventHandler);
|
|
14998
|
-
}
|
|
15145
|
+
const manager = createTooltipOpenManager({
|
|
15146
|
+
delay,
|
|
15147
|
+
onStateChange: setIsOpen
|
|
15148
|
+
});
|
|
15149
|
+
managerRef.current = manager;
|
|
15150
|
+
onPopperMount.current = el => manager.attachPopper(el);
|
|
15151
|
+
manager.attachAnchor(anchorElement);
|
|
14999
15152
|
return () => {
|
|
15000
|
-
|
|
15001
|
-
if (timer) clearTimeout(timer);
|
|
15002
|
-
|
|
15003
|
-
// Detach events.
|
|
15004
|
-
for (const [node, eventType, eventHandler] of events) {
|
|
15005
|
-
node.removeEventListener(eventType, eventHandler);
|
|
15006
|
-
}
|
|
15153
|
+
manager.destroy();
|
|
15007
15154
|
};
|
|
15008
15155
|
}, [anchorElement, delay]);
|
|
15009
15156
|
return {
|
|
@@ -15013,35 +15160,6 @@ function useTooltipOpen(delay, anchorElement) {
|
|
|
15013
15160
|
}
|
|
15014
15161
|
|
|
15015
15162
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
15016
|
-
/**
|
|
15017
|
-
* Component display name.
|
|
15018
|
-
*/
|
|
15019
|
-
const COMPONENT_NAME$2 = 'Tooltip';
|
|
15020
|
-
|
|
15021
|
-
/**
|
|
15022
|
-
* Component default class name and class prefix.
|
|
15023
|
-
*/
|
|
15024
|
-
const CLASSNAME$2 = 'lumx-tooltip';
|
|
15025
|
-
const {
|
|
15026
|
-
block: block$2,
|
|
15027
|
-
element: element$2
|
|
15028
|
-
} = classNames.bem(CLASSNAME$2);
|
|
15029
|
-
|
|
15030
|
-
/**
|
|
15031
|
-
* Component default props.
|
|
15032
|
-
*/
|
|
15033
|
-
const DEFAULT_PROPS$2 = {
|
|
15034
|
-
placement: Placement.BOTTOM,
|
|
15035
|
-
closeMode: 'unmount',
|
|
15036
|
-
ariaLinkMode: 'aria-describedby',
|
|
15037
|
-
zIndex: TOOLTIP_ZINDEX
|
|
15038
|
-
};
|
|
15039
|
-
|
|
15040
|
-
/**
|
|
15041
|
-
* Arrow size (in pixel).
|
|
15042
|
-
*/
|
|
15043
|
-
const ARROW_SIZE = 8;
|
|
15044
|
-
|
|
15045
15163
|
/**
|
|
15046
15164
|
* Tooltip component.
|
|
15047
15165
|
*
|
|
@@ -15076,12 +15194,16 @@ const Tooltip = forwardRef((props, ref) => {
|
|
|
15076
15194
|
placement: resolvedPlacement
|
|
15077
15195
|
} = useFloating({
|
|
15078
15196
|
placement: placement,
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
|
|
15083
|
-
|
|
15084
|
-
|
|
15197
|
+
// Disable autoUpdate and element refs in non-browser environments (e.g. jsdom) to avoid
|
|
15198
|
+
// flushSync act() warnings from @floating-ui/react-dom (positioning is not meaningful in jsdom anyway).
|
|
15199
|
+
...(IS_BROWSER$1 ? {
|
|
15200
|
+
whileElementsMounted: autoUpdate,
|
|
15201
|
+
elements: {
|
|
15202
|
+
reference: anchorElement,
|
|
15203
|
+
floating: popperElement
|
|
15204
|
+
}
|
|
15205
|
+
} : {}),
|
|
15206
|
+
middleware: [offset(ARROW_SIZE)]
|
|
15085
15207
|
});
|
|
15086
15208
|
const position = resolvedPlacement ?? placement;
|
|
15087
15209
|
const {
|
|
@@ -15099,33 +15221,21 @@ const Tooltip = forwardRef((props, ref) => {
|
|
|
15099
15221
|
label,
|
|
15100
15222
|
ariaLinkMode: ariaLinkMode
|
|
15101
15223
|
});
|
|
15102
|
-
const labelLines = label ? label.split('\n') : [];
|
|
15103
15224
|
const tooltipRef = useMergeRefs(ref, setPopperElement, onPopperMount);
|
|
15104
15225
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
15105
15226
|
children: [/*#__PURE__*/jsx(TooltipContextProvider, {
|
|
15106
15227
|
children: wrappedChildren
|
|
15107
15228
|
}), isMounted && /*#__PURE__*/jsx(Portal, {
|
|
15108
|
-
children:
|
|
15229
|
+
children: TooltipPopup({
|
|
15109
15230
|
ref: tooltipRef,
|
|
15110
15231
|
...forwardedProps,
|
|
15111
|
-
id
|
|
15112
|
-
|
|
15113
|
-
|
|
15114
|
-
|
|
15115
|
-
|
|
15116
|
-
|
|
15117
|
-
|
|
15118
|
-
zIndex
|
|
15119
|
-
},
|
|
15120
|
-
"data-popper-placement": position,
|
|
15121
|
-
children: [/*#__PURE__*/jsx("div", {
|
|
15122
|
-
className: element$2('arrow')
|
|
15123
|
-
}), /*#__PURE__*/jsx("div", {
|
|
15124
|
-
className: element$2('inner'),
|
|
15125
|
-
children: labelLines.map(line => /*#__PURE__*/jsx("p", {
|
|
15126
|
-
children: line
|
|
15127
|
-
}, line))
|
|
15128
|
-
})]
|
|
15232
|
+
id,
|
|
15233
|
+
label: label,
|
|
15234
|
+
position: position,
|
|
15235
|
+
isHidden,
|
|
15236
|
+
style: isHidden ? undefined : floatingStyles,
|
|
15237
|
+
zIndex,
|
|
15238
|
+
className
|
|
15129
15239
|
})
|
|
15130
15240
|
})]
|
|
15131
15241
|
});
|