@seeqdev/qomponents 0.0.108 → 0.0.109
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/dist/Accordion/Accordion.js +8 -8
- package/dist/Accordion/Accordion.stories.js +114 -114
- package/dist/Accordion/Accordion.test.js +54 -54
- package/dist/Accordion/Accordion.types.js +1 -1
- package/dist/Accordion/index.js +1 -1
- package/dist/Alert/Alert.js +31 -31
- package/dist/Alert/Alert.stories.js +44 -44
- package/dist/Alert/Alert.test.js +50 -50
- package/dist/Alert/Alert.types.js +1 -1
- package/dist/Alert/index.js +1 -1
- package/dist/Button/Button.js +91 -91
- package/dist/Button/Button.stories.js +97 -97
- package/dist/Button/Button.test.js +48 -48
- package/dist/Button/Button.types.js +4 -4
- package/dist/Button/index.js +1 -1
- package/dist/ButtonWithDropdown/ButtonWithDropdown.js +66 -66
- package/dist/ButtonWithDropdown/ButtonWithDropdown.stories.js +97 -97
- package/dist/ButtonWithDropdown/ButtonWithDropdown.test.js +84 -84
- package/dist/ButtonWithDropdown/ButtonWithDropdown.types.js +1 -1
- package/dist/ButtonWithDropdown/index.js +1 -1
- package/dist/ButtonWithPopover/ButtonWithPopover.js +50 -50
- package/dist/ButtonWithPopover/ButtonWithPopover.stories.js +74 -74
- package/dist/ButtonWithPopover/ButtonWithPopover.test.js +81 -81
- package/dist/ButtonWithPopover/ButtonWithPopover.types.js +1 -1
- package/dist/ButtonWithPopover/index.js +1 -1
- package/dist/Checkbox/Checkbox.js +25 -25
- package/dist/Checkbox/Checkbox.stories.js +33 -33
- package/dist/Checkbox/Checkbox.test.js +93 -93
- package/dist/Checkbox/Checkbox.types.js +1 -1
- package/dist/Checkbox/index.js +1 -1
- package/dist/Icon/Icon.js +53 -53
- package/dist/Icon/Icon.stories.js +44 -44
- package/dist/Icon/Icon.test.js +54 -54
- package/dist/Icon/Icon.types.js +15 -15
- package/dist/Icon/index.js +1 -1
- package/dist/InputGroup/InputGroup.js +25 -25
- package/dist/InputGroup/InputGroup.stories.js +141 -141
- package/dist/InputGroup/InputGroup.test.js +42 -42
- package/dist/InputGroup/InputGroup.types.js +1 -1
- package/dist/InputGroup/index.js +1 -1
- package/dist/Modal/Modal.js +97 -97
- package/dist/Modal/Modal.stories.js +126 -126
- package/dist/Modal/Modal.test.js +107 -107
- package/dist/Modal/Modal.types.js +1 -1
- package/dist/Modal/index.js +1 -1
- package/dist/SeeqActionDropdown/SeeqActionDropdown.js +47 -47
- package/dist/SeeqActionDropdown/SeeqActionDropdown.stories.js +79 -79
- package/dist/SeeqActionDropdown/SeeqActionDropdown.test.js +72 -72
- package/dist/SeeqActionDropdown/SeeqActionDropdown.types.js +1 -1
- package/dist/SeeqActionDropdown/index.js +1 -1
- package/dist/SeeqActionDropdown/variants.js +22 -22
- package/dist/Select/Select.js +173 -173
- package/dist/Select/Select.stories.js +79 -79
- package/dist/Select/Select.test.js +181 -181
- package/dist/Select/Select.types.js +1 -1
- package/dist/Select/index.js +2 -2
- package/dist/Tabs/Tabs.js +21 -21
- package/dist/Tabs/Tabs.stories.js +90 -90
- package/dist/Tabs/Tabs.test.js +90 -90
- package/dist/Tabs/Tabs.types.js +1 -1
- package/dist/Tabs/index.js +1 -1
- package/dist/TextArea/TextArea.js +24 -24
- package/dist/TextArea/TextArea.stories.js +45 -45
- package/dist/TextArea/TextArea.test.js +67 -67
- package/dist/TextArea/TextArea.types.js +1 -1
- package/dist/TextArea/index.js +1 -1
- package/dist/TextField/TextField.js +78 -78
- package/dist/TextField/TextField.stories.js +69 -69
- package/dist/TextField/TextField.test.js +38 -38
- package/dist/TextField/TextField.types.js +1 -1
- package/dist/TextField/index.js +1 -1
- package/dist/ToolbarButton/ToolbarButton.js +74 -74
- package/dist/ToolbarButton/ToolbarButton.stories.js +93 -93
- package/dist/ToolbarButton/ToolbarButton.test.js +92 -92
- package/dist/ToolbarButton/ToolbarButton.types.js +1 -1
- package/dist/ToolbarButton/index.js +1 -1
- package/dist/Tooltip/QTip.stories.js +44 -44
- package/dist/Tooltip/QTip.types.js +1 -1
- package/dist/Tooltip/QTipPerformance.stories.js +29 -29
- package/dist/Tooltip/Qtip.js +154 -154
- package/dist/Tooltip/Tooltip.js +30 -30
- package/dist/Tooltip/Tooltip.stories.js +31 -31
- package/dist/Tooltip/Tooltip.types.js +2 -2
- package/dist/Tooltip/TooltipPerformance.stories.js +29 -29
- package/dist/Tooltip/index.js +2 -2
- package/dist/Tooltip/qTip.utilities.js +10 -10
- package/dist/index.esm.js +30 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -17
- package/dist/index.js.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/browserId.js +28 -28
- package/dist/utils/svg.js +19 -19
- package/dist/utils/validateStyleDimension.js +13 -13
- package/dist/utils/validateStyleDimension.test.js +19 -19
- package/package.json +1 -1
package/dist/Tooltip/Qtip.js
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import DOMPurify from 'dompurify';
|
|
2
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { arrow, computePosition, offset } from '@floating-ui/dom';
|
|
4
|
-
import { useIntervalWhen } from 'rooks';
|
|
5
|
-
import { DEFAULT_TOOL_TIP_DELAY } from './Tooltip.types';
|
|
6
|
-
const getArrowStyle = (position, x, arrowWidth, tooltipHeight, tooltipWidth) => {
|
|
7
|
-
switch (position) {
|
|
8
|
-
case 'bottom':
|
|
9
|
-
return {
|
|
10
|
-
left: `${x}px`,
|
|
11
|
-
top: `${-arrowWidth}px`,
|
|
12
|
-
};
|
|
13
|
-
case 'left':
|
|
14
|
-
return {
|
|
15
|
-
left: `${tooltipWidth - arrowWidth}px`,
|
|
16
|
-
top: `${tooltipHeight / 2 - arrowWidth}px`,
|
|
17
|
-
};
|
|
18
|
-
case 'right':
|
|
19
|
-
return {
|
|
20
|
-
left: `${-arrowWidth}px`,
|
|
21
|
-
top: `${tooltipHeight / 2 - arrowWidth}px`,
|
|
22
|
-
};
|
|
23
|
-
default: // 'top':
|
|
24
|
-
return {
|
|
25
|
-
left: `${x}px`,
|
|
26
|
-
top: `${tooltipHeight - 10 + arrowWidth}px`,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const HTMLTip = ({ text }) => {
|
|
31
|
-
return React.createElement('div', {
|
|
32
|
-
dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(text) },
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
/** Tooltips can cause SystemTests to be flaky, so we suppress them in Playwright and Protractor */
|
|
36
|
-
const suppressTooltip = () => {
|
|
37
|
-
return window.navigator.userAgent === 'Playwright' || window.navigator.userAgent.includes('Protractor');
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* QTip
|
|
41
|
-
*
|
|
42
|
-
* QTip is a Singleton Tooltip component that guarantees high-performance and reduces component wrappers!
|
|
43
|
-
*
|
|
44
|
-
* QTip is used by all qomponents that support the display of tooltips.
|
|
45
|
-
* If you want to add a Tooltip to your application you can do so by adding the following html data-attributes:
|
|
46
|
-
*
|
|
47
|
-
* 'data-qtip-text': the tooltip text to display; this can also be a string containing valid HTML
|
|
48
|
-
* 'data-qtip-placement': one of TooltipPosition (top, bottom, right, or left)
|
|
49
|
-
* 'data-qtip-is-html': set this to true if you provided a text that contains HTML,
|
|
50
|
-
* 'data-qtip-delay': this can be used to delay the showing of the tooltip. this should be a number representing
|
|
51
|
-
* the # of milliseconds you want to delay the tooltip for. If no delay is provided the DEFAULT_TOOL_TIP_DELAY is
|
|
52
|
-
* applied!
|
|
53
|
-
* 'data-qtip-testid': use this attribute to provide a value for a data-testid of your tooltip; this is useful
|
|
54
|
-
* for tests
|
|
55
|
-
*
|
|
56
|
-
* In order for QTip to be able to display Tooltips you must add the QTip component to your top-most component
|
|
57
|
-
* (often that's App or Application) - simply add:
|
|
58
|
-
*
|
|
59
|
-
* <QTip />
|
|
60
|
-
*
|
|
61
|
-
* and enjoy beautiful & performant tooltips!
|
|
62
|
-
*/
|
|
63
|
-
export const QTip = () => {
|
|
64
|
-
const tooltipRef = useRef(null);
|
|
65
|
-
const tooltipTarget = useRef(null);
|
|
66
|
-
const tooltipArrowRef = useRef(null);
|
|
67
|
-
const [tooltipText, setTooltipText] = useState('');
|
|
68
|
-
const [tooltipTargetOriginalPosition, setTooltipTargetOriginalPosition] = useState(null);
|
|
69
|
-
const [show, setShow] = useState(false);
|
|
70
|
-
const [html, setHtml] = useState(false);
|
|
71
|
-
const [tooltipTestId, setTooltipTestId] = useState('');
|
|
72
|
-
const [overTooltip, setOverTooltip] = useState(false);
|
|
73
|
-
// Check every 300ms if the tooltip target position has changed and hide the tooltip if this happens.
|
|
74
|
-
useIntervalWhen(() => {
|
|
75
|
-
const currentPosition = tooltipTarget?.current?.getBoundingClientRect();
|
|
76
|
-
if (overTooltip) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (tooltipTargetOriginalPosition?.y !== currentPosition?.y ||
|
|
80
|
-
tooltipTargetOriginalPosition?.x !== currentPosition?.x) {
|
|
81
|
-
setShow(false);
|
|
82
|
-
}
|
|
83
|
-
}, 300, show);
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
!suppressTooltip() && document.body.addEventListener('mousemove', onMouseMove);
|
|
86
|
-
return () => {
|
|
87
|
-
!suppressTooltip() && document.removeEventListener('mousemove', onMouseMove);
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
|
-
const ttTimeout = useRef();
|
|
91
|
-
const onMouseMove = (e) => {
|
|
92
|
-
clearTimeout(ttTimeout.current);
|
|
93
|
-
tooltipTarget.current = e.target;
|
|
94
|
-
let dataset = e.target?.dataset;
|
|
95
|
-
let text = dataset?.qtipText;
|
|
96
|
-
// Buttons support React.Nodes as children, the tooltip however is applied to the actual button component.
|
|
97
|
-
// we only check two levels up - alternatively the tooltip can also be provided on the React.Node
|
|
98
|
-
if (!text || text === '') {
|
|
99
|
-
let currentTooltipTarget = e.target?.parentElement;
|
|
100
|
-
dataset = currentTooltipTarget?.dataset;
|
|
101
|
-
text = dataset?.qtipText;
|
|
102
|
-
if (!text || text === '') {
|
|
103
|
-
currentTooltipTarget = e.target?.parentElement?.parentElement || null;
|
|
104
|
-
dataset = currentTooltipTarget?.dataset;
|
|
105
|
-
text = dataset?.qtipText;
|
|
106
|
-
}
|
|
107
|
-
tooltipTarget.current = currentTooltipTarget;
|
|
108
|
-
}
|
|
109
|
-
if (text) {
|
|
110
|
-
const delay = parseInt(dataset?.qtipDelay ?? DEFAULT_TOOL_TIP_DELAY + '');
|
|
111
|
-
ttTimeout.current = setTimeout(() => makeTooltip(text, dataset?.qtipPlacement, dataset?.qtipIsHtml === 'true', dataset?.qtipTestid, delay), delay);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const makeTooltip = (tooltipText, position = 'top', isHtml, dataTestId, delay) => {
|
|
115
|
-
if (tooltipText && tooltipTarget.current) {
|
|
116
|
-
setHtml(isHtml);
|
|
117
|
-
setTooltipText(tooltipText);
|
|
118
|
-
setTooltipTestId(dataTestId);
|
|
119
|
-
setTooltipTargetOriginalPosition(tooltipTarget.current.getBoundingClientRect());
|
|
120
|
-
const positionTooltip = () => {
|
|
121
|
-
if (tooltipRef.current && tooltipTarget.current) {
|
|
122
|
-
computePosition(tooltipTarget.current, tooltipRef.current, {
|
|
123
|
-
placement: position,
|
|
124
|
-
middleware: [offset(10), arrow({ element: tooltipArrowRef.current })],
|
|
125
|
-
}).then(({ x, y, middlewareData }) => {
|
|
126
|
-
Object.assign(tooltipRef.current?.style, {
|
|
127
|
-
left: `${x}px`,
|
|
128
|
-
top: `${y}px`,
|
|
129
|
-
});
|
|
130
|
-
if (middlewareData.arrow) {
|
|
131
|
-
const { x, y } = middlewareData.arrow;
|
|
132
|
-
const arrowWidth = tooltipArrowRef.current?.offsetHeight / 2;
|
|
133
|
-
const tooltipHeight = tooltipRef.current?.offsetHeight;
|
|
134
|
-
const tooltipWidth = tooltipRef.current?.offsetWidth;
|
|
135
|
-
const style = getArrowStyle(position, x || y, arrowWidth, tooltipHeight, tooltipWidth);
|
|
136
|
-
Object.assign(tooltipArrowRef.current.style, style);
|
|
137
|
-
}
|
|
138
|
-
setShow(true);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
delay > 0
|
|
143
|
-
? requestAnimationFrame(() => {
|
|
144
|
-
positionTooltip();
|
|
145
|
-
})
|
|
146
|
-
: positionTooltip();
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
return (React.createElement(React.Fragment, null,
|
|
150
|
-
React.createElement("div", { onMouseEnter: () => setOverTooltip(true), onMouseLeave: () => setOverTooltip(false), "data-testid": tooltipTestId, ref: tooltipRef, className: 'tw-absolute tw-rounded tw-bg-black tw-p-2 tw-text-xs tw-text-white tw-z-[9999] fade-in ' +
|
|
151
|
-
(show ? 'tw-visible' : 'tw-invisible tw-pointer-events-none') },
|
|
152
|
-
html ? React.createElement(HTMLTip, { text: tooltipText }) : tooltipText,
|
|
153
|
-
React.createElement("div", { className: "tw-absolute tw-w-[10px] tw-h-[10px] tw-rotate-45 tw-bg-black", ref: tooltipArrowRef }))));
|
|
154
|
-
};
|
|
1
|
+
import DOMPurify from 'dompurify';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { arrow, computePosition, offset } from '@floating-ui/dom';
|
|
4
|
+
import { useIntervalWhen } from 'rooks';
|
|
5
|
+
import { DEFAULT_TOOL_TIP_DELAY } from './Tooltip.types';
|
|
6
|
+
const getArrowStyle = (position, x, arrowWidth, tooltipHeight, tooltipWidth) => {
|
|
7
|
+
switch (position) {
|
|
8
|
+
case 'bottom':
|
|
9
|
+
return {
|
|
10
|
+
left: `${x}px`,
|
|
11
|
+
top: `${-arrowWidth}px`,
|
|
12
|
+
};
|
|
13
|
+
case 'left':
|
|
14
|
+
return {
|
|
15
|
+
left: `${tooltipWidth - arrowWidth}px`,
|
|
16
|
+
top: `${tooltipHeight / 2 - arrowWidth}px`,
|
|
17
|
+
};
|
|
18
|
+
case 'right':
|
|
19
|
+
return {
|
|
20
|
+
left: `${-arrowWidth}px`,
|
|
21
|
+
top: `${tooltipHeight / 2 - arrowWidth}px`,
|
|
22
|
+
};
|
|
23
|
+
default: // 'top':
|
|
24
|
+
return {
|
|
25
|
+
left: `${x}px`,
|
|
26
|
+
top: `${tooltipHeight - 10 + arrowWidth}px`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const HTMLTip = ({ text }) => {
|
|
31
|
+
return React.createElement('div', {
|
|
32
|
+
dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(text) },
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
/** Tooltips can cause SystemTests to be flaky, so we suppress them in Playwright and Protractor */
|
|
36
|
+
const suppressTooltip = () => {
|
|
37
|
+
return window.navigator.userAgent === 'Playwright' || window.navigator.userAgent.includes('Protractor');
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* QTip
|
|
41
|
+
*
|
|
42
|
+
* QTip is a Singleton Tooltip component that guarantees high-performance and reduces component wrappers!
|
|
43
|
+
*
|
|
44
|
+
* QTip is used by all qomponents that support the display of tooltips.
|
|
45
|
+
* If you want to add a Tooltip to your application you can do so by adding the following html data-attributes:
|
|
46
|
+
*
|
|
47
|
+
* 'data-qtip-text': the tooltip text to display; this can also be a string containing valid HTML
|
|
48
|
+
* 'data-qtip-placement': one of TooltipPosition (top, bottom, right, or left)
|
|
49
|
+
* 'data-qtip-is-html': set this to true if you provided a text that contains HTML,
|
|
50
|
+
* 'data-qtip-delay': this can be used to delay the showing of the tooltip. this should be a number representing
|
|
51
|
+
* the # of milliseconds you want to delay the tooltip for. If no delay is provided the DEFAULT_TOOL_TIP_DELAY is
|
|
52
|
+
* applied!
|
|
53
|
+
* 'data-qtip-testid': use this attribute to provide a value for a data-testid of your tooltip; this is useful
|
|
54
|
+
* for tests
|
|
55
|
+
*
|
|
56
|
+
* In order for QTip to be able to display Tooltips you must add the QTip component to your top-most component
|
|
57
|
+
* (often that's App or Application) - simply add:
|
|
58
|
+
*
|
|
59
|
+
* <QTip />
|
|
60
|
+
*
|
|
61
|
+
* and enjoy beautiful & performant tooltips!
|
|
62
|
+
*/
|
|
63
|
+
export const QTip = () => {
|
|
64
|
+
const tooltipRef = useRef(null);
|
|
65
|
+
const tooltipTarget = useRef(null);
|
|
66
|
+
const tooltipArrowRef = useRef(null);
|
|
67
|
+
const [tooltipText, setTooltipText] = useState('');
|
|
68
|
+
const [tooltipTargetOriginalPosition, setTooltipTargetOriginalPosition] = useState(null);
|
|
69
|
+
const [show, setShow] = useState(false);
|
|
70
|
+
const [html, setHtml] = useState(false);
|
|
71
|
+
const [tooltipTestId, setTooltipTestId] = useState('');
|
|
72
|
+
const [overTooltip, setOverTooltip] = useState(false);
|
|
73
|
+
// Check every 300ms if the tooltip target position has changed and hide the tooltip if this happens.
|
|
74
|
+
useIntervalWhen(() => {
|
|
75
|
+
const currentPosition = tooltipTarget?.current?.getBoundingClientRect();
|
|
76
|
+
if (overTooltip) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (tooltipTargetOriginalPosition?.y !== currentPosition?.y ||
|
|
80
|
+
tooltipTargetOriginalPosition?.x !== currentPosition?.x) {
|
|
81
|
+
setShow(false);
|
|
82
|
+
}
|
|
83
|
+
}, 300, show);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
!suppressTooltip() && document.body.addEventListener('mousemove', onMouseMove);
|
|
86
|
+
return () => {
|
|
87
|
+
!suppressTooltip() && document.removeEventListener('mousemove', onMouseMove);
|
|
88
|
+
};
|
|
89
|
+
}, []);
|
|
90
|
+
const ttTimeout = useRef();
|
|
91
|
+
const onMouseMove = (e) => {
|
|
92
|
+
clearTimeout(ttTimeout.current);
|
|
93
|
+
tooltipTarget.current = e.target;
|
|
94
|
+
let dataset = e.target?.dataset;
|
|
95
|
+
let text = dataset?.qtipText;
|
|
96
|
+
// Buttons support React.Nodes as children, the tooltip however is applied to the actual button component.
|
|
97
|
+
// we only check two levels up - alternatively the tooltip can also be provided on the React.Node
|
|
98
|
+
if (!text || text === '') {
|
|
99
|
+
let currentTooltipTarget = e.target?.parentElement;
|
|
100
|
+
dataset = currentTooltipTarget?.dataset;
|
|
101
|
+
text = dataset?.qtipText;
|
|
102
|
+
if (!text || text === '') {
|
|
103
|
+
currentTooltipTarget = e.target?.parentElement?.parentElement || null;
|
|
104
|
+
dataset = currentTooltipTarget?.dataset;
|
|
105
|
+
text = dataset?.qtipText;
|
|
106
|
+
}
|
|
107
|
+
tooltipTarget.current = currentTooltipTarget;
|
|
108
|
+
}
|
|
109
|
+
if (text) {
|
|
110
|
+
const delay = parseInt(dataset?.qtipDelay ?? DEFAULT_TOOL_TIP_DELAY + '');
|
|
111
|
+
ttTimeout.current = setTimeout(() => makeTooltip(text, dataset?.qtipPlacement, dataset?.qtipIsHtml === 'true', dataset?.qtipTestid, delay), delay);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const makeTooltip = (tooltipText, position = 'top', isHtml, dataTestId, delay) => {
|
|
115
|
+
if (tooltipText && tooltipTarget.current) {
|
|
116
|
+
setHtml(isHtml);
|
|
117
|
+
setTooltipText(tooltipText);
|
|
118
|
+
setTooltipTestId(dataTestId);
|
|
119
|
+
setTooltipTargetOriginalPosition(tooltipTarget.current.getBoundingClientRect());
|
|
120
|
+
const positionTooltip = () => {
|
|
121
|
+
if (tooltipRef.current && tooltipTarget.current) {
|
|
122
|
+
computePosition(tooltipTarget.current, tooltipRef.current, {
|
|
123
|
+
placement: position,
|
|
124
|
+
middleware: [offset(10), arrow({ element: tooltipArrowRef.current })],
|
|
125
|
+
}).then(({ x, y, middlewareData }) => {
|
|
126
|
+
Object.assign(tooltipRef.current?.style, {
|
|
127
|
+
left: `${x}px`,
|
|
128
|
+
top: `${y}px`,
|
|
129
|
+
});
|
|
130
|
+
if (middlewareData.arrow) {
|
|
131
|
+
const { x, y } = middlewareData.arrow;
|
|
132
|
+
const arrowWidth = tooltipArrowRef.current?.offsetHeight / 2;
|
|
133
|
+
const tooltipHeight = tooltipRef.current?.offsetHeight;
|
|
134
|
+
const tooltipWidth = tooltipRef.current?.offsetWidth;
|
|
135
|
+
const style = getArrowStyle(position, x || y, arrowWidth, tooltipHeight, tooltipWidth);
|
|
136
|
+
Object.assign(tooltipArrowRef.current.style, style);
|
|
137
|
+
}
|
|
138
|
+
setShow(true);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
delay > 0
|
|
143
|
+
? requestAnimationFrame(() => {
|
|
144
|
+
positionTooltip();
|
|
145
|
+
})
|
|
146
|
+
: positionTooltip();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return (React.createElement(React.Fragment, null,
|
|
150
|
+
React.createElement("div", { onMouseEnter: () => setOverTooltip(true), onMouseLeave: () => setOverTooltip(false), "data-testid": tooltipTestId, ref: tooltipRef, className: 'tw-absolute tw-rounded tw-bg-black tw-p-2 tw-text-xs tw-text-white tw-z-[9999] fade-in ' +
|
|
151
|
+
(show ? 'tw-visible' : 'tw-invisible tw-pointer-events-none') },
|
|
152
|
+
html ? React.createElement(HTMLTip, { text: tooltipText }) : tooltipText,
|
|
153
|
+
React.createElement("div", { className: "tw-absolute tw-w-[10px] tw-h-[10px] tw-rotate-45 tw-bg-black", ref: tooltipArrowRef }))));
|
|
154
|
+
};
|
|
155
155
|
//# sourceMappingURL=Qtip.js.map
|
package/dist/Tooltip/Tooltip.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '../styles.css';
|
|
3
|
-
import { DEFAULT_TOOL_TIP_DELAY } from './Tooltip.types';
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated
|
|
6
|
-
* Note: Tooltip has been replaced by QTip - a singleton JS tooltip that behaves well even with overflow settings :)
|
|
7
|
-
* See @QTip for more info!
|
|
8
|
-
*
|
|
9
|
-
* This component displays a Tooltip for the provided children. It is a CSS only tooltip that will not display
|
|
10
|
-
* correctly if a parent element has an overflow CSS property assigned. Please use QTip to ensure your tooltips
|
|
11
|
-
* display correctly.
|
|
12
|
-
*/
|
|
13
|
-
export const Tooltip = ({ position = 'bottom', children, text, delay = DEFAULT_TOOL_TIP_DELAY, }) => {
|
|
14
|
-
const arrowBaseClasses = 'before:tw-content-[\'\'] before:tw-absolute before:tw-border-8';
|
|
15
|
-
const centerArrowVertically = 'before:tw-top-1/2 before:-tw-translate-y-1/2';
|
|
16
|
-
const centerArrowHorizontally = 'before:tw-left-1/2 before:-tw-translate-x-1/2';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '../styles.css';
|
|
3
|
+
import { DEFAULT_TOOL_TIP_DELAY } from './Tooltip.types';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated
|
|
6
|
+
* Note: Tooltip has been replaced by QTip - a singleton JS tooltip that behaves well even with overflow settings :)
|
|
7
|
+
* See @QTip for more info!
|
|
8
|
+
*
|
|
9
|
+
* This component displays a Tooltip for the provided children. It is a CSS only tooltip that will not display
|
|
10
|
+
* correctly if a parent element has an overflow CSS property assigned. Please use QTip to ensure your tooltips
|
|
11
|
+
* display correctly.
|
|
12
|
+
*/
|
|
13
|
+
export const Tooltip = ({ position = 'bottom', children, text, delay = DEFAULT_TOOL_TIP_DELAY, }) => {
|
|
14
|
+
const arrowBaseClasses = 'before:tw-content-[\'\'] before:tw-absolute before:tw-border-8';
|
|
15
|
+
const centerArrowVertically = 'before:tw-top-1/2 before:-tw-translate-y-1/2';
|
|
16
|
+
const centerArrowHorizontally = 'before:tw-left-1/2 before:-tw-translate-x-1/2';
|
|
17
17
|
const arrowRight = `${arrowBaseClasses} ${centerArrowVertically} before:tw-right-[100%] before:tw-border-y-transparent
|
|
18
|
-
before:tw-border-l-transparent before:tw-border-r-black`;
|
|
18
|
+
before:tw-border-l-transparent before:tw-border-r-black`;
|
|
19
19
|
const arrowLeft = `${arrowBaseClasses} ${centerArrowVertically} before:tw-left-[100%] before:tw-border-y-transparent
|
|
20
|
-
before:tw-border-l-black before:tw-border-r-transparent`;
|
|
20
|
+
before:tw-border-l-black before:tw-border-r-transparent`;
|
|
21
21
|
const arrowBottom = `${arrowBaseClasses} ${centerArrowHorizontally} before:-tw-top-4 before:tw-border-b-black
|
|
22
|
-
before:tw-border-r-transparent before:tw-border-l-transparent before:tw-border-t-transparent`;
|
|
22
|
+
before:tw-border-r-transparent before:tw-border-l-transparent before:tw-border-t-transparent`;
|
|
23
23
|
const arrowTop = `${arrowBaseClasses} ${centerArrowHorizontally} before:-tw-bottom-4 before:tw-border-b-transparent
|
|
24
|
-
before:tw-border-t-black before:tw-border-l-transparent before:tw-border-r-transparent`;
|
|
25
|
-
const placements = {
|
|
26
|
-
top: `-tw-top-2 -tw-translate-y-full tw-left-1/2 -tw-translate-x-1/2 ${arrowTop}`,
|
|
27
|
-
left: `-tw-translate-x-full -tw-left-3 -tw-translate-y-1/2 tw-top-1/2 ${arrowLeft}`,
|
|
28
|
-
right: `tw-translate-x-full -tw-right-3 -tw-translate-y-1/2 tw-top-1/2 ${arrowRight}`,
|
|
29
|
-
bottom: `-tw-bottom-2 tw-translate-y-full tw-left-1/2 -tw-translate-x-1/2 ${arrowBottom}`,
|
|
30
|
-
};
|
|
31
|
-
return (React.createElement("div", { className: "tw-group tw-relative tw-inline-block" },
|
|
32
|
-
children,
|
|
24
|
+
before:tw-border-t-black before:tw-border-l-transparent before:tw-border-r-transparent`;
|
|
25
|
+
const placements = {
|
|
26
|
+
top: `-tw-top-2 -tw-translate-y-full tw-left-1/2 -tw-translate-x-1/2 ${arrowTop}`,
|
|
27
|
+
left: `-tw-translate-x-full -tw-left-3 -tw-translate-y-1/2 tw-top-1/2 ${arrowLeft}`,
|
|
28
|
+
right: `tw-translate-x-full -tw-right-3 -tw-translate-y-1/2 tw-top-1/2 ${arrowRight}`,
|
|
29
|
+
bottom: `-tw-bottom-2 tw-translate-y-full tw-left-1/2 -tw-translate-x-1/2 ${arrowBottom}`,
|
|
30
|
+
};
|
|
31
|
+
return (React.createElement("div", { className: "tw-group tw-relative tw-inline-block" },
|
|
32
|
+
children,
|
|
33
33
|
React.createElement("div", { className: `tw-z-50 tw-whitespace-nowrap tw-hidden group-hover:tw-inline-block group-hover:tw-delay-[${delay}ms]
|
|
34
|
-
tw-absolute tw-opacity-0 group-hover:tw-opacity-100 tw-rounded tw-bg-black tw-p-2 tw-text-xs tw-text-white ${placements[position]}` }, text)));
|
|
35
|
-
};
|
|
34
|
+
tw-absolute tw-opacity-0 group-hover:tw-opacity-100 tw-rounded tw-bg-black tw-p-2 tw-text-xs tw-text-white ${placements[position]}` }, text)));
|
|
35
|
+
};
|
|
36
36
|
//# sourceMappingURL=Tooltip.js.map
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Tooltip } from './Tooltip';
|
|
3
|
-
import Icon from '../Icon';
|
|
4
|
-
import Button from '../Button';
|
|
5
|
-
import { tooltipPositions } from './Tooltip.types';
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Tooltip',
|
|
8
|
-
};
|
|
9
|
-
export const AllTooltips = () => {
|
|
10
|
-
const renderButtonsWithTooltip = () => tooltipPositions.map((position) => (React.createElement("div", { key: `${position}_button` },
|
|
11
|
-
React.createElement(Tooltip, { text: `Tooltip on the ${position}`, position: position },
|
|
12
|
-
React.createElement(Button, { label: position })))));
|
|
13
|
-
const renderIconsWithHtmlTooltip = () => tooltipPositions.map((position) => (React.createElement("div", { key: `${position}_icon` },
|
|
14
|
-
React.createElement(Tooltip, { text: React.createElement("div", null,
|
|
15
|
-
React.createElement("h2", null, "Fancy Tooltip"),
|
|
16
|
-
" This is a special tooltip. Why?",
|
|
17
|
-
React.createElement("br", null),
|
|
18
|
-
"Because it supports ",
|
|
19
|
-
React.createElement("b", null, "HTML!")), position: position },
|
|
20
|
-
React.createElement(Icon, { icon: "fc-sun" })))));
|
|
21
|
-
const renderTextTooltipOnText = () => tooltipPositions.map((position) => (React.createElement("div", { key: `${position}_text` },
|
|
22
|
-
React.createElement(Tooltip, { text: "Helpful information provided here", position: position },
|
|
23
|
-
React.createElement("span", null,
|
|
24
|
-
"Hover for Tooltip (on the ",
|
|
25
|
-
position,
|
|
26
|
-
")")))));
|
|
27
|
-
return (React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4 tw-text-center" },
|
|
28
|
-
renderButtonsWithTooltip(),
|
|
29
|
-
renderIconsWithHtmlTooltip(),
|
|
30
|
-
renderTextTooltipOnText()));
|
|
31
|
-
};
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Tooltip } from './Tooltip';
|
|
3
|
+
import Icon from '../Icon';
|
|
4
|
+
import Button from '../Button';
|
|
5
|
+
import { tooltipPositions } from './Tooltip.types';
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Tooltip',
|
|
8
|
+
};
|
|
9
|
+
export const AllTooltips = () => {
|
|
10
|
+
const renderButtonsWithTooltip = () => tooltipPositions.map((position) => (React.createElement("div", { key: `${position}_button` },
|
|
11
|
+
React.createElement(Tooltip, { text: `Tooltip on the ${position}`, position: position },
|
|
12
|
+
React.createElement(Button, { label: position })))));
|
|
13
|
+
const renderIconsWithHtmlTooltip = () => tooltipPositions.map((position) => (React.createElement("div", { key: `${position}_icon` },
|
|
14
|
+
React.createElement(Tooltip, { text: React.createElement("div", null,
|
|
15
|
+
React.createElement("h2", null, "Fancy Tooltip"),
|
|
16
|
+
" This is a special tooltip. Why?",
|
|
17
|
+
React.createElement("br", null),
|
|
18
|
+
"Because it supports ",
|
|
19
|
+
React.createElement("b", null, "HTML!")), position: position },
|
|
20
|
+
React.createElement(Icon, { icon: "fc-sun" })))));
|
|
21
|
+
const renderTextTooltipOnText = () => tooltipPositions.map((position) => (React.createElement("div", { key: `${position}_text` },
|
|
22
|
+
React.createElement(Tooltip, { text: "Helpful information provided here", position: position },
|
|
23
|
+
React.createElement("span", null,
|
|
24
|
+
"Hover for Tooltip (on the ",
|
|
25
|
+
position,
|
|
26
|
+
")")))));
|
|
27
|
+
return (React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4 tw-text-center" },
|
|
28
|
+
renderButtonsWithTooltip(),
|
|
29
|
+
renderIconsWithHtmlTooltip(),
|
|
30
|
+
renderTextTooltipOnText()));
|
|
31
|
+
};
|
|
32
32
|
//# sourceMappingURL=Tooltip.stories.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const DEFAULT_TOOL_TIP_DELAY = 500;
|
|
2
|
-
export const tooltipPositions = ['top', 'left', 'right', 'bottom'];
|
|
1
|
+
export const DEFAULT_TOOL_TIP_DELAY = 500;
|
|
2
|
+
export const tooltipPositions = ['top', 'left', 'right', 'bottom'];
|
|
3
3
|
//# sourceMappingURL=Tooltip.types.js.map
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Tooltip } from './Tooltip';
|
|
3
|
-
import Icon from '../Icon';
|
|
4
|
-
export default {
|
|
5
|
-
title: 'Tooltip',
|
|
6
|
-
};
|
|
7
|
-
const renderManyTooltips = () => {
|
|
8
|
-
const colsCount = 100;
|
|
9
|
-
const rowCount = 100;
|
|
10
|
-
const rows = [];
|
|
11
|
-
const getCols = (rowId) => {
|
|
12
|
-
const cols = [];
|
|
13
|
-
for (let i = 0; i < colsCount; i++) {
|
|
14
|
-
cols.push(React.createElement("td", { key: 'col_' + i + '_row_' + rowId },
|
|
15
|
-
React.createElement(Tooltip, { text: `hello there ${i}` },
|
|
16
|
-
React.createElement(Icon, { icon: "fc-sun" }))));
|
|
17
|
-
}
|
|
18
|
-
return cols;
|
|
19
|
-
};
|
|
20
|
-
for (let i = 0; i < rowCount; i++) {
|
|
21
|
-
rows.push(React.createElement("tr", { key: 'row_' + i }, ...getCols(i)));
|
|
22
|
-
}
|
|
23
|
-
return (React.createElement("table", null,
|
|
24
|
-
React.createElement("tbody", null, rows.map((row) => row))));
|
|
25
|
-
};
|
|
26
|
-
export const TooltipPerformance = () => {
|
|
27
|
-
return (React.createElement(React.Fragment, null,
|
|
28
|
-
React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4 tw-text-center" }, renderManyTooltips())));
|
|
29
|
-
};
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Tooltip } from './Tooltip';
|
|
3
|
+
import Icon from '../Icon';
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Tooltip',
|
|
6
|
+
};
|
|
7
|
+
const renderManyTooltips = () => {
|
|
8
|
+
const colsCount = 100;
|
|
9
|
+
const rowCount = 100;
|
|
10
|
+
const rows = [];
|
|
11
|
+
const getCols = (rowId) => {
|
|
12
|
+
const cols = [];
|
|
13
|
+
for (let i = 0; i < colsCount; i++) {
|
|
14
|
+
cols.push(React.createElement("td", { key: 'col_' + i + '_row_' + rowId },
|
|
15
|
+
React.createElement(Tooltip, { text: `hello there ${i}` },
|
|
16
|
+
React.createElement(Icon, { icon: "fc-sun" }))));
|
|
17
|
+
}
|
|
18
|
+
return cols;
|
|
19
|
+
};
|
|
20
|
+
for (let i = 0; i < rowCount; i++) {
|
|
21
|
+
rows.push(React.createElement("tr", { key: 'row_' + i }, ...getCols(i)));
|
|
22
|
+
}
|
|
23
|
+
return (React.createElement("table", null,
|
|
24
|
+
React.createElement("tbody", null, rows.map((row) => row))));
|
|
25
|
+
};
|
|
26
|
+
export const TooltipPerformance = () => {
|
|
27
|
+
return (React.createElement(React.Fragment, null,
|
|
28
|
+
React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4 tw-text-center" }, renderManyTooltips())));
|
|
29
|
+
};
|
|
30
30
|
//# sourceMappingURL=TooltipPerformance.stories.js.map
|
package/dist/Tooltip/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Tooltip } from './Tooltip';
|
|
2
|
-
export { QTip } from './Qtip';
|
|
1
|
+
export { Tooltip } from './Tooltip';
|
|
2
|
+
export { QTip } from './Qtip';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { DEFAULT_TOOL_TIP_DELAY } from './Tooltip.types';
|
|
2
|
-
export const getQTipData = ({ tooltip, tooltipPlacement, isHtmlTooltip, tooltipTestId, tooltipDelay = DEFAULT_TOOL_TIP_DELAY, }) => tooltip
|
|
3
|
-
? {
|
|
4
|
-
'data-qtip-text': tooltip,
|
|
5
|
-
'data-qtip-placement': tooltipPlacement,
|
|
6
|
-
'data-qtip-is-html': isHtmlTooltip,
|
|
7
|
-
'data-qtip-testid': tooltipTestId,
|
|
8
|
-
'data-qtip-delay': tooltipDelay,
|
|
9
|
-
}
|
|
10
|
-
: undefined;
|
|
1
|
+
import { DEFAULT_TOOL_TIP_DELAY } from './Tooltip.types';
|
|
2
|
+
export const getQTipData = ({ tooltip, tooltipPlacement, isHtmlTooltip, tooltipTestId, tooltipDelay = DEFAULT_TOOL_TIP_DELAY, }) => tooltip
|
|
3
|
+
? {
|
|
4
|
+
'data-qtip-text': tooltip,
|
|
5
|
+
'data-qtip-placement': tooltipPlacement,
|
|
6
|
+
'data-qtip-is-html': isHtmlTooltip,
|
|
7
|
+
'data-qtip-testid': tooltipTestId,
|
|
8
|
+
'data-qtip-delay': tooltipDelay,
|
|
9
|
+
}
|
|
10
|
+
: undefined;
|
|
11
11
|
//# sourceMappingURL=qTip.utilities.js.map
|
package/dist/index.esm.js
CHANGED
|
@@ -6584,27 +6584,40 @@ const QTip = () => {
|
|
|
6584
6584
|
};
|
|
6585
6585
|
}, []);
|
|
6586
6586
|
const ttTimeout = useRef();
|
|
6587
|
+
const findTooltipData = (element) => {
|
|
6588
|
+
// Traverse up to 8 levels to find the tooltip data
|
|
6589
|
+
for (let i = 0; i < 8 && element; i++) {
|
|
6590
|
+
if (!element) {
|
|
6591
|
+
return null;
|
|
6592
|
+
}
|
|
6593
|
+
if (element?.dataset?.qtipText) {
|
|
6594
|
+
return element.dataset;
|
|
6595
|
+
}
|
|
6596
|
+
element = element?.parentElement;
|
|
6597
|
+
}
|
|
6598
|
+
return null;
|
|
6599
|
+
};
|
|
6587
6600
|
const onMouseMove = (e) => {
|
|
6588
6601
|
clearTimeout(ttTimeout.current);
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
dataset = currentTooltipTarget?.dataset;
|
|
6597
|
-
text = dataset?.qtipText;
|
|
6598
|
-
if (!text || text === '') {
|
|
6599
|
-
currentTooltipTarget = e.target?.parentElement?.parentElement || null;
|
|
6600
|
-
dataset = currentTooltipTarget?.dataset;
|
|
6601
|
-
text = dataset?.qtipText;
|
|
6602
|
-
}
|
|
6603
|
-
tooltipTarget.current = currentTooltipTarget;
|
|
6602
|
+
// Find tooltip data on the current or parent elements
|
|
6603
|
+
const target = e.target;
|
|
6604
|
+
const dataset = findTooltipData(target);
|
|
6605
|
+
if (!dataset) {
|
|
6606
|
+
// No tooltip data found
|
|
6607
|
+
tooltipTarget.current = null;
|
|
6608
|
+
return;
|
|
6604
6609
|
}
|
|
6610
|
+
tooltipTarget.current = target;
|
|
6611
|
+
const text = dataset.qtipText;
|
|
6605
6612
|
if (text) {
|
|
6606
|
-
const delay = parseInt(dataset
|
|
6607
|
-
|
|
6613
|
+
const delay = parseInt(dataset.qtipDelay || `${DEFAULT_TOOL_TIP_DELAY}`, 10);
|
|
6614
|
+
const placement = dataset.qtipPlacement || 'top';
|
|
6615
|
+
const isHtml = dataset.qtipIsHtml === 'true';
|
|
6616
|
+
const testId = dataset.qtipTestid;
|
|
6617
|
+
// Debounced tooltip display
|
|
6618
|
+
ttTimeout.current = setTimeout(() => {
|
|
6619
|
+
makeTooltip(text, placement, isHtml, testId, delay);
|
|
6620
|
+
}, delay);
|
|
6608
6621
|
}
|
|
6609
6622
|
};
|
|
6610
6623
|
const makeTooltip = (tooltipText, position = 'top', isHtml, dataTestId, delay) => {
|