etudes 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Accordion.js +171 -205
- package/components/BurgerButton.js +40 -94
- package/components/Carousel.js +87 -123
- package/components/Collection.js +84 -120
- package/components/Counter.js +32 -63
- package/components/CoverImage.js +24 -68
- package/components/CoverVideo.js +25 -69
- package/components/DebugConsole.js +27 -79
- package/components/Dial.js +28 -65
- package/components/Dropdown.js +86 -98
- package/components/FlatSVG.js +22 -71
- package/components/Image.js +21 -50
- package/components/MasonryGrid.js +122 -257
- package/components/Panorama.js +48 -92
- package/components/PanoramaSlider.js +57 -113
- package/components/RangeSlider.js +125 -182
- package/components/RotatingGallery.js +28 -59
- package/components/SelectableButton.js +10 -54
- package/components/Slider.js +108 -159
- package/components/StepwiseSlider.js +124 -176
- package/components/SwipeContainer.js +30 -73
- package/components/TextField.js +12 -49
- package/components/Video.js +31 -61
- package/components/WithTooltip.js +117 -111
- package/components/index.js +24 -0
- package/hooks/index.js +17 -0
- package/hooks/useClickOutsideEffect.js +8 -38
- package/hooks/useDragEffect.js +20 -53
- package/hooks/useDragValueEffect.js +31 -81
- package/hooks/useImageSize.js +16 -38
- package/hooks/useInterval.js +9 -41
- package/hooks/useLoadImageEffect.js +15 -48
- package/hooks/useLoadVideoMetadataEffect.js +15 -48
- package/hooks/useMounted.js +5 -25
- package/hooks/usePrevious.js +4 -9
- package/hooks/useRect.js +9 -29
- package/hooks/useResizeEffect.js +10 -44
- package/hooks/useScrollPositionEffect.js +19 -50
- package/hooks/useSearchParamState.js +12 -34
- package/hooks/useSize.js +9 -29
- package/hooks/useTimeout.js +8 -38
- package/hooks/useVideoSize.js +16 -38
- package/hooks/useViewportSize.js +7 -27
- package/operators/Conditional.js +6 -11
- package/operators/Each.js +6 -14
- package/operators/ExtractChild.js +9 -36
- package/operators/ExtractChildren.js +7 -34
- package/operators/Repeat.js +4 -37
- package/operators/index.js +5 -0
- package/package.json +27 -41
- package/providers/ScrollPositionProvider.js +37 -60
- package/providers/index.js +1 -0
- package/utils/asClassNameDict.js +1 -5
- package/utils/asComponentDict.js +11 -16
- package/utils/asStyleDict.js +1 -5
- package/utils/cloneStyledElement.js +14 -61
- package/utils/index.js +5 -22
- package/utils/styles.js +5 -21
- package/components/Accordion.d.ts +0 -219
- package/components/Accordion.js.map +0 -1
- package/components/BurgerButton.d.ts +0 -34
- package/components/BurgerButton.js.map +0 -1
- package/components/Carousel.d.ts +0 -53
- package/components/Carousel.js.map +0 -1
- package/components/Collection.d.ts +0 -171
- package/components/Collection.js.map +0 -1
- package/components/Counter.d.ts +0 -11
- package/components/Counter.js.map +0 -1
- package/components/CoverImage.d.ts +0 -28
- package/components/CoverImage.js.map +0 -1
- package/components/CoverVideo.d.ts +0 -28
- package/components/CoverVideo.js.map +0 -1
- package/components/DebugConsole.d.ts +0 -15
- package/components/DebugConsole.js.map +0 -1
- package/components/Dial.d.ts +0 -79
- package/components/Dial.js.map +0 -1
- package/components/Dropdown.d.ts +0 -109
- package/components/Dropdown.js.map +0 -1
- package/components/FlatSVG.d.ts +0 -72
- package/components/FlatSVG.js.map +0 -1
- package/components/Image.d.ts +0 -144
- package/components/Image.js.map +0 -1
- package/components/MasonryGrid.d.ts +0 -29
- package/components/MasonryGrid.js.map +0 -1
- package/components/Panorama.d.ts +0 -77
- package/components/Panorama.js.map +0 -1
- package/components/PanoramaSlider.d.ts +0 -71
- package/components/PanoramaSlider.js.map +0 -1
- package/components/RangeSlider.d.ts +0 -34
- package/components/RangeSlider.js.map +0 -1
- package/components/RotatingGallery.d.ts +0 -91
- package/components/RotatingGallery.js.map +0 -1
- package/components/SelectableButton.d.ts +0 -19
- package/components/SelectableButton.js.map +0 -1
- package/components/Slider.d.ts +0 -160
- package/components/Slider.js.map +0 -1
- package/components/StepwiseSlider.d.ts +0 -215
- package/components/StepwiseSlider.js.map +0 -1
- package/components/SwipeContainer.d.ts +0 -21
- package/components/SwipeContainer.js.map +0 -1
- package/components/TextField.d.ts +0 -21
- package/components/TextField.js.map +0 -1
- package/components/Video.d.ts +0 -38
- package/components/Video.js.map +0 -1
- package/components/WithTooltip.d.ts +0 -32
- package/components/WithTooltip.js.map +0 -1
- package/hooks/useClickOutsideEffect.d.ts +0 -2
- package/hooks/useClickOutsideEffect.js.map +0 -1
- package/hooks/useDragEffect.d.ts +0 -48
- package/hooks/useDragEffect.js.map +0 -1
- package/hooks/useDragValueEffect.d.ts +0 -56
- package/hooks/useDragValueEffect.js.map +0 -1
- package/hooks/useImageSize.d.ts +0 -21
- package/hooks/useImageSize.js.map +0 -1
- package/hooks/useInterval.d.ts +0 -18
- package/hooks/useInterval.js.map +0 -1
- package/hooks/useLoadImageEffect.d.ts +0 -43
- package/hooks/useLoadImageEffect.js.map +0 -1
- package/hooks/useLoadVideoMetadataEffect.d.ts +0 -35
- package/hooks/useLoadVideoMetadataEffect.js.map +0 -1
- package/hooks/useMounted.d.ts +0 -1
- package/hooks/useMounted.js.map +0 -1
- package/hooks/usePrevious.d.ts +0 -19
- package/hooks/usePrevious.js.map +0 -1
- package/hooks/useRect.d.ts +0 -11
- package/hooks/useRect.js.map +0 -1
- package/hooks/useResizeEffect.d.ts +0 -17
- package/hooks/useResizeEffect.js.map +0 -1
- package/hooks/useScrollPositionEffect.d.ts +0 -13
- package/hooks/useScrollPositionEffect.js.map +0 -1
- package/hooks/useSearchParamState.d.ts +0 -34
- package/hooks/useSearchParamState.js.map +0 -1
- package/hooks/useSize.d.ts +0 -10
- package/hooks/useSize.js.map +0 -1
- package/hooks/useTimeout.d.ts +0 -10
- package/hooks/useTimeout.js.map +0 -1
- package/hooks/useVideoSize.d.ts +0 -21
- package/hooks/useVideoSize.js.map +0 -1
- package/hooks/useViewportSize.d.ts +0 -7
- package/hooks/useViewportSize.js.map +0 -1
- package/operators/Conditional.d.ts +0 -5
- package/operators/Conditional.js.map +0 -1
- package/operators/Each.d.ts +0 -7
- package/operators/Each.js.map +0 -1
- package/operators/ExtractChild.d.ts +0 -8
- package/operators/ExtractChild.js.map +0 -1
- package/operators/ExtractChildren.d.ts +0 -6
- package/operators/ExtractChildren.js.map +0 -1
- package/operators/Repeat.d.ts +0 -11
- package/operators/Repeat.js.map +0 -1
- package/providers/ScrollPositionProvider.d.ts +0 -15
- package/providers/ScrollPositionProvider.js.map +0 -1
- package/utils/asClassNameDict.d.ts +0 -3
- package/utils/asClassNameDict.js.map +0 -1
- package/utils/asComponentDict.d.ts +0 -5
- package/utils/asComponentDict.js.map +0 -1
- package/utils/asStyleDict.d.ts +0 -4
- package/utils/asStyleDict.js.map +0 -1
- package/utils/cloneStyledElement.d.ts +0 -18
- package/utils/cloneStyledElement.js.map +0 -1
- package/utils/index.d.ts +0 -5
- package/utils/index.js.map +0 -1
- package/utils/styles.d.ts +0 -2
- package/utils/styles.js.map +0 -1
package/components/TextField.js
CHANGED
|
@@ -1,57 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.TextField = void 0;
|
|
26
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
|
-
var react_1 = require("react");
|
|
28
|
-
var usePrevious_1 = require("../hooks/usePrevious");
|
|
29
|
-
exports.TextField = (0, react_1.forwardRef)(function (_a, ref) {
|
|
30
|
-
var _b = _a.emptyValue, emptyValue = _b === void 0 ? '' : _b, _c = _a.isDisabled, isDisabled = _c === void 0 ? false : _c, placeholder = _a.placeholder, externalValue = _a.value, formatter = _a.formatter, onFocus = _a.onFocus, onUnfocus = _a.onUnfocus, onValueChange = _a.onValueChange, props = __rest(_a, ["emptyValue", "isDisabled", "placeholder", "value", "formatter", "onFocus", "onUnfocus", "onValueChange"]);
|
|
31
|
-
var handleValueChange = function (newValue) {
|
|
32
|
-
var _a;
|
|
33
|
-
var formatted = (newValue !== emptyValue) ? ((_a = formatter === null || formatter === void 0 ? void 0 : formatter(value, newValue)) !== null && _a !== void 0 ? _a : newValue) : emptyValue;
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect } from 'react';
|
|
3
|
+
import { usePrevious } from '../hooks/usePrevious.js';
|
|
4
|
+
export const TextField = forwardRef(({ emptyValue = '', isDisabled = false, placeholder, value: externalValue, formatter, onFocus, onUnfocus, onValueChange, ...props }, ref) => {
|
|
5
|
+
const handleValueChange = (newValue) => {
|
|
6
|
+
const formatted = (newValue !== emptyValue) ? (formatter?.(value, newValue) ?? newValue) : emptyValue;
|
|
34
7
|
if (formatted === value)
|
|
35
8
|
return;
|
|
36
|
-
onValueChange
|
|
9
|
+
onValueChange?.(formatted);
|
|
37
10
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
11
|
+
const value = externalValue ?? emptyValue;
|
|
12
|
+
const prevValue = usePrevious(value);
|
|
13
|
+
useEffect(() => {
|
|
41
14
|
if (prevValue === undefined)
|
|
42
15
|
return;
|
|
43
16
|
handleValueChange(value);
|
|
44
17
|
}, [value]);
|
|
45
|
-
return ((
|
|
46
|
-
var target = _a.target;
|
|
47
|
-
return onUnfocus === null || onUnfocus === void 0 ? void 0 : onUnfocus(target.value);
|
|
48
|
-
}, onChange: function (_a) {
|
|
49
|
-
var target = _a.target;
|
|
50
|
-
return handleValueChange(target.value);
|
|
51
|
-
}, onFocus: function (_a) {
|
|
52
|
-
var target = _a.target;
|
|
53
|
-
return onFocus === null || onFocus === void 0 ? void 0 : onFocus(target.value);
|
|
54
|
-
} })));
|
|
18
|
+
return (_jsx("input", { ...props, ref: ref, "data-component": 'text-field', disabled: isDisabled, placeholder: placeholder, type: 'text', value: value, onBlur: ({ target }) => onUnfocus?.(target.value), onChange: ({ target }) => handleValueChange(target.value), onFocus: ({ target }) => onFocus?.(target.value) }));
|
|
55
19
|
});
|
|
56
|
-
Object.defineProperty(
|
|
57
|
-
//# sourceMappingURL=TextField.js.map
|
|
20
|
+
Object.defineProperty(TextField, 'displayName', { value: 'TextField', writable: false });
|
package/components/Video.js
CHANGED
|
@@ -1,44 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Video = void 0;
|
|
26
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
|
-
var react_1 = require("react");
|
|
28
|
-
var useVideoSize_1 = require("../hooks/useVideoSize");
|
|
29
|
-
exports.Video = (0, react_1.forwardRef)(function (_a, ref) {
|
|
30
|
-
var _b;
|
|
31
|
-
var _c = _a.autoLoop, autoLoop = _c === void 0 ? true : _c, _d = _a.autoPlay, autoPlay = _d === void 0 ? true : _d, _e = _a.hasControls, hasControls = _e === void 0 ? false : _e, _f = _a.isMuted, isMuted = _f === void 0 ? true : _f, _g = _a.playsInline, playsInline = _g === void 0 ? true : _g, posterSrc = _a.posterSrc, src = _a.src, onCanPlay = _a.onCanPlay, onEnd = _a.onEnd, onFullscreenChange = _a.onFullscreenChange, onLoadMetadata = _a.onLoadMetadata, onLoadMetadataComplete = _a.onLoadMetadataComplete, onLoadMetadataError = _a.onLoadMetadataError, onPause = _a.onPause, onPlay = _a.onPlay, onSizeChange = _a.onSizeChange, props = __rest(_a, ["autoLoop", "autoPlay", "hasControls", "isMuted", "playsInline", "posterSrc", "src", "onCanPlay", "onEnd", "onFullscreenChange", "onLoadMetadata", "onLoadMetadataComplete", "onLoadMetadataError", "onPause", "onPlay", "onSizeChange"]);
|
|
32
|
-
var localRef = (0, react_1.useRef)(null);
|
|
33
|
-
var videoRef = (_b = ref) !== null && _b !== void 0 ? _b : localRef;
|
|
34
|
-
var size = (0, useVideoSize_1.useVideoSize)({
|
|
35
|
-
src: src,
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useRef } from 'react';
|
|
3
|
+
import { useVideoSize } from '../hooks/useVideoSize.js';
|
|
4
|
+
export const Video = forwardRef(({ autoLoop = true, autoPlay = true, hasControls = false, isMuted = true, playsInline = true, posterSrc, src, onCanPlay, onEnd, onFullscreenChange, onLoadMetadata, onLoadMetadataComplete, onLoadMetadataError, onPause, onPlay, onSizeChange, ...props }, ref) => {
|
|
5
|
+
const localRef = useRef(null);
|
|
6
|
+
const videoRef = ref ?? localRef;
|
|
7
|
+
const size = useVideoSize({
|
|
8
|
+
src,
|
|
36
9
|
}, {
|
|
37
10
|
onLoadStart: onLoadMetadata,
|
|
38
11
|
onLoadComplete: onLoadMetadataComplete,
|
|
39
12
|
onLoadError: onLoadMetadataError,
|
|
40
13
|
});
|
|
41
|
-
|
|
14
|
+
useEffect(() => {
|
|
42
15
|
if (!videoRef.current)
|
|
43
16
|
return;
|
|
44
17
|
videoRef.current.muted = isMuted;
|
|
@@ -46,50 +19,47 @@ exports.Video = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
46
19
|
videoRef.current.addEventListener('webkitfullscreenchange', fullscreenChangeHandler);
|
|
47
20
|
videoRef.current.addEventListener('mozfullscreenchange', fullscreenChangeHandler);
|
|
48
21
|
videoRef.current.addEventListener('fullscreenchange', fullscreenChangeHandler);
|
|
49
|
-
return
|
|
50
|
-
var _a, _b, _c;
|
|
22
|
+
return () => {
|
|
51
23
|
pause();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
24
|
+
videoRef.current?.removeEventListener('webkitfullscreenchange', fullscreenChangeHandler);
|
|
25
|
+
videoRef.current?.removeEventListener('mozfullscreenchange', fullscreenChangeHandler);
|
|
26
|
+
videoRef.current?.removeEventListener('fullscreenchange', fullscreenChangeHandler);
|
|
55
27
|
};
|
|
56
28
|
}, [src]);
|
|
57
|
-
|
|
58
|
-
onSizeChange
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
onSizeChange?.(size);
|
|
59
31
|
}, [size]);
|
|
60
|
-
|
|
61
|
-
|
|
32
|
+
const fullscreenChangeHandler = (event) => {
|
|
33
|
+
const isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
|
|
62
34
|
if (isFullscreen === undefined)
|
|
63
35
|
return;
|
|
64
|
-
onFullscreenChange
|
|
36
|
+
onFullscreenChange?.(isFullscreen);
|
|
65
37
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (autoPlay && ((_b = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : false)) {
|
|
38
|
+
const canPlayHandler = event => {
|
|
39
|
+
if (autoPlay && (videoRef.current?.paused ?? false)) {
|
|
69
40
|
play();
|
|
70
41
|
}
|
|
71
|
-
onCanPlay
|
|
42
|
+
onCanPlay?.();
|
|
72
43
|
};
|
|
73
|
-
|
|
74
|
-
onPlay
|
|
44
|
+
const playHandler = event => {
|
|
45
|
+
onPlay?.();
|
|
75
46
|
};
|
|
76
|
-
|
|
77
|
-
onPause
|
|
47
|
+
const pauseHandler = event => {
|
|
48
|
+
onPause?.();
|
|
78
49
|
};
|
|
79
|
-
|
|
80
|
-
onEnd
|
|
50
|
+
const endHandler = event => {
|
|
51
|
+
onEnd?.();
|
|
81
52
|
};
|
|
82
|
-
|
|
53
|
+
const play = () => {
|
|
83
54
|
if (!videoRef.current)
|
|
84
55
|
return;
|
|
85
56
|
videoRef.current.play();
|
|
86
57
|
};
|
|
87
|
-
|
|
58
|
+
const pause = () => {
|
|
88
59
|
if (!videoRef.current)
|
|
89
60
|
return;
|
|
90
61
|
videoRef.current.pause();
|
|
91
62
|
};
|
|
92
|
-
return ((
|
|
63
|
+
return (_jsx("video", { ...props, ref: ref, autoPlay: autoPlay, controls: hasControls, "data-component": 'video', loop: autoLoop, muted: isMuted, playsInline: playsInline, poster: posterSrc, onCanPlay: canPlayHandler, onEnded: endHandler, onPause: pauseHandler, onPlay: playHandler, children: _jsx("source", { src: src }) }));
|
|
93
64
|
});
|
|
94
|
-
Object.defineProperty(
|
|
95
|
-
//# sourceMappingURL=Video.js.map
|
|
65
|
+
Object.defineProperty(Video, 'displayName', { value: 'Video', writable: false });
|
|
@@ -1,55 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WithTooltip = WithTooltip;
|
|
18
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
-
var clsx_1 = __importDefault(require("clsx"));
|
|
20
|
-
var react_1 = require("react");
|
|
21
|
-
var spase_1 = require("spase");
|
|
22
|
-
var useRect_1 = require("../hooks/useRect");
|
|
23
|
-
var useViewportSize_1 = require("../hooks/useViewportSize");
|
|
24
|
-
var ExtractChild_1 = require("../operators/ExtractChild");
|
|
25
|
-
var utils_1 = require("../utils");
|
|
26
|
-
function WithTooltip(_a) {
|
|
27
|
-
var children = _a.children, className = _a.className, style = _a.style, _b = _a.arrowHeight, arrowHeight = _b === void 0 ? 8 : _b, _c = _a.backgroundColor, backgroundColor = _c === void 0 ? '#000' : _c, _d = _a.gap, gap = _d === void 0 ? 5 : _d, hint = _a.hint, _e = _a.maxTextWidth, maxTextWidth = _e === void 0 ? 200 : _e, _f = _a.threshold, threshold = _f === void 0 ? 100 : _f;
|
|
28
|
-
var createDialog = function () {
|
|
29
|
-
var dialog = document.createElement('div');
|
|
30
|
-
var dialogStyle = (0, utils_1.styles)(style, fixedStyles.dialog);
|
|
31
|
-
dialog.className = (0, clsx_1.default)(className);
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { Rect, Size } from 'spase';
|
|
5
|
+
import { useRect } from '../hooks/useRect.js';
|
|
6
|
+
import { useViewportSize } from '../hooks/useViewportSize.js';
|
|
7
|
+
import { ExtractChild } from '../operators/ExtractChild.js';
|
|
8
|
+
import { asStyleDict, styles } from '../utils/index.js';
|
|
9
|
+
export function WithTooltip({ children, className, style, arrowHeight = 8, backgroundColor = '#000', gap = 5, hint, maxTextWidth = 200, threshold = 100, }) {
|
|
10
|
+
const createDialog = () => {
|
|
11
|
+
const dialog = document.createElement('div');
|
|
12
|
+
const dialogStyle = styles(style, fixedStyles.dialog);
|
|
13
|
+
dialog.className = clsx(className);
|
|
32
14
|
dialog.setAttribute('data-component', 'tool-tip');
|
|
33
|
-
Object.keys(dialogStyle).forEach(
|
|
34
|
-
|
|
35
|
-
Object.keys(fixedStyles.arrow).forEach(
|
|
36
|
-
|
|
15
|
+
Object.keys(dialogStyle).forEach(rule => dialog.style[rule] = dialogStyle[rule]);
|
|
16
|
+
const arrow = document.createElement('div');
|
|
17
|
+
Object.keys(fixedStyles.arrow).forEach(rule => arrow.style[rule] = fixedStyles.arrow[rule]);
|
|
18
|
+
const content = document.createElement('div');
|
|
37
19
|
content.innerText = hint;
|
|
38
|
-
Object.keys(fixedStyles.content).forEach(
|
|
20
|
+
Object.keys(fixedStyles.content).forEach(rule => content.style[rule] = fixedStyles.content[rule]);
|
|
39
21
|
dialog.appendChild(arrow);
|
|
40
22
|
dialog.appendChild(content);
|
|
41
23
|
return dialog;
|
|
42
24
|
};
|
|
43
|
-
|
|
25
|
+
const computeAlignment = () => {
|
|
44
26
|
if (!rootRef.current)
|
|
45
27
|
return 'bc';
|
|
46
|
-
|
|
47
|
-
|
|
28
|
+
const vrect = Rect.fromViewport();
|
|
29
|
+
const irect = Rect.intersecting(rootRef.current);
|
|
48
30
|
if (irect) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
const leftBound = irect.left - vrect.left < threshold;
|
|
32
|
+
const rightBound = vrect.right - irect.right < threshold;
|
|
33
|
+
const topBound = irect.top - vrect.top < threshold;
|
|
34
|
+
const bottomBound = vrect.bottom - irect.bottom < threshold;
|
|
53
35
|
if (leftBound && topBound)
|
|
54
36
|
return 'br';
|
|
55
37
|
if (leftBound && bottomBound)
|
|
@@ -67,11 +49,11 @@ function WithTooltip(_a) {
|
|
|
67
49
|
}
|
|
68
50
|
return 'bc';
|
|
69
51
|
};
|
|
70
|
-
|
|
52
|
+
const computeTextSize = () => {
|
|
71
53
|
if (!dialogRef.current)
|
|
72
|
-
return new
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
return new Size();
|
|
55
|
+
const computedStyle = window.getComputedStyle(dialogRef.current);
|
|
56
|
+
const div = document.createElement('div');
|
|
75
57
|
div.innerText = hint;
|
|
76
58
|
div.style.fontFamily = computedStyle.getPropertyValue('font-family');
|
|
77
59
|
div.style.fontSize = computedStyle.getPropertyValue('font-size');
|
|
@@ -85,73 +67,71 @@ function WithTooltip(_a) {
|
|
|
85
67
|
div.style.whiteSpace = 'pre';
|
|
86
68
|
document.body.appendChild(div);
|
|
87
69
|
// Add 1px as buffer to mitigate precision discrepancies.
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
const width = div.clientWidth + 1;
|
|
71
|
+
const height = div.clientHeight + 1;
|
|
90
72
|
document.body.removeChild(div);
|
|
91
|
-
return new
|
|
73
|
+
return new Size([width, height]);
|
|
92
74
|
};
|
|
93
|
-
|
|
75
|
+
const mouseEnterHandler = (event) => {
|
|
94
76
|
if (!dialogRef.current)
|
|
95
77
|
return;
|
|
96
78
|
dialogRef.current.style.opacity = '1';
|
|
97
79
|
};
|
|
98
|
-
|
|
80
|
+
const mouseLeaveHandler = (event) => {
|
|
99
81
|
if (!dialogRef.current)
|
|
100
82
|
return;
|
|
101
83
|
dialogRef.current.style.opacity = '0';
|
|
102
84
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
(_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.appendChild(dialogNode);
|
|
85
|
+
const rootRef = useRef(null);
|
|
86
|
+
const dialogRef = useRef();
|
|
87
|
+
const rect = useRect(rootRef);
|
|
88
|
+
const viewportSize = useViewportSize();
|
|
89
|
+
const alignment = computeAlignment();
|
|
90
|
+
const textSize = computeTextSize();
|
|
91
|
+
const fixedStyles = getFixedStyles({ rect, arrowHeight, alignment, backgroundColor, maxTextWidth, textSize, gap });
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const dialogNode = createDialog();
|
|
94
|
+
rootRef.current?.appendChild(dialogNode);
|
|
114
95
|
dialogRef.current = dialogNode;
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
(_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.removeChild(dialogNode);
|
|
96
|
+
return () => {
|
|
97
|
+
rootRef.current?.removeChild(dialogNode);
|
|
118
98
|
};
|
|
119
99
|
}, [rect, viewportSize]);
|
|
120
|
-
return ((
|
|
100
|
+
return (_jsx(ExtractChild, { ref: rootRef, onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, children: children }));
|
|
121
101
|
}
|
|
122
102
|
function makeDisplacementStyle(alignment, arrowHeight, gap) {
|
|
123
103
|
switch (alignment) {
|
|
124
104
|
case 'tl': return {
|
|
125
|
-
top:
|
|
126
|
-
left:
|
|
105
|
+
top: `${-arrowHeight}px`,
|
|
106
|
+
left: `calc(50% + ${arrowHeight * 2.5}px)`,
|
|
127
107
|
};
|
|
128
108
|
case 'tc': return {
|
|
129
|
-
top:
|
|
109
|
+
top: `${-arrowHeight}px`,
|
|
130
110
|
left: '50%',
|
|
131
111
|
};
|
|
132
112
|
case 'tr': return {
|
|
133
|
-
top:
|
|
134
|
-
right:
|
|
113
|
+
top: `${-arrowHeight}px`,
|
|
114
|
+
right: `calc(50% + ${arrowHeight * 2.5}px)`,
|
|
135
115
|
};
|
|
136
116
|
case 'cl': return {
|
|
137
117
|
top: '50%',
|
|
138
|
-
left:
|
|
118
|
+
left: `${-arrowHeight}px`,
|
|
139
119
|
};
|
|
140
120
|
case 'cr': return {
|
|
141
121
|
top: '50%',
|
|
142
|
-
right:
|
|
122
|
+
right: `${-arrowHeight}px`,
|
|
143
123
|
};
|
|
144
124
|
case 'bl': return {
|
|
145
|
-
bottom:
|
|
146
|
-
left:
|
|
125
|
+
bottom: `${-arrowHeight}px`,
|
|
126
|
+
left: `calc(50% + ${arrowHeight * 2.5}px)`,
|
|
147
127
|
};
|
|
148
128
|
case 'bc': return {
|
|
149
|
-
bottom:
|
|
129
|
+
bottom: `${-arrowHeight}px`,
|
|
150
130
|
left: '50%',
|
|
151
131
|
};
|
|
152
132
|
case 'br': return {
|
|
153
|
-
bottom:
|
|
154
|
-
right:
|
|
133
|
+
bottom: `${-arrowHeight}px`,
|
|
134
|
+
right: `calc(50% + ${arrowHeight * 2.5}px)`,
|
|
155
135
|
};
|
|
156
136
|
default: return {};
|
|
157
137
|
}
|
|
@@ -159,28 +139,28 @@ function makeDisplacementStyle(alignment, arrowHeight, gap) {
|
|
|
159
139
|
function makeContentPositionStyle(alignment, arrowHeight, gap) {
|
|
160
140
|
switch (alignment) {
|
|
161
141
|
case 'tl': return {
|
|
162
|
-
transform:
|
|
142
|
+
transform: `translate3d(calc(-100% - ${gap}px), calc(-100% - ${gap}px), 0)`,
|
|
163
143
|
};
|
|
164
144
|
case 'tc': return {
|
|
165
|
-
transform:
|
|
145
|
+
transform: `translate3d(-50%, calc(-100% - ${gap}px), 0)`,
|
|
166
146
|
};
|
|
167
147
|
case 'tr': return {
|
|
168
|
-
transform:
|
|
148
|
+
transform: `translate3d(calc(100% + ${gap}px), calc(-100% - ${gap}px), 0)`,
|
|
169
149
|
};
|
|
170
150
|
case 'cl': return {
|
|
171
|
-
transform:
|
|
151
|
+
transform: `translate3d(calc(-100% - ${gap}px), -50%, 0)`,
|
|
172
152
|
};
|
|
173
153
|
case 'cr': return {
|
|
174
|
-
transform:
|
|
154
|
+
transform: `translate3d(calc(100% + ${gap}px), -50%, 0)`,
|
|
175
155
|
};
|
|
176
156
|
case 'bl': return {
|
|
177
|
-
transform:
|
|
157
|
+
transform: `translate3d(calc(-100% - ${gap}px), calc(100% + ${gap}px), 0)`,
|
|
178
158
|
};
|
|
179
159
|
case 'bc': return {
|
|
180
|
-
transform:
|
|
160
|
+
transform: `translate3d(-50%, calc(100% + ${gap}px), 0)`,
|
|
181
161
|
};
|
|
182
162
|
case 'br': return {
|
|
183
|
-
transform:
|
|
163
|
+
transform: `translate3d(calc(100% + ${gap}px), calc(100% + ${gap}px), 0)`,
|
|
184
164
|
};
|
|
185
165
|
default: return {};
|
|
186
166
|
}
|
|
@@ -188,57 +168,83 @@ function makeContentPositionStyle(alignment, arrowHeight, gap) {
|
|
|
188
168
|
function makeArrowPositionStyle(alignment, arrowHeight, gap, color) {
|
|
189
169
|
switch (alignment) {
|
|
190
170
|
case 'tl': return {
|
|
191
|
-
borderColor:
|
|
192
|
-
transform:
|
|
171
|
+
borderColor: `${color} transparent transparent transparent`,
|
|
172
|
+
transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% - ${gap}px), 0)`,
|
|
193
173
|
};
|
|
194
174
|
case 'tc': return {
|
|
195
|
-
borderColor:
|
|
196
|
-
transform:
|
|
175
|
+
borderColor: `${color} transparent transparent transparent`,
|
|
176
|
+
transform: `translate3d(-50%, calc(0% - ${gap}px), 0)`,
|
|
197
177
|
};
|
|
198
178
|
case 'tr': return {
|
|
199
|
-
borderColor:
|
|
200
|
-
transform:
|
|
179
|
+
borderColor: `${color} transparent transparent transparent`,
|
|
180
|
+
transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% - ${gap}px), 0)`,
|
|
201
181
|
};
|
|
202
182
|
case 'cl': return {
|
|
203
|
-
borderColor:
|
|
204
|
-
transform:
|
|
183
|
+
borderColor: `transparent transparent transparent ${color}`,
|
|
184
|
+
transform: `translate3d(calc(0% - ${gap}px), -50%, 0)`,
|
|
205
185
|
};
|
|
206
186
|
case 'cr': return {
|
|
207
|
-
borderColor:
|
|
208
|
-
transform:
|
|
187
|
+
borderColor: `transparent ${color} transparent transparent`,
|
|
188
|
+
transform: `translate3d(calc(0% + ${gap}px), -50%, 0)`,
|
|
209
189
|
};
|
|
210
190
|
case 'bl': return {
|
|
211
|
-
borderColor:
|
|
212
|
-
transform:
|
|
191
|
+
borderColor: `transparent transparent ${color} transparent`,
|
|
192
|
+
transform: `translate3d(calc(0% - ${gap}px - ${arrowHeight * 3}px), calc(0% + ${gap}px), 0)`,
|
|
213
193
|
};
|
|
214
194
|
case 'bc': return {
|
|
215
|
-
borderColor:
|
|
216
|
-
transform:
|
|
195
|
+
borderColor: `transparent transparent ${color} transparent`,
|
|
196
|
+
transform: `translate3d(-50%, calc(0% + ${gap}px), 0)`,
|
|
217
197
|
};
|
|
218
198
|
case 'br': return {
|
|
219
|
-
borderColor:
|
|
220
|
-
transform:
|
|
199
|
+
borderColor: `transparent transparent ${color} transparent`,
|
|
200
|
+
transform: `translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% + ${gap}px), 0)`,
|
|
221
201
|
};
|
|
222
202
|
default: return {};
|
|
223
203
|
}
|
|
224
204
|
}
|
|
225
|
-
function getFixedStyles(
|
|
226
|
-
|
|
227
|
-
return (0, utils_1.asStyleDict)({
|
|
205
|
+
function getFixedStyles({ rect = new Rect(), arrowHeight = 0, alignment = 'tl', backgroundColor = '', maxTextWidth = 0, textSize = new Size(), gap = 0 }) {
|
|
206
|
+
return asStyleDict({
|
|
228
207
|
dialog: {
|
|
229
208
|
background: 'none',
|
|
230
209
|
boxSizing: 'border-box',
|
|
231
|
-
height:
|
|
210
|
+
height: `${rect.size.height}px`,
|
|
232
211
|
left: '0',
|
|
233
212
|
margin: '0',
|
|
234
213
|
opacity: '0',
|
|
235
214
|
position: 'absolute',
|
|
236
215
|
top: '0',
|
|
237
|
-
width:
|
|
216
|
+
width: `${rect.size.width}px`,
|
|
238
217
|
zIndex: '10000',
|
|
239
218
|
},
|
|
240
|
-
arrow:
|
|
241
|
-
|
|
219
|
+
arrow: {
|
|
220
|
+
borderStyle: 'solid',
|
|
221
|
+
borderWidth: `${arrowHeight}px`,
|
|
222
|
+
height: '0',
|
|
223
|
+
pointerEvents: 'none',
|
|
224
|
+
position: 'absolute',
|
|
225
|
+
width: '0',
|
|
226
|
+
...makeDisplacementStyle(alignment, arrowHeight, gap),
|
|
227
|
+
...makeArrowPositionStyle(alignment, arrowHeight, gap, backgroundColor),
|
|
228
|
+
},
|
|
229
|
+
content: {
|
|
230
|
+
background: backgroundColor,
|
|
231
|
+
boxSizing: 'content-box',
|
|
232
|
+
color: 'inherit',
|
|
233
|
+
fontFamily: 'inherit',
|
|
234
|
+
fontSize: 'inherit',
|
|
235
|
+
fontWeight: 'inherit',
|
|
236
|
+
letterSpacing: 'inherit',
|
|
237
|
+
lineHeight: 'inherit',
|
|
238
|
+
maxWidth: `${maxTextWidth}px`,
|
|
239
|
+
overflow: 'hidden',
|
|
240
|
+
padding: 'inherit',
|
|
241
|
+
pointerEvents: 'none',
|
|
242
|
+
position: 'absolute',
|
|
243
|
+
textAlign: 'inherit',
|
|
244
|
+
transition: 'inherit',
|
|
245
|
+
width: textSize.width > 0 ? `${textSize.width}px` : 'auto',
|
|
246
|
+
...makeDisplacementStyle(alignment, arrowHeight, gap),
|
|
247
|
+
...makeContentPositionStyle(alignment, arrowHeight, gap),
|
|
248
|
+
},
|
|
242
249
|
});
|
|
243
250
|
}
|
|
244
|
-
//# sourceMappingURL=WithTooltip.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './Accordion.js';
|
|
2
|
+
export * from './BurgerButton.js';
|
|
3
|
+
export * from './Carousel.js';
|
|
4
|
+
export * from './Collection.js';
|
|
5
|
+
export * from './Counter.js';
|
|
6
|
+
export * from './CoverImage.js';
|
|
7
|
+
export * from './CoverVideo.js';
|
|
8
|
+
export * from './DebugConsole.js';
|
|
9
|
+
export * from './Dial.js';
|
|
10
|
+
export * from './Dropdown.js';
|
|
11
|
+
export * from './FlatSVG.js';
|
|
12
|
+
export * from './Image.js';
|
|
13
|
+
export * from './MasonryGrid.js';
|
|
14
|
+
export * from './Panorama.js';
|
|
15
|
+
export * from './PanoramaSlider.js';
|
|
16
|
+
export * from './RangeSlider.js';
|
|
17
|
+
export * from './RotatingGallery.js';
|
|
18
|
+
export * from './SelectableButton.js';
|
|
19
|
+
export * from './Slider.js';
|
|
20
|
+
export * from './StepwiseSlider.js';
|
|
21
|
+
export * from './SwipeContainer.js';
|
|
22
|
+
export * from './TextField.js';
|
|
23
|
+
export * from './Video.js';
|
|
24
|
+
export * from './WithTooltip.js';
|
package/hooks/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './useClickOutsideEffect.js';
|
|
2
|
+
export * from './useDragEffect.js';
|
|
3
|
+
export * from './useDragValueEffect.js';
|
|
4
|
+
export * from './useImageSize.js';
|
|
5
|
+
export * from './useInterval.js';
|
|
6
|
+
export * from './useLoadImageEffect.js';
|
|
7
|
+
export * from './useLoadVideoMetadataEffect.js';
|
|
8
|
+
export * from './useMounted.js';
|
|
9
|
+
export * from './usePrevious.js';
|
|
10
|
+
export * from './useRect.js';
|
|
11
|
+
export * from './useResizeEffect.js';
|
|
12
|
+
export * from './useScrollPositionEffect.js';
|
|
13
|
+
export * from './useSearchParamState.js';
|
|
14
|
+
export * from './useSize.js';
|
|
15
|
+
export * from './useTimeout.js';
|
|
16
|
+
export * from './useVideoSize.js';
|
|
17
|
+
export * from './useViewportSize.js';
|