venice-ui 3.0.46 → 3.0.48
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/cjs/components/Filters/Filters.js +0 -21
- package/dist/cjs/components/Icon/Icon.js +2 -2
- package/dist/cjs/components/Tooltip/Tooltip.js +142 -0
- package/dist/cjs/components/Tooltip/Tooltip.styles.js +27 -0
- package/dist/cjs/components/Tooltip/index.js +5 -0
- package/dist/cjs/config/config.js +19 -1
- package/dist/cjs/index.js +1 -0
- package/dist/esm/components/Filters/Filters.js +0 -21
- package/dist/esm/components/Icon/Icon.js +2 -2
- package/dist/esm/components/Tooltip/Tooltip.js +106 -1
- package/dist/esm/components/Tooltip/Tooltip.styles.js +21 -0
- package/dist/esm/components/Tooltip/index.js +1 -0
- package/dist/esm/config/config.js +19 -1
- package/dist/esm/index.js +1 -0
- package/dist/types/components/Tooltip/Tooltip.d.ts +14 -0
- package/dist/types/components/Tooltip/Tooltip.styles.d.ts +10 -0
- package/dist/types/components/Tooltip/index.d.ts +1 -0
- package/dist/types/config/config.d.ts +53 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -61,23 +61,6 @@ const Filters = ({ theme, themeVariant = 'default', size = 'md', labels = {
|
|
|
61
61
|
const resolvedTheme = resolvedThemeData.resolvedTheme;
|
|
62
62
|
const { componentsConfig } = resolvedThemeData;
|
|
63
63
|
const filterConfig = componentsConfig.filters;
|
|
64
|
-
console.log('--------');
|
|
65
|
-
console.log('filter fullElements', fullElements);
|
|
66
|
-
// const normalizeDateValue = useCallback(
|
|
67
|
-
// (rawValue: any): number | undefined => {
|
|
68
|
-
// if (rawValue === undefined || rawValue === null || rawValue === '') {
|
|
69
|
-
// return undefined
|
|
70
|
-
// }
|
|
71
|
-
// const numericValue =
|
|
72
|
-
// typeof rawValue === 'number' ? rawValue : Number(rawValue)
|
|
73
|
-
// if (!Number.isNaN(numericValue)) {
|
|
74
|
-
// return numericValue
|
|
75
|
-
// }
|
|
76
|
-
// const parsed = new Date(rawValue)
|
|
77
|
-
// return Number.isNaN(parsed.getTime()) ? undefined : parsed.getTime()
|
|
78
|
-
// },
|
|
79
|
-
// [],
|
|
80
|
-
// )
|
|
81
64
|
const [source, _setSource] = (0, react_1.useState)(fullElements || []);
|
|
82
65
|
const sourceRef = (0, react_1.useRef)(source);
|
|
83
66
|
const setSource = (data) => {
|
|
@@ -147,9 +130,6 @@ const Filters = ({ theme, themeVariant = 'default', size = 'md', labels = {
|
|
|
147
130
|
collapsible: true,
|
|
148
131
|
};
|
|
149
132
|
}
|
|
150
|
-
if (type === 'select' && h.name === 'joint_name') {
|
|
151
|
-
console.log('scope', values);
|
|
152
|
-
}
|
|
153
133
|
return {
|
|
154
134
|
label: h.name,
|
|
155
135
|
name: key,
|
|
@@ -266,7 +246,6 @@ const Filters = ({ theme, themeVariant = 'default', size = 'md', labels = {
|
|
|
266
246
|
[filterName]: { ...prev[filterName], [filterParam]: value },
|
|
267
247
|
}));
|
|
268
248
|
}, []);
|
|
269
|
-
console.log('activeFilters', activeFilters);
|
|
270
249
|
const setTextFilter = (0, react_1.useCallback)((name, value) => {
|
|
271
250
|
const filterName = (name || '').split('__')[0];
|
|
272
251
|
setActiveFilters((prev) => ({
|
|
@@ -39,9 +39,9 @@ const styled_components_1 = require("styled-components");
|
|
|
39
39
|
const Icon_styles_1 = require("./Icon.styles");
|
|
40
40
|
const IconsPath_1 = require("./IconsPath");
|
|
41
41
|
const config_1 = require("../../config");
|
|
42
|
+
const Tooltip_1 = require("../Tooltip");
|
|
42
43
|
const Icon = ({ name = 'person', size = 'lg', isDisabled = false, isActive = false, isError = false, onClick, tooltip, color, background, hoverColor, hoverBackground, theme, themeVariant = 'default', }) => {
|
|
43
44
|
const iconRef = (0, react_1.useRef)(null);
|
|
44
|
-
// const [showTooltip, setShowTooltip] = useState(false)
|
|
45
45
|
const { resolvedTheme, componentsConfig } = (0, config_1.resolveThemeWithComponentsConfig)({
|
|
46
46
|
theme,
|
|
47
47
|
themeVariant,
|
|
@@ -56,7 +56,7 @@ const Icon = ({ name = 'person', size = 'lg', isDisabled = false, isActive = fal
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
return (react_1.default.createElement(styled_components_1.ThemeProvider, { theme: resolvedTheme },
|
|
59
|
-
react_1.default.createElement(
|
|
59
|
+
react_1.default.createElement(Tooltip_1.Tooltip, { content: tooltip, disabled: !tooltip },
|
|
60
60
|
react_1.default.createElement(Icon_styles_1.IconElement, { ref: iconRef, config: componentsConfig, onClick: handleClick, isDisabled: isDisabled, isError: isError, isActive: isActive, color: color, background: background, hoverColor: hoverColor, hoverBackground: hoverBackground, resolvedSize: resolvedSize,
|
|
61
61
|
// onMouseEnter={() => setShowTooltip(true)}
|
|
62
62
|
// onMouseLeave={() => setShowTooltip(false)}
|
|
@@ -1 +1,143 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Tooltip = void 0;
|
|
37
|
+
const config_1 = require("../../config");
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const react_dom_1 = require("react-dom");
|
|
40
|
+
const styled_components_1 = require("styled-components");
|
|
41
|
+
const Tooltip_styles_1 = require("./Tooltip.styles");
|
|
42
|
+
const Tooltip = ({ children, content, position = 'top', disabled = false, delay = 200, theme, themeVariant = 'default', }) => {
|
|
43
|
+
const { resolvedTheme, componentsConfig } = (0, config_1.resolveThemeWithComponentsConfig)({
|
|
44
|
+
theme,
|
|
45
|
+
themeVariant,
|
|
46
|
+
});
|
|
47
|
+
const tooltipConfig = componentsConfig.tooltip;
|
|
48
|
+
const triggerRef = (0, react_1.useRef)(null);
|
|
49
|
+
const tooltipRef = (0, react_1.useRef)(null);
|
|
50
|
+
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
51
|
+
const [coords, setCoords] = (0, react_1.useState)({
|
|
52
|
+
top: 0,
|
|
53
|
+
left: 0,
|
|
54
|
+
});
|
|
55
|
+
(0, react_1.useEffect)(() => {
|
|
56
|
+
if (!visible)
|
|
57
|
+
return;
|
|
58
|
+
const trigger = triggerRef.current;
|
|
59
|
+
const tooltip = tooltipRef.current;
|
|
60
|
+
if (!trigger || !tooltip)
|
|
61
|
+
return;
|
|
62
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
63
|
+
const tooltipRect = tooltip.getBoundingClientRect();
|
|
64
|
+
let nextPosition = position;
|
|
65
|
+
if (position === 'top' && triggerRect.top - tooltipRect.height < 8) {
|
|
66
|
+
nextPosition = 'bottom';
|
|
67
|
+
}
|
|
68
|
+
if (position === 'bottom' &&
|
|
69
|
+
triggerRect.bottom + tooltipRect.height > window.innerHeight - 8) {
|
|
70
|
+
nextPosition = 'top';
|
|
71
|
+
}
|
|
72
|
+
if (position === 'left' && triggerRect.left - tooltipRect.width < 8) {
|
|
73
|
+
nextPosition = 'right';
|
|
74
|
+
}
|
|
75
|
+
if (position === 'right' &&
|
|
76
|
+
triggerRect.right + tooltipRect.width > window.innerWidth - 8) {
|
|
77
|
+
nextPosition = 'left';
|
|
78
|
+
}
|
|
79
|
+
const gap = 8;
|
|
80
|
+
let top = 0;
|
|
81
|
+
let left = 0;
|
|
82
|
+
switch (nextPosition) {
|
|
83
|
+
case 'top':
|
|
84
|
+
top = triggerRect.top + window.scrollY - tooltipRect.height - gap;
|
|
85
|
+
left =
|
|
86
|
+
triggerRect.left +
|
|
87
|
+
window.scrollX +
|
|
88
|
+
triggerRect.width / 2 -
|
|
89
|
+
tooltipRect.width / 2;
|
|
90
|
+
break;
|
|
91
|
+
case 'bottom':
|
|
92
|
+
top = triggerRect.bottom + window.scrollY + gap;
|
|
93
|
+
left =
|
|
94
|
+
triggerRect.left +
|
|
95
|
+
window.scrollX +
|
|
96
|
+
triggerRect.width / 2 -
|
|
97
|
+
tooltipRect.width / 2;
|
|
98
|
+
break;
|
|
99
|
+
case 'left':
|
|
100
|
+
top =
|
|
101
|
+
triggerRect.top +
|
|
102
|
+
window.scrollY +
|
|
103
|
+
triggerRect.height / 2 -
|
|
104
|
+
tooltipRect.height / 2;
|
|
105
|
+
left = triggerRect.left + window.scrollX - tooltipRect.width - gap;
|
|
106
|
+
break;
|
|
107
|
+
case 'right':
|
|
108
|
+
top =
|
|
109
|
+
triggerRect.top +
|
|
110
|
+
window.scrollY +
|
|
111
|
+
triggerRect.height / 2 -
|
|
112
|
+
tooltipRect.height / 2;
|
|
113
|
+
left = triggerRect.right + window.scrollX + gap;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
setCoords({ top, left });
|
|
117
|
+
}, [visible, position]);
|
|
118
|
+
(0, react_1.useEffect)(() => {
|
|
119
|
+
const close = () => setVisible(false);
|
|
120
|
+
window.addEventListener('scroll', close, true);
|
|
121
|
+
window.addEventListener('resize', close);
|
|
122
|
+
return () => {
|
|
123
|
+
window.removeEventListener('scroll', close, true);
|
|
124
|
+
window.removeEventListener('resize', close);
|
|
125
|
+
};
|
|
126
|
+
}, []);
|
|
127
|
+
let timer;
|
|
128
|
+
const show = () => {
|
|
129
|
+
timer = setTimeout(() => {
|
|
130
|
+
setVisible(true);
|
|
131
|
+
}, delay);
|
|
132
|
+
};
|
|
133
|
+
const hide = () => {
|
|
134
|
+
clearTimeout(timer);
|
|
135
|
+
setVisible(false);
|
|
136
|
+
};
|
|
137
|
+
return (react_1.default.createElement(styled_components_1.ThemeProvider, { theme: resolvedTheme },
|
|
138
|
+
react_1.default.createElement(Tooltip_styles_1.TooltipTriger, { ref: triggerRef, onMouseEnter: show, onMouseLeave: hide, onFocus: show, onBlur: hide }, children),
|
|
139
|
+
!disabled &&
|
|
140
|
+
visible &&
|
|
141
|
+
(0, react_dom_1.createPortal)(react_1.default.createElement(Tooltip_styles_1.TooltipRoot, { ref: tooltipRef, top: coords.top, left: coords.left, config: tooltipConfig, theme: resolvedTheme }, content), document.body)));
|
|
142
|
+
};
|
|
143
|
+
exports.Tooltip = Tooltip;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TooltipRoot = exports.TooltipTriger = void 0;
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
exports.TooltipTriger = styled_components_1.default.div `
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
`;
|
|
12
|
+
exports.TooltipRoot = styled_components_1.default.div `
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
position: absolute;
|
|
15
|
+
z-index: ${({ config }) => config.size.zIndex};
|
|
16
|
+
background-color: ${({ config }) => config.color.background};
|
|
17
|
+
padding: ${({ config }) => `${config.size.paddingY}px ${config.size.paddingX}px`};
|
|
18
|
+
border-radius: ${({ config }) => `${config.size.radius}px`};
|
|
19
|
+
box-shadow: ${({ config }) => config.color.shadow};
|
|
20
|
+
color: ${({ config }) => config.color.text};
|
|
21
|
+
font-size: ${({ config }) => `${config.size.fontSize}px`};
|
|
22
|
+
line-height: ${({ config }) => `${config.size.lineHeight}px`};
|
|
23
|
+
top: ${({ top }) => `${top}px`};
|
|
24
|
+
left: ${({ left }) => `${left}px`};
|
|
25
|
+
white-space: nowrap;
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
`;
|
|
@@ -95,6 +95,7 @@ const createTheme = (theme = 'default') => {
|
|
|
95
95
|
inner: 'inset 0 1px 2px rgba(0,0,0,0.06)',
|
|
96
96
|
card: ' 0px 1px 2px rgba(16, 24, 40, 0.04),0px 1px 3px rgba(16, 24, 40, 0.10);',
|
|
97
97
|
modal: '0px 24px 48px rgba(15, 23, 42, 0.18),0px 8px 16px rgba(15, 23, 42, 0.12),0px 2px 4px rgba(15, 23, 42, 0.08)',
|
|
98
|
+
tooltip: '0 4px 12px rgba(0,0,0,.15)',
|
|
98
99
|
},
|
|
99
100
|
divider: {
|
|
100
101
|
default: 'rgba(17,24,39,0.06)',
|
|
@@ -104,6 +105,7 @@ const createTheme = (theme = 'default') => {
|
|
|
104
105
|
},
|
|
105
106
|
other: {
|
|
106
107
|
transparent: 'transparent',
|
|
108
|
+
almostBlack: p.neutral[800],
|
|
107
109
|
},
|
|
108
110
|
};
|
|
109
111
|
};
|
|
@@ -235,6 +237,7 @@ exports.measurements = {
|
|
|
235
237
|
modal: 1001,
|
|
236
238
|
sidepanel: 900,
|
|
237
239
|
sidepanelOverlayer: 850,
|
|
240
|
+
tooltip: 9999,
|
|
238
241
|
uperModal: 1100,
|
|
239
242
|
},
|
|
240
243
|
};
|
|
@@ -1408,7 +1411,7 @@ const createComponentsConfig = (theme = 'default') => {
|
|
|
1408
1411
|
},
|
|
1409
1412
|
icon: {
|
|
1410
1413
|
width: exports.measurements.space.xl3,
|
|
1411
|
-
}
|
|
1414
|
+
},
|
|
1412
1415
|
},
|
|
1413
1416
|
},
|
|
1414
1417
|
},
|
|
@@ -1440,6 +1443,21 @@ const createComponentsConfig = (theme = 'default') => {
|
|
|
1440
1443
|
},
|
|
1441
1444
|
},
|
|
1442
1445
|
},
|
|
1446
|
+
tooltip: {
|
|
1447
|
+
size: {
|
|
1448
|
+
fontSize: exports.measurements.font.size.xs,
|
|
1449
|
+
lineHeight: exports.measurements.font.lineHeight.xs,
|
|
1450
|
+
paddingX: exports.measurements.space.sm,
|
|
1451
|
+
paddingY: exports.measurements.space.md,
|
|
1452
|
+
radius: exports.measurements.size.radius.sm,
|
|
1453
|
+
zIndex: exports.measurements.zIndex.tooltip,
|
|
1454
|
+
},
|
|
1455
|
+
color: {
|
|
1456
|
+
background: Theme.other.almostBlack, // or #111827
|
|
1457
|
+
text: Theme.text.inverse,
|
|
1458
|
+
shadow: Theme.shadow.tooltip,
|
|
1459
|
+
},
|
|
1460
|
+
},
|
|
1443
1461
|
};
|
|
1444
1462
|
};
|
|
1445
1463
|
exports.createComponentsConfig = createComponentsConfig;
|
package/dist/cjs/index.js
CHANGED
|
@@ -47,5 +47,6 @@ __exportStar(require("./components/Table"), exports);
|
|
|
47
47
|
__exportStar(require("./components/Tag"), exports);
|
|
48
48
|
__exportStar(require("./components/Tile"), exports);
|
|
49
49
|
__exportStar(require("./components/Toggle"), exports);
|
|
50
|
+
__exportStar(require("./components/Tooltip"), exports);
|
|
50
51
|
__exportStar(require("./components/Typography"), exports);
|
|
51
52
|
__exportStar(require("./types"), exports);
|
|
@@ -25,23 +25,6 @@ export const Filters = ({ theme, themeVariant = 'default', size = 'md', labels =
|
|
|
25
25
|
const resolvedTheme = resolvedThemeData.resolvedTheme;
|
|
26
26
|
const { componentsConfig } = resolvedThemeData;
|
|
27
27
|
const filterConfig = componentsConfig.filters;
|
|
28
|
-
console.log('--------');
|
|
29
|
-
console.log('filter fullElements', fullElements);
|
|
30
|
-
// const normalizeDateValue = useCallback(
|
|
31
|
-
// (rawValue: any): number | undefined => {
|
|
32
|
-
// if (rawValue === undefined || rawValue === null || rawValue === '') {
|
|
33
|
-
// return undefined
|
|
34
|
-
// }
|
|
35
|
-
// const numericValue =
|
|
36
|
-
// typeof rawValue === 'number' ? rawValue : Number(rawValue)
|
|
37
|
-
// if (!Number.isNaN(numericValue)) {
|
|
38
|
-
// return numericValue
|
|
39
|
-
// }
|
|
40
|
-
// const parsed = new Date(rawValue)
|
|
41
|
-
// return Number.isNaN(parsed.getTime()) ? undefined : parsed.getTime()
|
|
42
|
-
// },
|
|
43
|
-
// [],
|
|
44
|
-
// )
|
|
45
28
|
const [source, _setSource] = useState(fullElements || []);
|
|
46
29
|
const sourceRef = useRef(source);
|
|
47
30
|
const setSource = (data) => {
|
|
@@ -111,9 +94,6 @@ export const Filters = ({ theme, themeVariant = 'default', size = 'md', labels =
|
|
|
111
94
|
collapsible: true,
|
|
112
95
|
};
|
|
113
96
|
}
|
|
114
|
-
if (type === 'select' && h.name === 'joint_name') {
|
|
115
|
-
console.log('scope', values);
|
|
116
|
-
}
|
|
117
97
|
return {
|
|
118
98
|
label: h.name,
|
|
119
99
|
name: key,
|
|
@@ -230,7 +210,6 @@ export const Filters = ({ theme, themeVariant = 'default', size = 'md', labels =
|
|
|
230
210
|
[filterName]: { ...prev[filterName], [filterParam]: value },
|
|
231
211
|
}));
|
|
232
212
|
}, []);
|
|
233
|
-
console.log('activeFilters', activeFilters);
|
|
234
213
|
const setTextFilter = useCallback((name, value) => {
|
|
235
214
|
const filterName = (name || '').split('__')[0];
|
|
236
215
|
setActiveFilters((prev) => ({
|
|
@@ -3,9 +3,9 @@ import { ThemeProvider } from 'styled-components';
|
|
|
3
3
|
import { IconElement } from './Icon.styles';
|
|
4
4
|
import { iconsPath } from './IconsPath';
|
|
5
5
|
import { resolveThemeWithComponentsConfig } from '../../config';
|
|
6
|
+
import { Tooltip } from '../Tooltip';
|
|
6
7
|
export const Icon = ({ name = 'person', size = 'lg', isDisabled = false, isActive = false, isError = false, onClick, tooltip, color, background, hoverColor, hoverBackground, theme, themeVariant = 'default', }) => {
|
|
7
8
|
const iconRef = useRef(null);
|
|
8
|
-
// const [showTooltip, setShowTooltip] = useState(false)
|
|
9
9
|
const { resolvedTheme, componentsConfig } = resolveThemeWithComponentsConfig({
|
|
10
10
|
theme,
|
|
11
11
|
themeVariant,
|
|
@@ -20,7 +20,7 @@ export const Icon = ({ name = 'person', size = 'lg', isDisabled = false, isActiv
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
return (React.createElement(ThemeProvider, { theme: resolvedTheme },
|
|
23
|
-
React.createElement(
|
|
23
|
+
React.createElement(Tooltip, { content: tooltip, disabled: !tooltip },
|
|
24
24
|
React.createElement(IconElement, { ref: iconRef, config: componentsConfig, onClick: handleClick, isDisabled: isDisabled, isError: isError, isActive: isActive, color: color, background: background, hoverColor: hoverColor, hoverBackground: hoverBackground, resolvedSize: resolvedSize,
|
|
25
25
|
// onMouseEnter={() => setShowTooltip(true)}
|
|
26
26
|
// onMouseLeave={() => setShowTooltip(false)}
|
|
@@ -1 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolveThemeWithComponentsConfig, } from '../../config';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { ThemeProvider } from 'styled-components';
|
|
5
|
+
import { TooltipRoot, TooltipTriger } from './Tooltip.styles';
|
|
6
|
+
export const Tooltip = ({ children, content, position = 'top', disabled = false, delay = 200, theme, themeVariant = 'default', }) => {
|
|
7
|
+
const { resolvedTheme, componentsConfig } = resolveThemeWithComponentsConfig({
|
|
8
|
+
theme,
|
|
9
|
+
themeVariant,
|
|
10
|
+
});
|
|
11
|
+
const tooltipConfig = componentsConfig.tooltip;
|
|
12
|
+
const triggerRef = useRef(null);
|
|
13
|
+
const tooltipRef = useRef(null);
|
|
14
|
+
const [visible, setVisible] = useState(false);
|
|
15
|
+
const [coords, setCoords] = useState({
|
|
16
|
+
top: 0,
|
|
17
|
+
left: 0,
|
|
18
|
+
});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!visible)
|
|
21
|
+
return;
|
|
22
|
+
const trigger = triggerRef.current;
|
|
23
|
+
const tooltip = tooltipRef.current;
|
|
24
|
+
if (!trigger || !tooltip)
|
|
25
|
+
return;
|
|
26
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
27
|
+
const tooltipRect = tooltip.getBoundingClientRect();
|
|
28
|
+
let nextPosition = position;
|
|
29
|
+
if (position === 'top' && triggerRect.top - tooltipRect.height < 8) {
|
|
30
|
+
nextPosition = 'bottom';
|
|
31
|
+
}
|
|
32
|
+
if (position === 'bottom' &&
|
|
33
|
+
triggerRect.bottom + tooltipRect.height > window.innerHeight - 8) {
|
|
34
|
+
nextPosition = 'top';
|
|
35
|
+
}
|
|
36
|
+
if (position === 'left' && triggerRect.left - tooltipRect.width < 8) {
|
|
37
|
+
nextPosition = 'right';
|
|
38
|
+
}
|
|
39
|
+
if (position === 'right' &&
|
|
40
|
+
triggerRect.right + tooltipRect.width > window.innerWidth - 8) {
|
|
41
|
+
nextPosition = 'left';
|
|
42
|
+
}
|
|
43
|
+
const gap = 8;
|
|
44
|
+
let top = 0;
|
|
45
|
+
let left = 0;
|
|
46
|
+
switch (nextPosition) {
|
|
47
|
+
case 'top':
|
|
48
|
+
top = triggerRect.top + window.scrollY - tooltipRect.height - gap;
|
|
49
|
+
left =
|
|
50
|
+
triggerRect.left +
|
|
51
|
+
window.scrollX +
|
|
52
|
+
triggerRect.width / 2 -
|
|
53
|
+
tooltipRect.width / 2;
|
|
54
|
+
break;
|
|
55
|
+
case 'bottom':
|
|
56
|
+
top = triggerRect.bottom + window.scrollY + gap;
|
|
57
|
+
left =
|
|
58
|
+
triggerRect.left +
|
|
59
|
+
window.scrollX +
|
|
60
|
+
triggerRect.width / 2 -
|
|
61
|
+
tooltipRect.width / 2;
|
|
62
|
+
break;
|
|
63
|
+
case 'left':
|
|
64
|
+
top =
|
|
65
|
+
triggerRect.top +
|
|
66
|
+
window.scrollY +
|
|
67
|
+
triggerRect.height / 2 -
|
|
68
|
+
tooltipRect.height / 2;
|
|
69
|
+
left = triggerRect.left + window.scrollX - tooltipRect.width - gap;
|
|
70
|
+
break;
|
|
71
|
+
case 'right':
|
|
72
|
+
top =
|
|
73
|
+
triggerRect.top +
|
|
74
|
+
window.scrollY +
|
|
75
|
+
triggerRect.height / 2 -
|
|
76
|
+
tooltipRect.height / 2;
|
|
77
|
+
left = triggerRect.right + window.scrollX + gap;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
setCoords({ top, left });
|
|
81
|
+
}, [visible, position]);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const close = () => setVisible(false);
|
|
84
|
+
window.addEventListener('scroll', close, true);
|
|
85
|
+
window.addEventListener('resize', close);
|
|
86
|
+
return () => {
|
|
87
|
+
window.removeEventListener('scroll', close, true);
|
|
88
|
+
window.removeEventListener('resize', close);
|
|
89
|
+
};
|
|
90
|
+
}, []);
|
|
91
|
+
let timer;
|
|
92
|
+
const show = () => {
|
|
93
|
+
timer = setTimeout(() => {
|
|
94
|
+
setVisible(true);
|
|
95
|
+
}, delay);
|
|
96
|
+
};
|
|
97
|
+
const hide = () => {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
setVisible(false);
|
|
100
|
+
};
|
|
101
|
+
return (React.createElement(ThemeProvider, { theme: resolvedTheme },
|
|
102
|
+
React.createElement(TooltipTriger, { ref: triggerRef, onMouseEnter: show, onMouseLeave: hide, onFocus: show, onBlur: hide }, children),
|
|
103
|
+
!disabled &&
|
|
104
|
+
visible &&
|
|
105
|
+
createPortal(React.createElement(TooltipRoot, { ref: tooltipRef, top: coords.top, left: coords.left, config: tooltipConfig, theme: resolvedTheme }, content), document.body)));
|
|
106
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
export const TooltipTriger = styled.div `
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
`;
|
|
6
|
+
export const TooltipRoot = styled.div `
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
position: absolute;
|
|
9
|
+
z-index: ${({ config }) => config.size.zIndex};
|
|
10
|
+
background-color: ${({ config }) => config.color.background};
|
|
11
|
+
padding: ${({ config }) => `${config.size.paddingY}px ${config.size.paddingX}px`};
|
|
12
|
+
border-radius: ${({ config }) => `${config.size.radius}px`};
|
|
13
|
+
box-shadow: ${({ config }) => config.color.shadow};
|
|
14
|
+
color: ${({ config }) => config.color.text};
|
|
15
|
+
font-size: ${({ config }) => `${config.size.fontSize}px`};
|
|
16
|
+
line-height: ${({ config }) => `${config.size.lineHeight}px`};
|
|
17
|
+
top: ${({ top }) => `${top}px`};
|
|
18
|
+
left: ${({ left }) => `${left}px`};
|
|
19
|
+
white-space: nowrap;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Tooltip } from './Tooltip';
|
|
@@ -92,6 +92,7 @@ export const createTheme = (theme = 'default') => {
|
|
|
92
92
|
inner: 'inset 0 1px 2px rgba(0,0,0,0.06)',
|
|
93
93
|
card: ' 0px 1px 2px rgba(16, 24, 40, 0.04),0px 1px 3px rgba(16, 24, 40, 0.10);',
|
|
94
94
|
modal: '0px 24px 48px rgba(15, 23, 42, 0.18),0px 8px 16px rgba(15, 23, 42, 0.12),0px 2px 4px rgba(15, 23, 42, 0.08)',
|
|
95
|
+
tooltip: '0 4px 12px rgba(0,0,0,.15)',
|
|
95
96
|
},
|
|
96
97
|
divider: {
|
|
97
98
|
default: 'rgba(17,24,39,0.06)',
|
|
@@ -101,6 +102,7 @@ export const createTheme = (theme = 'default') => {
|
|
|
101
102
|
},
|
|
102
103
|
other: {
|
|
103
104
|
transparent: 'transparent',
|
|
105
|
+
almostBlack: p.neutral[800],
|
|
104
106
|
},
|
|
105
107
|
};
|
|
106
108
|
};
|
|
@@ -231,6 +233,7 @@ export const measurements = {
|
|
|
231
233
|
modal: 1001,
|
|
232
234
|
sidepanel: 900,
|
|
233
235
|
sidepanelOverlayer: 850,
|
|
236
|
+
tooltip: 9999,
|
|
234
237
|
uperModal: 1100,
|
|
235
238
|
},
|
|
236
239
|
};
|
|
@@ -1403,7 +1406,7 @@ export const createComponentsConfig = (theme = 'default') => {
|
|
|
1403
1406
|
},
|
|
1404
1407
|
icon: {
|
|
1405
1408
|
width: measurements.space.xl3,
|
|
1406
|
-
}
|
|
1409
|
+
},
|
|
1407
1410
|
},
|
|
1408
1411
|
},
|
|
1409
1412
|
},
|
|
@@ -1435,6 +1438,21 @@ export const createComponentsConfig = (theme = 'default') => {
|
|
|
1435
1438
|
},
|
|
1436
1439
|
},
|
|
1437
1440
|
},
|
|
1441
|
+
tooltip: {
|
|
1442
|
+
size: {
|
|
1443
|
+
fontSize: measurements.font.size.xs,
|
|
1444
|
+
lineHeight: measurements.font.lineHeight.xs,
|
|
1445
|
+
paddingX: measurements.space.sm,
|
|
1446
|
+
paddingY: measurements.space.md,
|
|
1447
|
+
radius: measurements.size.radius.sm,
|
|
1448
|
+
zIndex: measurements.zIndex.tooltip,
|
|
1449
|
+
},
|
|
1450
|
+
color: {
|
|
1451
|
+
background: Theme.other.almostBlack, // or #111827
|
|
1452
|
+
text: Theme.text.inverse,
|
|
1453
|
+
shadow: Theme.shadow.tooltip,
|
|
1454
|
+
},
|
|
1455
|
+
},
|
|
1438
1456
|
};
|
|
1439
1457
|
};
|
|
1440
1458
|
export const Theme = createTheme('default');
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AppTheme, ThemeName } from '../../config';
|
|
2
|
+
import { FC, ReactNode } from 'react';
|
|
3
|
+
type TooltipPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
4
|
+
interface ITooltipProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
content: ReactNode;
|
|
7
|
+
position?: TooltipPosition;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
delay?: number;
|
|
10
|
+
theme?: AppTheme;
|
|
11
|
+
themeVariant?: ThemeName;
|
|
12
|
+
}
|
|
13
|
+
export declare const Tooltip: FC<ITooltipProps>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AppTheme } from 'config';
|
|
2
|
+
export declare const TooltipTriger: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
3
|
+
interface ITooltipRootProps {
|
|
4
|
+
theme: AppTheme;
|
|
5
|
+
config: any;
|
|
6
|
+
top: number;
|
|
7
|
+
left: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const TooltipRoot: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, ITooltipRootProps, never>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Tooltip } from './Tooltip';
|
|
@@ -89,6 +89,7 @@ export declare const createTheme: (theme?: ThemeName | AppTheme) => {
|
|
|
89
89
|
inner: string;
|
|
90
90
|
card: string;
|
|
91
91
|
modal: string;
|
|
92
|
+
tooltip: string;
|
|
92
93
|
};
|
|
93
94
|
divider: {
|
|
94
95
|
default: string;
|
|
@@ -98,6 +99,7 @@ export declare const createTheme: (theme?: ThemeName | AppTheme) => {
|
|
|
98
99
|
};
|
|
99
100
|
other: {
|
|
100
101
|
transparent: string;
|
|
102
|
+
almostBlack: "#1F2937";
|
|
101
103
|
};
|
|
102
104
|
};
|
|
103
105
|
export type ThemeConfig = ReturnType<typeof createTheme>;
|
|
@@ -228,6 +230,7 @@ export declare const measurements: {
|
|
|
228
230
|
readonly modal: 1001;
|
|
229
231
|
readonly sidepanel: 900;
|
|
230
232
|
readonly sidepanelOverlayer: 850;
|
|
233
|
+
readonly tooltip: 9999;
|
|
231
234
|
readonly uperModal: 1100;
|
|
232
235
|
};
|
|
233
236
|
};
|
|
@@ -1478,6 +1481,21 @@ export declare const createComponentsConfig: (theme?: ThemeName | AppTheme) => {
|
|
|
1478
1481
|
};
|
|
1479
1482
|
};
|
|
1480
1483
|
};
|
|
1484
|
+
tooltip: {
|
|
1485
|
+
size: {
|
|
1486
|
+
fontSize: 12;
|
|
1487
|
+
lineHeight: 16;
|
|
1488
|
+
paddingX: 8;
|
|
1489
|
+
paddingY: 12;
|
|
1490
|
+
radius: 8;
|
|
1491
|
+
zIndex: 9999;
|
|
1492
|
+
};
|
|
1493
|
+
color: {
|
|
1494
|
+
background: "#1F2937";
|
|
1495
|
+
text: "#FFFFFF";
|
|
1496
|
+
shadow: string;
|
|
1497
|
+
};
|
|
1498
|
+
};
|
|
1481
1499
|
};
|
|
1482
1500
|
export type ComponentsConfig = ReturnType<typeof createComponentsConfig>;
|
|
1483
1501
|
export declare const Theme: {
|
|
@@ -1570,6 +1588,7 @@ export declare const Theme: {
|
|
|
1570
1588
|
inner: string;
|
|
1571
1589
|
card: string;
|
|
1572
1590
|
modal: string;
|
|
1591
|
+
tooltip: string;
|
|
1573
1592
|
};
|
|
1574
1593
|
divider: {
|
|
1575
1594
|
default: string;
|
|
@@ -1579,6 +1598,7 @@ export declare const Theme: {
|
|
|
1579
1598
|
};
|
|
1580
1599
|
other: {
|
|
1581
1600
|
transparent: string;
|
|
1601
|
+
almostBlack: "#1F2937";
|
|
1582
1602
|
};
|
|
1583
1603
|
};
|
|
1584
1604
|
export declare const componentsConfig: {
|
|
@@ -2800,6 +2820,21 @@ export declare const componentsConfig: {
|
|
|
2800
2820
|
};
|
|
2801
2821
|
};
|
|
2802
2822
|
};
|
|
2823
|
+
tooltip: {
|
|
2824
|
+
size: {
|
|
2825
|
+
fontSize: 12;
|
|
2826
|
+
lineHeight: 16;
|
|
2827
|
+
paddingX: 8;
|
|
2828
|
+
paddingY: 12;
|
|
2829
|
+
radius: 8;
|
|
2830
|
+
zIndex: 9999;
|
|
2831
|
+
};
|
|
2832
|
+
color: {
|
|
2833
|
+
background: "#1F2937";
|
|
2834
|
+
text: "#FFFFFF";
|
|
2835
|
+
shadow: string;
|
|
2836
|
+
};
|
|
2837
|
+
};
|
|
2803
2838
|
};
|
|
2804
2839
|
export declare const createConfig: (theme?: ThemeName | AppTheme) => {
|
|
2805
2840
|
Theme: {
|
|
@@ -2892,6 +2927,7 @@ export declare const createConfig: (theme?: ThemeName | AppTheme) => {
|
|
|
2892
2927
|
inner: string;
|
|
2893
2928
|
card: string;
|
|
2894
2929
|
modal: string;
|
|
2930
|
+
tooltip: string;
|
|
2895
2931
|
};
|
|
2896
2932
|
divider: {
|
|
2897
2933
|
default: string;
|
|
@@ -2901,6 +2937,7 @@ export declare const createConfig: (theme?: ThemeName | AppTheme) => {
|
|
|
2901
2937
|
};
|
|
2902
2938
|
other: {
|
|
2903
2939
|
transparent: string;
|
|
2940
|
+
almostBlack: "#1F2937";
|
|
2904
2941
|
};
|
|
2905
2942
|
};
|
|
2906
2943
|
measurements: {
|
|
@@ -3030,6 +3067,7 @@ export declare const createConfig: (theme?: ThemeName | AppTheme) => {
|
|
|
3030
3067
|
readonly modal: 1001;
|
|
3031
3068
|
readonly sidepanel: 900;
|
|
3032
3069
|
readonly sidepanelOverlayer: 850;
|
|
3070
|
+
readonly tooltip: 9999;
|
|
3033
3071
|
readonly uperModal: 1100;
|
|
3034
3072
|
};
|
|
3035
3073
|
};
|
|
@@ -4266,5 +4304,20 @@ export declare const createConfig: (theme?: ThemeName | AppTheme) => {
|
|
|
4266
4304
|
};
|
|
4267
4305
|
};
|
|
4268
4306
|
};
|
|
4307
|
+
tooltip: {
|
|
4308
|
+
size: {
|
|
4309
|
+
fontSize: 12;
|
|
4310
|
+
lineHeight: 16;
|
|
4311
|
+
paddingX: 8;
|
|
4312
|
+
paddingY: 12;
|
|
4313
|
+
radius: 8;
|
|
4314
|
+
zIndex: 9999;
|
|
4315
|
+
};
|
|
4316
|
+
color: {
|
|
4317
|
+
background: "#1F2937";
|
|
4318
|
+
text: "#FFFFFF";
|
|
4319
|
+
shadow: string;
|
|
4320
|
+
};
|
|
4321
|
+
};
|
|
4269
4322
|
};
|
|
4270
4323
|
};
|
package/dist/types/index.d.ts
CHANGED