@seeqdev/qomponents 0.0.184 → 0.0.185
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/src/Accordion/Accordion.d.ts +4 -0
- package/dist/src/Accordion/Accordion.js +8 -0
- package/dist/src/Accordion/Accordion.stories.d.ts +5 -0
- package/dist/src/Accordion/Accordion.stories.js +96 -0
- package/dist/src/Accordion/Accordion.test.d.ts +1 -0
- package/dist/src/Accordion/Accordion.test.js +54 -0
- package/dist/src/Accordion/Accordion.types.d.ts +86 -0
- package/dist/src/Accordion/Accordion.types.js +1 -0
- package/dist/src/Accordion/index.d.ts +1 -0
- package/dist/src/Accordion/index.js +1 -0
- package/dist/src/Alert/Alert.d.ts +7 -0
- package/dist/src/Alert/Alert.js +33 -0
- package/dist/src/Alert/Alert.stories.d.ts +14 -0
- package/dist/src/Alert/Alert.stories.js +72 -0
- package/dist/src/Alert/Alert.test.d.ts +1 -0
- package/dist/src/Alert/Alert.test.js +49 -0
- package/dist/src/Alert/Alert.types.d.ts +62 -0
- package/dist/src/Alert/Alert.types.js +1 -0
- package/dist/src/Alert/index.d.ts +1 -0
- package/dist/src/Alert/index.js +1 -0
- package/dist/src/Button/Button.d.ts +10 -0
- package/dist/src/Button/Button.js +107 -0
- package/dist/src/Button/Button.stories.d.ts +9 -0
- package/dist/src/Button/Button.stories.js +74 -0
- package/dist/src/Button/Button.test.d.ts +1 -0
- package/dist/src/Button/Button.test.js +65 -0
- package/dist/src/Button/Button.types.d.ts +148 -0
- package/dist/src/Button/Button.types.js +4 -0
- package/dist/src/Button/index.d.ts +1 -0
- package/dist/src/Button/index.js +1 -0
- package/dist/src/ButtonGroup/ButtonGroup.d.ts +7 -0
- package/dist/src/ButtonGroup/ButtonGroup.js +34 -0
- package/dist/src/ButtonGroup/ButtonGroup.stories.d.ts +5 -0
- package/dist/src/ButtonGroup/ButtonGroup.stories.js +328 -0
- package/dist/src/ButtonGroup/ButtonGroup.test.d.ts +1 -0
- package/dist/src/ButtonGroup/ButtonGroup.test.js +65 -0
- package/dist/src/ButtonGroup/ButtonGroup.types.d.ts +80 -0
- package/dist/src/ButtonGroup/ButtonGroup.types.js +1 -0
- package/dist/src/ButtonGroup/index.d.ts +1 -0
- package/dist/src/ButtonGroup/index.js +1 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.d.ts +4 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.js +46 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.stories.d.ts +5 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.stories.js +119 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.test.d.ts +1 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.test.js +92 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.types.d.ts +232 -0
- package/dist/src/ButtonWithDropdown/ButtonWithDropdown.types.js +1 -0
- package/dist/src/ButtonWithDropdown/index.d.ts +1 -0
- package/dist/src/ButtonWithDropdown/index.js +1 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.d.ts +4 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.js +54 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.stories.d.ts +5 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.stories.js +51 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.test.d.ts +1 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.test.js +80 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.types.d.ts +134 -0
- package/dist/src/ButtonWithPopover/ButtonWithPopover.types.js +1 -0
- package/dist/src/ButtonWithPopover/index.d.ts +1 -0
- package/dist/src/ButtonWithPopover/index.js +1 -0
- package/dist/src/Carousel/Carousel.d.ts +9 -0
- package/dist/src/Carousel/Carousel.js +80 -0
- package/dist/src/Carousel/Carousel.stories.d.ts +5 -0
- package/dist/src/Carousel/Carousel.stories.js +100 -0
- package/dist/src/Carousel/Carousel.test.d.ts +1 -0
- package/dist/src/Carousel/Carousel.test.js +47 -0
- package/dist/src/Carousel/Carousel.types.d.ts +85 -0
- package/dist/src/Carousel/Carousel.types.js +1 -0
- package/dist/src/Carousel/index.d.ts +1 -0
- package/dist/src/Carousel/index.js +1 -0
- package/dist/src/Checkbox/Checkbox.d.ts +7 -0
- package/dist/src/Checkbox/Checkbox.js +24 -0
- package/dist/src/Checkbox/Checkbox.stories.d.ts +5 -0
- package/dist/src/Checkbox/Checkbox.stories.js +21 -0
- package/dist/src/Checkbox/Checkbox.test.d.ts +1 -0
- package/dist/src/Checkbox/Checkbox.test.js +93 -0
- package/dist/src/Checkbox/Checkbox.types.d.ts +91 -0
- package/dist/src/Checkbox/Checkbox.types.js +1 -0
- package/dist/src/Checkbox/index.d.ts +1 -0
- package/dist/src/Checkbox/index.js +1 -0
- package/dist/src/Collapse/Collapse.d.ts +4 -0
- package/dist/src/Collapse/Collapse.js +16 -0
- package/dist/src/Collapse/Collapse.stories.d.ts +5 -0
- package/dist/src/Collapse/Collapse.stories.js +28 -0
- package/dist/src/Collapse/Collapse.test.d.ts +1 -0
- package/dist/src/Collapse/Collapse.test.js +16 -0
- package/dist/src/Collapse/Collapse.types.d.ts +18 -0
- package/dist/src/Collapse/Collapse.types.js +1 -0
- package/dist/src/Collapse/index.d.ts +1 -0
- package/dist/src/Collapse/index.js +1 -0
- package/dist/src/Icon/Icon.d.ts +10 -0
- package/dist/src/Icon/Icon.js +55 -0
- package/dist/src/Icon/Icon.stories.d.ts +5 -0
- package/dist/src/Icon/Icon.stories.js +31 -0
- package/dist/src/Icon/Icon.test.d.ts +1 -0
- package/dist/src/Icon/Icon.test.js +54 -0
- package/dist/src/Icon/Icon.types.d.ts +90 -0
- package/dist/src/Icon/Icon.types.js +15 -0
- package/dist/src/Icon/index.d.ts +1 -0
- package/dist/src/Icon/index.js +1 -0
- package/dist/src/InputGroup/InputGroup.d.ts +7 -0
- package/dist/src/InputGroup/InputGroup.js +33 -0
- package/dist/src/InputGroup/InputGroup.stories.d.ts +5 -0
- package/dist/src/InputGroup/InputGroup.stories.js +144 -0
- package/dist/src/InputGroup/InputGroup.test.d.ts +1 -0
- package/dist/src/InputGroup/InputGroup.test.js +41 -0
- package/dist/src/InputGroup/InputGroup.types.d.ts +61 -0
- package/dist/src/InputGroup/InputGroup.types.js +1 -0
- package/dist/src/InputGroup/index.d.ts +2 -0
- package/dist/src/InputGroup/index.js +1 -0
- package/dist/src/Modal/Modal.d.ts +5 -0
- package/dist/src/Modal/Modal.js +86 -0
- package/dist/src/Modal/Modal.stories.d.ts +10 -0
- package/dist/src/Modal/Modal.stories.js +79 -0
- package/dist/src/Modal/Modal.test.d.ts +1 -0
- package/dist/src/Modal/Modal.test.js +107 -0
- package/dist/src/Modal/Modal.types.d.ts +244 -0
- package/dist/src/Modal/Modal.types.js +1 -0
- package/dist/src/Modal/index.d.ts +1 -0
- package/dist/src/Modal/index.js +1 -0
- package/dist/src/ProgressBar/ProgressBar.d.ts +4 -0
- package/dist/src/ProgressBar/ProgressBar.js +71 -0
- package/dist/src/ProgressBar/ProgressBar.stories.d.ts +5 -0
- package/dist/src/ProgressBar/ProgressBar.stories.js +46 -0
- package/dist/src/ProgressBar/ProgressBar.test.d.ts +1 -0
- package/dist/src/ProgressBar/ProgressBar.test.js +42 -0
- package/dist/src/ProgressBar/ProgressBar.types.d.ts +77 -0
- package/dist/src/ProgressBar/ProgressBar.types.js +1 -0
- package/dist/src/ProgressBar/index.d.ts +1 -0
- package/dist/src/ProgressBar/index.js +1 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.d.ts +4 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.js +41 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.stories.d.ts +5 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.stories.js +73 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.test.d.ts +1 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.test.js +72 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.types.d.ts +159 -0
- package/dist/src/SeeqActionDropdown/SeeqActionDropdown.types.js +1 -0
- package/dist/src/SeeqActionDropdown/index.d.ts +1 -0
- package/dist/src/SeeqActionDropdown/index.js +1 -0
- package/dist/src/SeeqActionDropdown/variants.d.ts +5 -0
- package/dist/src/SeeqActionDropdown/variants.js +34 -0
- package/dist/src/Select/Select.d.ts +15 -0
- package/dist/src/Select/Select.js +171 -0
- package/dist/src/Select/Select.stories.d.ts +5 -0
- package/dist/src/Select/Select.stories.js +50 -0
- package/dist/src/Select/Select.test.d.ts +1 -0
- package/dist/src/Select/Select.test.js +176 -0
- package/dist/src/Select/Select.types.d.ts +220 -0
- package/dist/src/Select/Select.types.js +1 -0
- package/dist/src/Select/index.d.ts +2 -0
- package/dist/src/Select/index.js +2 -0
- package/dist/src/Slider/Slider.d.ts +6 -0
- package/dist/src/Slider/Slider.js +11 -0
- package/dist/src/Slider/Slider.stories.d.ts +5 -0
- package/dist/src/Slider/Slider.stories.js +37 -0
- package/dist/src/Slider/Slider.test.d.ts +1 -0
- package/dist/src/Slider/Slider.test.js +31 -0
- package/dist/src/Slider/Slider.types.d.ts +84 -0
- package/dist/src/Slider/Slider.types.js +1 -0
- package/dist/src/Slider/index.d.ts +1 -0
- package/dist/src/Slider/index.js +1 -0
- package/dist/src/SvgIcon/SvgIcon.d.ts +20 -0
- package/dist/src/SvgIcon/SvgIcon.js +27 -0
- package/dist/src/SvgIcon/SvgIcon.stories.d.ts +5 -0
- package/dist/src/SvgIcon/SvgIcon.stories.js +26 -0
- package/dist/src/SvgIcon/SvgIcon.test.d.ts +1 -0
- package/dist/src/SvgIcon/SvgIcon.test.js +40 -0
- package/dist/src/SvgIcon/SvgIcon.types.d.ts +75 -0
- package/dist/src/SvgIcon/SvgIcon.types.js +2 -0
- package/dist/src/SvgIcon/index.d.ts +1 -0
- package/dist/src/SvgIcon/index.js +1 -0
- package/dist/src/Tabs/Tabs.d.ts +4 -0
- package/dist/src/Tabs/Tabs.js +18 -0
- package/dist/src/Tabs/Tabs.stories.d.ts +5 -0
- package/dist/src/Tabs/Tabs.stories.js +83 -0
- package/dist/src/Tabs/Tabs.test.d.ts +1 -0
- package/dist/src/Tabs/Tabs.test.js +91 -0
- package/dist/src/Tabs/Tabs.types.d.ts +100 -0
- package/dist/src/Tabs/Tabs.types.js +1 -0
- package/dist/src/Tabs/index.d.ts +1 -0
- package/dist/src/Tabs/index.js +1 -0
- package/dist/src/TextArea/TextArea.d.ts +7 -0
- package/dist/src/TextArea/TextArea.js +54 -0
- package/dist/src/TextArea/TextArea.stories.d.ts +5 -0
- package/dist/src/TextArea/TextArea.stories.js +21 -0
- package/dist/src/TextArea/TextArea.test.d.ts +1 -0
- package/dist/src/TextArea/TextArea.test.js +129 -0
- package/dist/src/TextArea/TextArea.types.d.ts +115 -0
- package/dist/src/TextArea/TextArea.types.js +1 -0
- package/dist/src/TextArea/index.d.ts +1 -0
- package/dist/src/TextArea/index.js +1 -0
- package/dist/src/TextField/TextField.d.ts +7 -0
- package/dist/src/TextField/TextField.js +85 -0
- package/dist/src/TextField/TextField.stories.d.ts +5 -0
- package/dist/src/TextField/TextField.stories.js +30 -0
- package/dist/src/TextField/TextField.test.d.ts +1 -0
- package/dist/src/TextField/TextField.test.js +40 -0
- package/dist/src/TextField/TextField.types.d.ts +198 -0
- package/dist/src/TextField/TextField.types.js +1 -0
- package/dist/src/TextField/index.d.ts +1 -0
- package/dist/src/TextField/index.js +1 -0
- package/dist/src/ToolbarButton/ToolbarButton.d.ts +3 -0
- package/dist/src/ToolbarButton/ToolbarButton.js +58 -0
- package/dist/src/ToolbarButton/ToolbarButton.stories.d.ts +5 -0
- package/dist/src/ToolbarButton/ToolbarButton.stories.js +63 -0
- package/dist/src/ToolbarButton/ToolbarButton.test.d.ts +1 -0
- package/dist/src/ToolbarButton/ToolbarButton.test.js +89 -0
- package/dist/src/ToolbarButton/ToolbarButton.types.d.ts +122 -0
- package/dist/src/ToolbarButton/ToolbarButton.types.js +1 -0
- package/dist/src/ToolbarButton/index.d.ts +1 -0
- package/dist/src/ToolbarButton/index.js +1 -0
- package/dist/src/Tooltip/QTip.stories.d.ts +5 -0
- package/dist/src/Tooltip/QTip.stories.js +22 -0
- package/dist/src/Tooltip/QTip.types.d.ts +13 -0
- package/dist/src/Tooltip/QTip.types.js +1 -0
- package/dist/src/Tooltip/QTipPerformance.stories.d.ts +5 -0
- package/dist/src/Tooltip/QTipPerformance.stories.js +27 -0
- package/dist/src/Tooltip/Qtip.d.ts +26 -0
- package/dist/src/Tooltip/Qtip.js +168 -0
- package/dist/src/Tooltip/Tooltip.d.ts +13 -0
- package/dist/src/Tooltip/Tooltip.js +34 -0
- package/dist/src/Tooltip/Tooltip.stories.d.ts +5 -0
- package/dist/src/Tooltip/Tooltip.stories.js +20 -0
- package/dist/src/Tooltip/Tooltip.types.d.ts +22 -0
- package/dist/src/Tooltip/Tooltip.types.js +2 -0
- package/dist/src/Tooltip/TooltipPerformance.stories.d.ts +5 -0
- package/dist/src/Tooltip/TooltipPerformance.stories.js +25 -0
- package/dist/src/Tooltip/index.d.ts +2 -0
- package/dist/src/Tooltip/index.js +2 -0
- package/dist/src/Tooltip/qTip.utilities.d.ts +3 -0
- package/dist/src/Tooltip/qTip.utilities.js +10 -0
- package/dist/src/index.d.ts +46 -0
- package/dist/src/index.js +47 -0
- package/dist/src/setupTests.d.ts +1 -0
- package/dist/src/setupTests.js +5 -0
- package/dist/src/types.d.ts +27 -0
- package/dist/src/types.js +25 -0
- package/dist/src/utils/browserId.d.ts +9 -0
- package/dist/src/utils/browserId.js +28 -0
- package/dist/src/utils/svg.d.ts +15 -0
- package/dist/src/utils/svg.js +19 -0
- package/dist/src/utils/validateStyleDimension.d.ts +2 -0
- package/dist/src/utils/validateStyleDimension.js +13 -0
- package/dist/src/utils/validateStyleDimension.test.d.ts +1 -0
- package/dist/src/utils/validateStyleDimension.test.js +19 -0
- package/package.json +11 -5
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import DOMPurify from 'dompurify';
|
|
3
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { arrow, computePosition, offset, flip, shift } from '@floating-ui/dom';
|
|
5
|
+
import { useIntervalWhen } from 'rooks';
|
|
6
|
+
import { DEFAULT_TOOL_TIP_DELAY } from './Tooltip.types';
|
|
7
|
+
const getArrowStyle = (position, x, arrowWidth, tooltipHeight, tooltipWidth) => {
|
|
8
|
+
switch (position) {
|
|
9
|
+
case 'bottom':
|
|
10
|
+
return {
|
|
11
|
+
left: `${x}px`,
|
|
12
|
+
top: `${-arrowWidth}px`,
|
|
13
|
+
};
|
|
14
|
+
case 'left':
|
|
15
|
+
return {
|
|
16
|
+
left: `${tooltipWidth - arrowWidth}px`,
|
|
17
|
+
top: `${tooltipHeight / 2 - arrowWidth}px`,
|
|
18
|
+
};
|
|
19
|
+
case 'right':
|
|
20
|
+
return {
|
|
21
|
+
left: `${-arrowWidth}px`,
|
|
22
|
+
top: `${tooltipHeight / 2 - arrowWidth}px`,
|
|
23
|
+
};
|
|
24
|
+
default: // 'top':
|
|
25
|
+
return {
|
|
26
|
+
left: `${x}px`,
|
|
27
|
+
top: `${tooltipHeight - 10 + arrowWidth}px`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const HTMLTip = ({ text }) => {
|
|
32
|
+
return React.createElement('div', {
|
|
33
|
+
dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(text) },
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
/** Tooltips can cause SystemTests to be flaky, so we suppress them in Playwright and Protractor */
|
|
37
|
+
const suppressTooltip = () => {
|
|
38
|
+
return window.navigator.userAgent === 'Playwright' || window.navigator.userAgent.includes('Protractor');
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* QTip
|
|
42
|
+
*
|
|
43
|
+
* QTip is a Singleton Tooltip component that guarantees high-performance and reduces component wrappers!
|
|
44
|
+
*
|
|
45
|
+
* QTip is used by all qomponents that support the display of tooltips.
|
|
46
|
+
* If you want to add a Tooltip to your application you can do so by adding the following html data-attributes:
|
|
47
|
+
*
|
|
48
|
+
* 'data-qtip-text': the tooltip text to display; this can also be a string containing valid HTML
|
|
49
|
+
* 'data-qtip-placement': one of TooltipPosition (top, bottom, right, or left)
|
|
50
|
+
* 'data-qtip-is-html': set this to true if you provided a text that contains HTML,
|
|
51
|
+
* 'data-qtip-delay': this can be used to delay the showing of the tooltip. this should be a number representing
|
|
52
|
+
* the # of milliseconds you want to delay the tooltip for. If no delay is provided the DEFAULT_TOOL_TIP_DELAY is
|
|
53
|
+
* applied!
|
|
54
|
+
* 'data-qtip-testid': use this attribute to provide a value for a data-testid of your tooltip; this is useful
|
|
55
|
+
* for tests
|
|
56
|
+
*
|
|
57
|
+
* In order for QTip to be able to display Tooltips you must add the QTip component to your top-most component
|
|
58
|
+
* (often that's App or Application) - simply add:
|
|
59
|
+
*
|
|
60
|
+
* <QTip />
|
|
61
|
+
*
|
|
62
|
+
* and enjoy beautiful & performant tooltips!
|
|
63
|
+
*/
|
|
64
|
+
export const QTip = () => {
|
|
65
|
+
const tooltipRef = useRef(null);
|
|
66
|
+
const tooltipTarget = useRef(null);
|
|
67
|
+
const tooltipArrowRef = useRef(null);
|
|
68
|
+
const [tooltipText, setTooltipText] = useState('');
|
|
69
|
+
const [tooltipTargetOriginalPosition, setTooltipTargetOriginalPosition] = useState(null);
|
|
70
|
+
const [show, setShow] = useState(false);
|
|
71
|
+
const [html, setHtml] = useState(false);
|
|
72
|
+
const [tooltipTestId, setTooltipTestId] = useState('');
|
|
73
|
+
const [overTooltip, setOverTooltip] = useState(false);
|
|
74
|
+
// Check every 300ms if the tooltip target position has changed and hide the tooltip if this happens.
|
|
75
|
+
useIntervalWhen(() => {
|
|
76
|
+
const currentPosition = tooltipTarget?.current?.getBoundingClientRect();
|
|
77
|
+
if (overTooltip) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (tooltipTargetOriginalPosition?.y !== currentPosition?.y ||
|
|
81
|
+
tooltipTargetOriginalPosition?.x !== currentPosition?.x) {
|
|
82
|
+
setShow(false);
|
|
83
|
+
}
|
|
84
|
+
}, 300, show);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
!suppressTooltip() && document.body.addEventListener('mousemove', onMouseMove);
|
|
87
|
+
return () => {
|
|
88
|
+
!suppressTooltip() && document.removeEventListener('mousemove', onMouseMove);
|
|
89
|
+
};
|
|
90
|
+
}, []);
|
|
91
|
+
const ttTimeout = useRef(null);
|
|
92
|
+
const findTooltipData = (element) => {
|
|
93
|
+
// Traverse up to 8 levels to find the tooltip data
|
|
94
|
+
for (let i = 0; i < 8 && element; i++) {
|
|
95
|
+
if (!element) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (element?.dataset?.qtipText) {
|
|
99
|
+
return element.dataset;
|
|
100
|
+
}
|
|
101
|
+
element = element?.parentElement;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
const onMouseMove = (e) => {
|
|
106
|
+
if (ttTimeout.current) {
|
|
107
|
+
clearTimeout(ttTimeout.current);
|
|
108
|
+
}
|
|
109
|
+
// Find tooltip data on the current or parent elements
|
|
110
|
+
const target = e.target;
|
|
111
|
+
const dataset = findTooltipData(target);
|
|
112
|
+
if (!dataset) {
|
|
113
|
+
// No tooltip data found
|
|
114
|
+
tooltipTarget.current = null;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
tooltipTarget.current = target;
|
|
118
|
+
const text = dataset.qtipText;
|
|
119
|
+
if (text) {
|
|
120
|
+
const delay = parseInt(dataset.qtipDelay || `${DEFAULT_TOOL_TIP_DELAY}`, 10);
|
|
121
|
+
const placement = dataset.qtipPlacement || 'top';
|
|
122
|
+
const isHtml = dataset.qtipIsHtml === 'true';
|
|
123
|
+
const testId = dataset.qtipTestid;
|
|
124
|
+
// Debounced tooltip display
|
|
125
|
+
ttTimeout.current = setTimeout(() => {
|
|
126
|
+
makeTooltip(text, placement, isHtml, testId, delay);
|
|
127
|
+
}, delay);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const makeTooltip = (tooltipText, position = 'top', isHtml, dataTestId, delay) => {
|
|
131
|
+
if (tooltipText && tooltipTarget.current) {
|
|
132
|
+
setHtml(isHtml);
|
|
133
|
+
setTooltipText(tooltipText);
|
|
134
|
+
setTooltipTestId(dataTestId);
|
|
135
|
+
setTooltipTargetOriginalPosition(tooltipTarget.current.getBoundingClientRect());
|
|
136
|
+
const positionTooltip = () => {
|
|
137
|
+
if (tooltipRef.current && tooltipTarget.current) {
|
|
138
|
+
computePosition(tooltipTarget.current, tooltipRef.current, {
|
|
139
|
+
placement: position,
|
|
140
|
+
middleware: [offset(10), flip(), shift({ padding: 8 }), arrow({ element: tooltipArrowRef.current })],
|
|
141
|
+
}).then(({ x, y, middlewareData, placement: finalPlacement }) => {
|
|
142
|
+
Object.assign(tooltipRef.current?.style, {
|
|
143
|
+
left: `${x}px`,
|
|
144
|
+
top: `${y}px`,
|
|
145
|
+
});
|
|
146
|
+
if (middlewareData.arrow) {
|
|
147
|
+
const { x, y } = middlewareData.arrow;
|
|
148
|
+
const arrowWidth = tooltipArrowRef.current?.offsetHeight / 2;
|
|
149
|
+
const tooltipHeight = tooltipRef.current?.offsetHeight;
|
|
150
|
+
const tooltipWidth = tooltipRef.current?.offsetWidth;
|
|
151
|
+
const style = getArrowStyle(finalPlacement, x || y, arrowWidth, tooltipHeight, tooltipWidth);
|
|
152
|
+
Object.assign(tooltipArrowRef.current.style, style);
|
|
153
|
+
}
|
|
154
|
+
setShow(true);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
delay > 0
|
|
159
|
+
? requestAnimationFrame(() => {
|
|
160
|
+
positionTooltip();
|
|
161
|
+
})
|
|
162
|
+
: positionTooltip();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return (_jsx(_Fragment, { children: _jsxs("div", { onMouseEnter: () => setOverTooltip(true), onMouseLeave: () => setOverTooltip(false), "data-testid": tooltipTestId, ref: tooltipRef, className: 'tw-absolute tw-rounded tw-bg-black tw-max-w-96 tw-p-2 tw-text-xs tw-text-white tw-z-[9999] fade-in ' +
|
|
166
|
+
(show ? 'tw-visible' : 'tw-invisible tw-pointer-events-none'), children: [html ? _jsx(HTMLTip, { text: tooltipText }) : tooltipText, _jsx("div", { className: "tw-absolute tw-w-[10px] tw-h-[10px] tw-rotate-45 tw-bg-black", ref: tooltipArrowRef })
|
|
167
|
+
] }) }));
|
|
168
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '../styles.css';
|
|
3
|
+
import { TooltipProps } 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 declare const Tooltip: React.FunctionComponent<TooltipProps>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
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
|
+
const arrowRight = `${arrowBaseClasses} ${centerArrowVertically} before:tw-right-[100%] before:tw-border-y-transparent
|
|
18
|
+
before:tw-border-l-transparent before:tw-border-r-black`;
|
|
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`;
|
|
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`;
|
|
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 (_jsxs("div", { className: "tw-group tw-relative tw-inline-block", children: [children, _jsx("div", { className: `tw-z-50 tw-whitespace-nowrap tw-hidden group-hover:tw-inline-block group-hover:tw-delay-[${delay}ms]
|
|
32
|
+
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]}`, children: text })
|
|
33
|
+
] }));
|
|
34
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
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) => (_jsx("div", { children: _jsx(Tooltip, { text: `Tooltip on the ${position}`, position: position, children: _jsx(Button, { label: position }) }) }, `${position}_button`)));
|
|
11
|
+
const renderIconsWithHtmlTooltip = () => tooltipPositions.map((position) => (_jsx("div", { children: _jsx(Tooltip, { text: _jsxs("div", { children: [
|
|
12
|
+
_jsx("h2", { children: "Fancy Tooltip" }),
|
|
13
|
+
" This is a special tooltip. Why?",
|
|
14
|
+
_jsx("br", {}),
|
|
15
|
+
"Because it supports ",
|
|
16
|
+
_jsx("b", { children: "HTML!" })
|
|
17
|
+
] }), position: position, children: _jsx(Icon, { icon: "fc-sun" }) }) }, `${position}_icon`)));
|
|
18
|
+
const renderTextTooltipOnText = () => tooltipPositions.map((position) => (_jsx("div", { children: _jsx(Tooltip, { text: "Helpful information provided here", position: position, children: _jsxs("span", { children: ["Hover for Tooltip (on the ", position, ")"] }) }) }, `${position}_text`)));
|
|
19
|
+
return (_jsxs("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4 tw-text-center", children: [renderButtonsWithTooltip(), renderIconsWithHtmlTooltip(), renderTextTooltipOnText()] }));
|
|
20
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const DEFAULT_TOOL_TIP_DELAY = 500;
|
|
2
|
+
export declare const tooltipPositions: readonly ["top", "left", "right", "bottom"];
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export type TooltipPosition = typeof tooltipPositions[number];
|
|
5
|
+
export interface TooltipProps {
|
|
6
|
+
position?: TooltipPosition;
|
|
7
|
+
children?: React.JSX.Element | string;
|
|
8
|
+
text: React.JSX.Element | string;
|
|
9
|
+
delay?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface TooltipComponentProps {
|
|
12
|
+
/** text to display on tooltip */
|
|
13
|
+
tooltip?: string;
|
|
14
|
+
/** number of milliseconds to wait before showing a tooltip on-hover */
|
|
15
|
+
tooltipDelay?: number;
|
|
16
|
+
/** one of four possible tooltip positions */
|
|
17
|
+
tooltipPlacement?: TooltipPosition;
|
|
18
|
+
/** true if the provided tooltip text should be rendered as HTML */
|
|
19
|
+
isHtmlTooltip?: boolean;
|
|
20
|
+
/** optional testId applied to the tooltip - useful for testing */
|
|
21
|
+
tooltipTestId?: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
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(_jsx("td", { children: _jsx(Tooltip, { text: `hello there ${i}`, children: _jsx(Icon, { icon: "fc-sun" }) }) }, 'col_' + i + '_row_' + rowId));
|
|
15
|
+
}
|
|
16
|
+
return cols;
|
|
17
|
+
};
|
|
18
|
+
for (let i = 0; i < rowCount; i++) {
|
|
19
|
+
rows.push(_jsxs("tr", { children: [...getCols(i)] }, 'row_' + i));
|
|
20
|
+
}
|
|
21
|
+
return (_jsx("table", { children: _jsx("tbody", { children: rows.map((row) => row) }) }));
|
|
22
|
+
};
|
|
23
|
+
export const TooltipPerformance = () => {
|
|
24
|
+
return (_jsx(_Fragment, { children: _jsx("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4 tw-text-center", children: renderManyTooltips() }) }));
|
|
25
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { QTipDataAttributes } from './QTip.types';
|
|
2
|
+
import { TooltipComponentProps } from './Tooltip.types';
|
|
3
|
+
export declare const getQTipData: ({ tooltip, tooltipPlacement, isHtmlTooltip, tooltipTestId, tooltipDelay, }: TooltipComponentProps) => QTipDataAttributes | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Button from './Button';
|
|
2
|
+
import ToolbarButton from './ToolbarButton';
|
|
3
|
+
import TextField from './TextField';
|
|
4
|
+
import Checkbox from './Checkbox';
|
|
5
|
+
import TextArea from './TextArea';
|
|
6
|
+
import { QTip, Tooltip } from './Tooltip';
|
|
7
|
+
import Icon from './Icon';
|
|
8
|
+
import Select from './Select';
|
|
9
|
+
import { SelectCompoents } from './Select';
|
|
10
|
+
import Modal from './Modal';
|
|
11
|
+
import Tabs from './Tabs';
|
|
12
|
+
import Accordion from './Accordion';
|
|
13
|
+
import ButtonWithPopover from './ButtonWithPopover';
|
|
14
|
+
import ButtonWithDropdown from './ButtonWithDropdown';
|
|
15
|
+
import Alert from './Alert';
|
|
16
|
+
import SeeqActionDropdown from './SeeqActionDropdown';
|
|
17
|
+
import InputGroup from './InputGroup';
|
|
18
|
+
import Collapse from './Collapse';
|
|
19
|
+
import Slider from './Slider';
|
|
20
|
+
import ProgressBar from './ProgressBar';
|
|
21
|
+
import ButtonGroup from './ButtonGroup';
|
|
22
|
+
import Carousel from './Carousel';
|
|
23
|
+
export { Tabs };
|
|
24
|
+
export { Button };
|
|
25
|
+
export { ToolbarButton };
|
|
26
|
+
export { TextField };
|
|
27
|
+
export { TextArea };
|
|
28
|
+
export { Tooltip };
|
|
29
|
+
export { Checkbox };
|
|
30
|
+
export { Icon };
|
|
31
|
+
export { Select };
|
|
32
|
+
export { SelectCompoents };
|
|
33
|
+
export { QTip };
|
|
34
|
+
export { Modal };
|
|
35
|
+
export { Accordion };
|
|
36
|
+
export { ButtonWithPopover };
|
|
37
|
+
export { ButtonWithDropdown };
|
|
38
|
+
export { Alert };
|
|
39
|
+
export { SeeqActionDropdown };
|
|
40
|
+
export { InputGroup };
|
|
41
|
+
export { Collapse };
|
|
42
|
+
export { Slider };
|
|
43
|
+
export { ProgressBar };
|
|
44
|
+
export { ButtonGroup };
|
|
45
|
+
export { Carousel };
|
|
46
|
+
export * from './types';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Button from './Button';
|
|
2
|
+
import ToolbarButton from './ToolbarButton';
|
|
3
|
+
import TextField from './TextField';
|
|
4
|
+
import Checkbox from './Checkbox';
|
|
5
|
+
import TextArea from './TextArea';
|
|
6
|
+
import { QTip, Tooltip } from './Tooltip';
|
|
7
|
+
import Icon from './Icon';
|
|
8
|
+
import Select from './Select';
|
|
9
|
+
import { SelectCompoents } from './Select';
|
|
10
|
+
import Modal from './Modal';
|
|
11
|
+
import Tabs from './Tabs';
|
|
12
|
+
import Accordion from './Accordion';
|
|
13
|
+
import ButtonWithPopover from './ButtonWithPopover';
|
|
14
|
+
import ButtonWithDropdown from './ButtonWithDropdown';
|
|
15
|
+
import Alert from './Alert';
|
|
16
|
+
import SeeqActionDropdown from './SeeqActionDropdown';
|
|
17
|
+
import InputGroup from './InputGroup';
|
|
18
|
+
import Collapse from './Collapse';
|
|
19
|
+
import Slider from './Slider';
|
|
20
|
+
import ProgressBar from './ProgressBar';
|
|
21
|
+
import ButtonGroup from './ButtonGroup';
|
|
22
|
+
import Carousel from './Carousel';
|
|
23
|
+
export { Tabs };
|
|
24
|
+
export { Button };
|
|
25
|
+
export { ToolbarButton };
|
|
26
|
+
export { TextField };
|
|
27
|
+
export { TextArea };
|
|
28
|
+
export { Tooltip };
|
|
29
|
+
export { Checkbox };
|
|
30
|
+
export { Icon };
|
|
31
|
+
export { Select };
|
|
32
|
+
export { SelectCompoents };
|
|
33
|
+
export { QTip };
|
|
34
|
+
export { Modal };
|
|
35
|
+
export { Accordion };
|
|
36
|
+
export { ButtonWithPopover };
|
|
37
|
+
export { ButtonWithDropdown };
|
|
38
|
+
export { Alert };
|
|
39
|
+
export { SeeqActionDropdown };
|
|
40
|
+
export { InputGroup };
|
|
41
|
+
export { Collapse };
|
|
42
|
+
export { Slider };
|
|
43
|
+
export { ProgressBar };
|
|
44
|
+
export { ButtonGroup };
|
|
45
|
+
export { Carousel };
|
|
46
|
+
// Export types
|
|
47
|
+
export * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type InputGroupPlacement = 'left' | 'right' | undefined;
|
|
2
|
+
export type FormControlElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
3
|
+
export * from './Accordion/Accordion.types';
|
|
4
|
+
export * from './Alert/Alert.types';
|
|
5
|
+
export * from './Button/Button.types';
|
|
6
|
+
export * from './ButtonGroup/ButtonGroup.types';
|
|
7
|
+
export * from './ButtonWithDropdown/ButtonWithDropdown.types';
|
|
8
|
+
export * from './ButtonWithPopover/ButtonWithPopover.types';
|
|
9
|
+
export * from './Carousel/Carousel.types';
|
|
10
|
+
export * from './Checkbox/Checkbox.types';
|
|
11
|
+
export * from './Collapse/Collapse.types';
|
|
12
|
+
export * from './Icon/Icon.types';
|
|
13
|
+
export * from './InputGroup/InputGroup.types';
|
|
14
|
+
export * from './Modal/Modal.types';
|
|
15
|
+
export * from './ProgressBar/ProgressBar.types';
|
|
16
|
+
export * from './SeeqActionDropdown/SeeqActionDropdown.types';
|
|
17
|
+
export * from './Select/Select.types';
|
|
18
|
+
export * from './Slider/Slider.types';
|
|
19
|
+
export * from './SvgIcon/SvgIcon.types';
|
|
20
|
+
export * from './Tabs/Tabs.types';
|
|
21
|
+
export * from './TextArea/TextArea.types';
|
|
22
|
+
export * from './TextField/TextField.types';
|
|
23
|
+
export * from './ToolbarButton/ToolbarButton.types';
|
|
24
|
+
export * from './Tooltip/QTip.types';
|
|
25
|
+
export * from './Tooltip/Tooltip.types';
|
|
26
|
+
export type { ToolbarButtonVariant, ToolbarButtonProps } from './ToolbarButton/ToolbarButton.types';
|
|
27
|
+
export { toolbarButtonVariants } from './ToolbarButton/ToolbarButton.types';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Export all component types
|
|
2
|
+
export * from './Accordion/Accordion.types';
|
|
3
|
+
export * from './Alert/Alert.types';
|
|
4
|
+
export * from './Button/Button.types';
|
|
5
|
+
export * from './ButtonGroup/ButtonGroup.types';
|
|
6
|
+
export * from './ButtonWithDropdown/ButtonWithDropdown.types';
|
|
7
|
+
export * from './ButtonWithPopover/ButtonWithPopover.types';
|
|
8
|
+
export * from './Carousel/Carousel.types';
|
|
9
|
+
export * from './Checkbox/Checkbox.types';
|
|
10
|
+
export * from './Collapse/Collapse.types';
|
|
11
|
+
export * from './Icon/Icon.types';
|
|
12
|
+
export * from './InputGroup/InputGroup.types';
|
|
13
|
+
export * from './Modal/Modal.types';
|
|
14
|
+
export * from './ProgressBar/ProgressBar.types';
|
|
15
|
+
export * from './SeeqActionDropdown/SeeqActionDropdown.types';
|
|
16
|
+
export * from './Select/Select.types';
|
|
17
|
+
export * from './Slider/Slider.types';
|
|
18
|
+
export * from './SvgIcon/SvgIcon.types';
|
|
19
|
+
export * from './Tabs/Tabs.types';
|
|
20
|
+
export * from './TextArea/TextArea.types';
|
|
21
|
+
export * from './TextField/TextField.types';
|
|
22
|
+
export * from './ToolbarButton/ToolbarButton.types';
|
|
23
|
+
export * from './Tooltip/QTip.types';
|
|
24
|
+
export * from './Tooltip/Tooltip.types';
|
|
25
|
+
export { toolbarButtonVariants } from './ToolbarButton/ToolbarButton.types';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @exports the browser id (i.e., 'IE 11' 'Chrome 90')
|
|
3
|
+
* @see http://stackoverflow.com/questions/2400935/browser-detection-in-javascript
|
|
4
|
+
*/
|
|
5
|
+
export declare const browserId: string;
|
|
6
|
+
export declare const browserName: string;
|
|
7
|
+
export declare const browserVersion: number | "";
|
|
8
|
+
export declare const browserIsFirefox: boolean | "";
|
|
9
|
+
export declare const browserIsEdgeBeforeChromium: boolean | "" | 0;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @exports the browser id (i.e., 'IE 11' 'Chrome 90')
|
|
3
|
+
* @see http://stackoverflow.com/questions/2400935/browser-detection-in-javascript
|
|
4
|
+
*/
|
|
5
|
+
export const browserId = (function () {
|
|
6
|
+
let tem;
|
|
7
|
+
const ua = navigator.userAgent;
|
|
8
|
+
let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
9
|
+
if (/trident/i.test(M[1])) {
|
|
10
|
+
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
|
|
11
|
+
return `IE ${tem[1] || ''}`;
|
|
12
|
+
}
|
|
13
|
+
if (M[1] === 'Chrome') {
|
|
14
|
+
tem = ua.match(/\b(OPR|Edge?)\/(\d+)/);
|
|
15
|
+
if (tem !== null) {
|
|
16
|
+
return tem.slice(1).join(' ').replace('OPR', 'Opera').replace('Edg ', 'Edge ');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
|
|
20
|
+
if ((tem = ua.match(/version\/(\d+)/i)) !== null) {
|
|
21
|
+
M.splice(1, 1, tem[1]);
|
|
22
|
+
}
|
|
23
|
+
return M.join(' ');
|
|
24
|
+
})();
|
|
25
|
+
export const browserName = browserId && browserId.split(' ', 2)[0];
|
|
26
|
+
export const browserVersion = browserId && parseInt(browserId.split(' ', 2)[1], 10);
|
|
27
|
+
export const browserIsFirefox = browserId && browserName === 'Firefox';
|
|
28
|
+
export const browserIsEdgeBeforeChromium = browserName && browserVersion && browserName === 'Edge' && browserVersion < 70;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const SVG_PATH = "svgpath:";
|
|
2
|
+
/**
|
|
3
|
+
* Determines if an icon is SVG
|
|
4
|
+
*
|
|
5
|
+
* @param icon - an icon string that will either be an icon class or an SVG path definition (e.g. "fa fa-wrench" or
|
|
6
|
+
* "svgpath:M 17.0181 0 ...")
|
|
7
|
+
*/
|
|
8
|
+
export declare function isSvgIcon(icon: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the SVG path from an SVG icon
|
|
11
|
+
*
|
|
12
|
+
* @param icon - an SVG icon string including path definition (e.g. "svgpath:M 17.0181 0 ...")
|
|
13
|
+
* @returns the SVG icon path or an empty string if the supplied icon is not SVG
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSvgIconPath(icon: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const SVG_PATH = 'svgpath:';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if an icon is SVG
|
|
4
|
+
*
|
|
5
|
+
* @param icon - an icon string that will either be an icon class or an SVG path definition (e.g. "fa fa-wrench" or
|
|
6
|
+
* "svgpath:M 17.0181 0 ...")
|
|
7
|
+
*/
|
|
8
|
+
export function isSvgIcon(icon) {
|
|
9
|
+
return icon.startsWith(SVG_PATH);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the SVG path from an SVG icon
|
|
13
|
+
*
|
|
14
|
+
* @param icon - an SVG icon string including path definition (e.g. "svgpath:M 17.0181 0 ...")
|
|
15
|
+
* @returns the SVG icon path or an empty string if the supplied icon is not SVG
|
|
16
|
+
*/
|
|
17
|
+
export function getSvgIconPath(icon) {
|
|
18
|
+
return isSvgIcon(icon) ? icon.substring(SVG_PATH.length) : '';
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const setValidInputDimension = (width, height) => {
|
|
2
|
+
let inputStyle;
|
|
3
|
+
if (typeof width === 'number' && width > 0) {
|
|
4
|
+
inputStyle = {
|
|
5
|
+
width: `${width}px`,
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
if (typeof height === 'number' && height > 0) {
|
|
9
|
+
inputStyle = inputStyle || {};
|
|
10
|
+
inputStyle['height'] = `${height}px`;
|
|
11
|
+
}
|
|
12
|
+
return inputStyle;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { setValidInputDimension } from './validateStyleDimension';
|
|
2
|
+
describe('setValidInputDimension', () => {
|
|
3
|
+
it('returns undefined if both width and height are undefined', () => {
|
|
4
|
+
const result = setValidInputDimension();
|
|
5
|
+
expect(result).toBeUndefined();
|
|
6
|
+
});
|
|
7
|
+
it('returns a DimensionStyle object with width if width is a valid number', () => {
|
|
8
|
+
const result = setValidInputDimension(300);
|
|
9
|
+
expect(result).toEqual({ width: '300px' });
|
|
10
|
+
});
|
|
11
|
+
it('returns a DimensionStyle object with height if height is a valid number', () => {
|
|
12
|
+
const result = setValidInputDimension(undefined, 400);
|
|
13
|
+
expect(result).toEqual({ height: '400px' });
|
|
14
|
+
});
|
|
15
|
+
it('returns a DimensionStyle object with both width and height if both are valid numbers', () => {
|
|
16
|
+
const result = setValidInputDimension(500, 600);
|
|
17
|
+
expect(result).toEqual({ width: '500px', height: '600px' });
|
|
18
|
+
});
|
|
19
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seeqdev/qomponents",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.185",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@typescript/native-preview": "7.0.0-dev.20260102.1",
|
|
45
45
|
"autoprefixer": "10.4.17",
|
|
46
46
|
"color": "4.2.3",
|
|
47
|
+
"cross-env": "10.0.0",
|
|
47
48
|
"identity-obj-proxy": "3.0.0",
|
|
48
49
|
"jest": "29.7.0",
|
|
49
50
|
"jest-cli": "29.7.0",
|
|
@@ -83,9 +84,14 @@
|
|
|
83
84
|
},
|
|
84
85
|
"scripts": {
|
|
85
86
|
"build": "rollup -c --bundleConfigAsCjs",
|
|
86
|
-
"
|
|
87
|
-
"test": "jest",
|
|
88
|
-
"test:watch": "jest --watch",
|
|
89
|
-
"dev": "ladle serve"
|
|
87
|
+
"build:watch": "rollup -c --bundleConfigAsCjs --watch",
|
|
88
|
+
"test": "cross-env TZ=UTC LANG=en-US jest",
|
|
89
|
+
"test:watch": "cross-env TZ=UTC LANG=en-US jest --watch",
|
|
90
|
+
"dev": "ladle serve",
|
|
91
|
+
"lint": "echo 'ESLint not configured yet'",
|
|
92
|
+
"lint:fix": "echo 'ESLint not configured yet'",
|
|
93
|
+
"format:check": "prettier --check \"**/*.{ts,tsx,js,json,css}\"",
|
|
94
|
+
"format:write": "prettier --write \"**/*.{ts,tsx,js,json,css}\"",
|
|
95
|
+
"type:check": "tsc --noEmit"
|
|
90
96
|
}
|
|
91
97
|
}
|