@dr.pogodin/react-utils 1.47.0-alpha.7 → 1.47.0-alpha.8
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/build/development/client/index.js +1 -1
- package/build/development/client/index.js.map +1 -1
- package/build/development/index.js +1 -11
- package/build/development/index.js.map +1 -1
- package/build/development/server/index.js +3 -6
- package/build/development/server/index.js.map +1 -1
- package/build/development/server/utils/index.js +1 -1
- package/build/development/server/utils/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +1 -1
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +1 -1
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +1 -1
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +1 -1
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +1 -1
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +1 -1
- package/build/development/shared/components/TextArea/index.js.map +1 -1
- package/build/development/shared/components/Throbber/index.js +1 -1
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +1 -1
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/development/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js +1 -1
- package/build/development/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/development/shared/components/selectors/Switch/index.js +1 -1
- package/build/development/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/production/client/index.js +1 -1
- package/build/production/client/index.js.map +1 -1
- package/build/production/index.js +2 -6
- package/build/production/index.js.map +1 -1
- package/build/production/server/index.js +3 -3
- package/build/production/server/index.js.map +1 -1
- package/build/production/server/utils/index.js +1 -1
- package/build/production/server/utils/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +1 -1
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +1 -1
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +1 -1
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +1 -1
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +1 -1
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +1 -1
- package/build/production/shared/components/TextArea/index.js.map +1 -1
- package/build/production/shared/components/Throbber/index.js +1 -1
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/index.js +1 -1
- package/build/production/shared/components/WithTooltip/index.js.map +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js +1 -1
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/production/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js +1 -1
- package/build/production/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/production/shared/components/selectors/Switch/index.js +1 -1
- package/build/production/shared/components/selectors/Switch/index.js.map +1 -1
- package/build/types-code/client/index.d.ts +1 -1
- package/build/types-code/index.d.ts +0 -5
- package/build/types-code/server/index.d.ts +4 -9
- package/build/types-code/server/utils/index.d.ts +1 -1
- package/build/web/client/index.js +1 -1
- package/build/web/client/index.js.map +1 -1
- package/build/web/index.js +1 -11
- package/build/web/index.js.map +1 -1
- package/build/web/server/index.js +3 -6
- package/build/web/server/index.js.map +1 -1
- package/build/web/server/utils/index.js +1 -1
- package/build/web/server/utils/index.js.map +1 -1
- package/build/web/shared/components/Button/index.js +1 -1
- package/build/web/shared/components/Button/index.js.map +1 -1
- package/build/web/shared/components/Checkbox/index.js +1 -1
- package/build/web/shared/components/Checkbox/index.js.map +1 -1
- package/build/web/shared/components/Input/index.js +1 -1
- package/build/web/shared/components/Input/index.js.map +1 -1
- package/build/web/shared/components/Modal/index.js +1 -1
- package/build/web/shared/components/Modal/index.js.map +1 -1
- package/build/web/shared/components/PageLayout/index.js +1 -1
- package/build/web/shared/components/PageLayout/index.js.map +1 -1
- package/build/web/shared/components/TextArea/index.js +1 -1
- package/build/web/shared/components/TextArea/index.js.map +1 -1
- package/build/web/shared/components/Throbber/index.js +1 -1
- package/build/web/shared/components/Throbber/index.js.map +1 -1
- package/build/web/shared/components/WithTooltip/index.js +1 -1
- package/build/web/shared/components/WithTooltip/index.js.map +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js +1 -1
- package/build/web/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js +1 -1
- package/build/web/shared/components/selectors/CustomDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js +1 -1
- package/build/web/shared/components/selectors/NativeDropdown/index.js.map +1 -1
- package/build/web/shared/components/selectors/Switch/index.js +1 -1
- package/build/web/shared/components/selectors/Switch/index.js.map +1 -1
- package/package.json +17 -6
- package/src/client/getInj.ts +0 -71
- package/src/client/index.tsx +0 -45
- package/src/client/init.ts +0 -52
- package/src/index.ts +0 -75
- package/src/server/Cache.ts +0 -61
- package/src/server/index.ts +0 -243
- package/src/server/renderer.tsx +0 -635
- package/src/server/server.ts +0 -330
- package/src/server/utils/errors.ts +0 -122
- package/src/server/utils/index.ts +0 -3
- package/src/shared/components/Button/index.tsx +0 -130
- package/src/shared/components/Button/style.scss +0 -54
- package/src/shared/components/Checkbox/index.tsx +0 -53
- package/src/shared/components/Checkbox/theme.scss +0 -63
- package/src/shared/components/GenericLink/index.tsx +0 -141
- package/src/shared/components/GenericLink/style.scss +0 -3
- package/src/shared/components/Input/index.tsx +0 -96
- package/src/shared/components/Input/theme.scss +0 -52
- package/src/shared/components/Link.tsx +0 -25
- package/src/shared/components/Modal/base-theme.scss +0 -38
- package/src/shared/components/Modal/index.tsx +0 -177
- package/src/shared/components/Modal/styles.scss +0 -3
- package/src/shared/components/NavLink.tsx +0 -18
- package/src/shared/components/PageLayout/base-theme.scss +0 -30
- package/src/shared/components/PageLayout/index.tsx +0 -51
- package/src/shared/components/TextArea/index.tsx +0 -139
- package/src/shared/components/TextArea/style.scss +0 -68
- package/src/shared/components/Throbber/index.tsx +0 -28
- package/src/shared/components/Throbber/theme.scss +0 -26
- package/src/shared/components/WithTooltip/Tooltip.tsx +0 -274
- package/src/shared/components/WithTooltip/default-theme.scss +0 -36
- package/src/shared/components/WithTooltip/index.tsx +0 -186
- package/src/shared/components/YouTubeVideo/base.scss +0 -15
- package/src/shared/components/YouTubeVideo/index.tsx +0 -73
- package/src/shared/components/YouTubeVideo/throbber.scss +0 -11
- package/src/shared/components/index.ts +0 -20
- package/src/shared/components/selectors/CustomDropdown/Options/index.tsx +0 -124
- package/src/shared/components/selectors/CustomDropdown/Options/style.scss +0 -6
- package/src/shared/components/selectors/CustomDropdown/index.tsx +0 -146
- package/src/shared/components/selectors/CustomDropdown/theme.scss +0 -118
- package/src/shared/components/selectors/NativeDropdown/index.tsx +0 -90
- package/src/shared/components/selectors/NativeDropdown/theme.scss +0 -81
- package/src/shared/components/selectors/Switch/index.tsx +0 -74
- package/src/shared/components/selectors/Switch/theme.scss +0 -39
- package/src/shared/components/selectors/common.ts +0 -57
- package/src/shared/components/selectors/index.ts +0 -8
- package/src/shared/utils/config.ts +0 -59
- package/src/shared/utils/globalState.ts +0 -44
- package/src/shared/utils/index.ts +0 -45
- package/src/shared/utils/isomorphy/buildInfo.ts +0 -50
- package/src/shared/utils/isomorphy/environment-check.ts +0 -18
- package/src/shared/utils/isomorphy/index.ts +0 -36
- package/src/shared/utils/jest/E2eSsrEnv.ts +0 -304
- package/src/shared/utils/jest/global.ts +0 -17
- package/src/shared/utils/jest/index.ts +0 -215
- package/src/shared/utils/splitComponent.tsx +0 -284
- package/src/shared/utils/time.ts +0 -101
- package/src/shared/utils/webpack.ts +0 -80
- package/src/styles/_global/reset.css +0 -52
- package/src/styles/_mixins/fonts.scss +0 -40
- package/src/styles/_mixins/media.scss +0 -150
- package/src/styles/_mixins/typography.scss +0 -83
- package/src/styles/global.scss +0 -11
- package/src/styles/mixins.scss +0 -6
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
4
|
-
|
|
5
|
-
import baseTheme from './base-theme.scss';
|
|
6
|
-
|
|
7
|
-
type ThemeKeyT = 'container' | 'leftSidePanel' | 'mainPanel' | 'rightSidePanel'
|
|
8
|
-
| 'sidePanel';
|
|
9
|
-
|
|
10
|
-
type PropsT = {
|
|
11
|
-
children?: ReactNode;
|
|
12
|
-
leftSidePanelContent?: ReactNode;
|
|
13
|
-
rightSidePanelContent?: ReactNode;
|
|
14
|
-
theme: Theme<ThemeKeyT>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Simple and themeable page layout. It keeps the main content centered in
|
|
19
|
-
* a column of limited width, which fills entire viewport on small screens
|
|
20
|
-
* (under `$screen-md = 1024px` size). At larger screens the column keeps
|
|
21
|
-
* `$screen-md` size, and it is centered at the page, surrounded by side
|
|
22
|
-
* panels, where additional content can be displayed.
|
|
23
|
-
*
|
|
24
|
-
* **Children:** Component children are rendered as the content of main panel.
|
|
25
|
-
* @param {object} [props] Component properties.
|
|
26
|
-
* @param {Node} [props.leftSidePanelContent] The content for left side panel.
|
|
27
|
-
* @param {Node} [props.rightSidePanelContent] The content for right side panel.
|
|
28
|
-
* @param {PageLayoutTheme} [props.theme] _Ad hoc_ theme.
|
|
29
|
-
* @param {...any} [props....]
|
|
30
|
-
* [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
|
|
31
|
-
*/
|
|
32
|
-
const PageLayout: React.FunctionComponent<PropsT> = ({
|
|
33
|
-
children,
|
|
34
|
-
leftSidePanelContent,
|
|
35
|
-
rightSidePanelContent,
|
|
36
|
-
theme,
|
|
37
|
-
}) => (
|
|
38
|
-
<div className={theme.container}>
|
|
39
|
-
<div className={[theme.sidePanel, theme.leftSidePanel].join(' ')}>
|
|
40
|
-
{leftSidePanelContent}
|
|
41
|
-
</div>
|
|
42
|
-
<div className={theme.mainPanel}>
|
|
43
|
-
{children}
|
|
44
|
-
</div>
|
|
45
|
-
<div className={[theme.sidePanel, theme.rightSidePanel].join(' ')}>
|
|
46
|
-
{rightSidePanelContent}
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
export default themed(PageLayout, 'PageLayout', baseTheme);
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ChangeEventHandler,
|
|
3
|
-
type FocusEventHandler,
|
|
4
|
-
type FunctionComponent,
|
|
5
|
-
type KeyboardEventHandler,
|
|
6
|
-
type ReactNode,
|
|
7
|
-
useEffect,
|
|
8
|
-
useLayoutEffect,
|
|
9
|
-
useRef,
|
|
10
|
-
useState,
|
|
11
|
-
} from 'react';
|
|
12
|
-
|
|
13
|
-
import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
14
|
-
|
|
15
|
-
import defaultTheme from './style.scss';
|
|
16
|
-
|
|
17
|
-
type ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'
|
|
18
|
-
| 'textarea';
|
|
19
|
-
|
|
20
|
-
type Props = {
|
|
21
|
-
disabled?: boolean;
|
|
22
|
-
error?: ReactNode;
|
|
23
|
-
label?: string;
|
|
24
|
-
onBlur?: FocusEventHandler<HTMLTextAreaElement>;
|
|
25
|
-
onChange?: ChangeEventHandler<HTMLTextAreaElement>;
|
|
26
|
-
onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;
|
|
27
|
-
placeholder?: string;
|
|
28
|
-
testId?: string;
|
|
29
|
-
theme: Theme<ThemeKeyT>;
|
|
30
|
-
value?: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const TextArea: FunctionComponent<Props> = ({
|
|
34
|
-
disabled,
|
|
35
|
-
error,
|
|
36
|
-
label,
|
|
37
|
-
onBlur,
|
|
38
|
-
onChange,
|
|
39
|
-
onKeyDown,
|
|
40
|
-
placeholder,
|
|
41
|
-
testId,
|
|
42
|
-
theme,
|
|
43
|
-
value,
|
|
44
|
-
}) => {
|
|
45
|
-
const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);
|
|
46
|
-
const [height, setHeight] = useState<number | undefined>();
|
|
47
|
-
|
|
48
|
-
const textAreaRef = useRef<HTMLTextAreaElement>(null);
|
|
49
|
-
|
|
50
|
-
const [localValue, setLocalValue] = useState(value ?? '');
|
|
51
|
-
if (value !== undefined && localValue !== value) setLocalValue(value);
|
|
52
|
-
|
|
53
|
-
// This resizes text area's height when its width is changed for any reason.
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const el = hiddenAreaRef.current;
|
|
56
|
-
if (!el) return undefined;
|
|
57
|
-
|
|
58
|
-
const cb = () => {
|
|
59
|
-
setHeight(el.scrollHeight);
|
|
60
|
-
};
|
|
61
|
-
const observer = new ResizeObserver(cb);
|
|
62
|
-
observer.observe(el);
|
|
63
|
-
|
|
64
|
-
return () => {
|
|
65
|
-
observer.disconnect();
|
|
66
|
-
};
|
|
67
|
-
}, []);
|
|
68
|
-
|
|
69
|
-
// Resizes the text area when its content is modified.
|
|
70
|
-
//
|
|
71
|
-
// NOTE: useLayoutEffect() instead of useEffect() makes difference here,
|
|
72
|
-
// as it helps to avoid visible "content/height" jumps (i.e. with just
|
|
73
|
-
// useEffect() it becomes visible how the content is modified first,
|
|
74
|
-
// and then input height is incremented, if necessary).
|
|
75
|
-
// See: https://github.com/birdofpreyru/react-utils/issues/313
|
|
76
|
-
useLayoutEffect(() => {
|
|
77
|
-
const el = hiddenAreaRef.current;
|
|
78
|
-
if (el) setHeight(el.scrollHeight);
|
|
79
|
-
}, [localValue]);
|
|
80
|
-
|
|
81
|
-
let containerClassName = theme.container;
|
|
82
|
-
if (error) containerClassName += ` ${theme.error}`;
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<div
|
|
86
|
-
className={containerClassName}
|
|
87
|
-
onFocus={() => {
|
|
88
|
-
textAreaRef.current?.focus();
|
|
89
|
-
}}
|
|
90
|
-
>
|
|
91
|
-
{label === undefined ? null : <div className={theme.label}>{label}</div>}
|
|
92
|
-
<textarea
|
|
93
|
-
className={`${theme.textarea} ${theme.hidden}`}
|
|
94
|
-
|
|
95
|
-
// This text area is hidden underneath the primary one below,
|
|
96
|
-
// and it is used for text measurements, to implement auto-scaling
|
|
97
|
-
// of the primary textarea's height.
|
|
98
|
-
readOnly
|
|
99
|
-
ref={hiddenAreaRef}
|
|
100
|
-
|
|
101
|
-
// The "-1" value of "tabIndex" removes this hidden text area from
|
|
102
|
-
// the tab-focus-chain.
|
|
103
|
-
tabIndex={-1}
|
|
104
|
-
|
|
105
|
-
// NOTE: With empty string value ("") the scrolling height of this text
|
|
106
|
-
// area is zero, thus collapsing <TextArea> height below the single line
|
|
107
|
-
// input height. To avoid it we fallback to whitespace (" ") character
|
|
108
|
-
// here.
|
|
109
|
-
value={localValue || ' '}
|
|
110
|
-
/>
|
|
111
|
-
<textarea
|
|
112
|
-
className={theme.textarea}
|
|
113
|
-
data-testid={process.env.NODE_ENV === 'production' ? undefined : testId}
|
|
114
|
-
disabled={disabled}
|
|
115
|
-
onBlur={onBlur}
|
|
116
|
-
|
|
117
|
-
// When value is "undefined" the text area is not-managed, and we should
|
|
118
|
-
// manage it internally for the measurement / resizing functionality
|
|
119
|
-
// to work.
|
|
120
|
-
onChange={
|
|
121
|
-
value === undefined
|
|
122
|
-
? (e) => {
|
|
123
|
-
setLocalValue(e.target.value);
|
|
124
|
-
} : onChange
|
|
125
|
-
}
|
|
126
|
-
onKeyDown={onKeyDown}
|
|
127
|
-
placeholder={placeholder}
|
|
128
|
-
ref={textAreaRef}
|
|
129
|
-
style={{ height }}
|
|
130
|
-
value={localValue}
|
|
131
|
-
/>
|
|
132
|
-
{error && error !== true
|
|
133
|
-
? <div className={theme.errorMessage}>{error}</div>
|
|
134
|
-
: null}
|
|
135
|
-
</div>
|
|
136
|
-
);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export default themed(TextArea, 'TextArea', defaultTheme);
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
@use "sass:color";
|
|
2
|
-
|
|
3
|
-
*,
|
|
4
|
-
.context,
|
|
5
|
-
.ad.hoc {
|
|
6
|
-
&.container {
|
|
7
|
-
display: inline-flex;
|
|
8
|
-
flex-wrap: wrap;
|
|
9
|
-
margin: 0.1em;
|
|
10
|
-
position: relative;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
&.label {
|
|
14
|
-
margin: 0 0.3em;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
&.textarea {
|
|
18
|
-
background: white;
|
|
19
|
-
border: 1px solid gray;
|
|
20
|
-
border-radius: 0.3em;
|
|
21
|
-
box-sizing: border-box;
|
|
22
|
-
font: inherit;
|
|
23
|
-
height: 0;
|
|
24
|
-
outline: none;
|
|
25
|
-
overflow: hidden;
|
|
26
|
-
padding: 0.3em 0.3em calc(0.3em + 1px);
|
|
27
|
-
resize: none;
|
|
28
|
-
width: 100%;
|
|
29
|
-
|
|
30
|
-
&:focus {
|
|
31
|
-
border-color: blue;
|
|
32
|
-
box-shadow: 0 0 3px 1px lightblue;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
&::placeholder {
|
|
36
|
-
color: gray;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
&:disabled {
|
|
40
|
-
border-color: color.adjust($color: gray, $alpha: -0.66);
|
|
41
|
-
cursor: not-allowed;
|
|
42
|
-
color: color.adjust($color: gray, $alpha: -0.66);
|
|
43
|
-
user-select: none;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
&.error &.textarea {
|
|
48
|
-
border-color: red;
|
|
49
|
-
|
|
50
|
-
&:focus { box-shadow: 0 0 3px 1px orangered }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
&.errorMessage {
|
|
54
|
-
color: red;
|
|
55
|
-
font-size: 0.8em;
|
|
56
|
-
font-style: italic;
|
|
57
|
-
padding-right: 0.6em;
|
|
58
|
-
text-align: right;
|
|
59
|
-
width: 100%;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
&.hidden {
|
|
63
|
-
// NOTE: We hide it this way, as setting "display: none" will interfere
|
|
64
|
-
// with measurements, making the hidden input height zero.
|
|
65
|
-
opacity: 0;
|
|
66
|
-
position: absolute;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
2
|
-
|
|
3
|
-
import defaultTheme from './theme.scss';
|
|
4
|
-
|
|
5
|
-
type ThemeKeyT = 'bouncing' | 'circle' | 'container';
|
|
6
|
-
|
|
7
|
-
type PropsT = {
|
|
8
|
-
theme: Theme<ThemeKeyT>;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Throbber is an "action in progress" indicator, which renders
|
|
13
|
-
* three bouncing circles as a simple pending activity indicator,
|
|
14
|
-
* and can be further themed to a certain degree.
|
|
15
|
-
* @param {object} [props] Component properties.
|
|
16
|
-
* @param {ThrobberTheme} [props.theme] _Ad hoc_ theme.
|
|
17
|
-
* @param {...any} [props....]
|
|
18
|
-
* [Other theming properties](https://www.npmjs.com/package/@dr.pogodin/react-themes#themed-component-properties)
|
|
19
|
-
*/
|
|
20
|
-
const Throbber: React.FunctionComponent<PropsT> = ({ theme }) => (
|
|
21
|
-
<span className={theme.container}>
|
|
22
|
-
<span className={theme.circle} />
|
|
23
|
-
<span className={theme.circle} />
|
|
24
|
-
<span className={theme.circle} />
|
|
25
|
-
</span>
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
export default themed(Throbber, 'Throbber', defaultTheme);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
@keyframes bouncing {
|
|
2
|
-
from { top: -0.3em; }
|
|
3
|
-
to { top: 0.3em; }
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
*,
|
|
7
|
-
.context,
|
|
8
|
-
.ad.hoc {
|
|
9
|
-
&.container {
|
|
10
|
-
display: inline-block;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
&.circle {
|
|
14
|
-
animation: bouncing 0.4s ease-in infinite alternate;
|
|
15
|
-
background: black;
|
|
16
|
-
border-radius: 0.3em;
|
|
17
|
-
display: inline-block;
|
|
18
|
-
height: 0.6em;
|
|
19
|
-
margin: 0 0.1em;
|
|
20
|
-
position: relative;
|
|
21
|
-
width: 0.6em;
|
|
22
|
-
|
|
23
|
-
&:first-child { animation-delay: -0.2s; }
|
|
24
|
-
&:last-child { animation-delay: 0.2s; }
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The actual tooltip component. It is rendered outside the regular document
|
|
3
|
-
* hierarchy, and with sub-components managed without React to achieve the best
|
|
4
|
-
* performance during animation.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
type FunctionComponent,
|
|
9
|
-
type ReactNode,
|
|
10
|
-
type RefObject,
|
|
11
|
-
useImperativeHandle,
|
|
12
|
-
useRef,
|
|
13
|
-
} from 'react';
|
|
14
|
-
|
|
15
|
-
import { createPortal } from 'react-dom';
|
|
16
|
-
|
|
17
|
-
import type { Theme } from '@dr.pogodin/react-themes';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Valid placements of the rendered tooltip. They will be overriden when
|
|
21
|
-
* necessary to fit the tooltip within the viewport.
|
|
22
|
-
*/
|
|
23
|
-
export enum PLACEMENTS {
|
|
24
|
-
ABOVE_CURSOR = 'ABOVE_CURSOR',
|
|
25
|
-
ABOVE_ELEMENT = 'ABOVE_ELEMENT',
|
|
26
|
-
BELOW_CURSOR = 'BELOW_CURSOR',
|
|
27
|
-
BELOW_ELEMENT = 'BELOW_ELEMENT',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const ARROW_STYLE_DOWN = [
|
|
31
|
-
'border-bottom-color:transparent',
|
|
32
|
-
'border-left-color:transparent',
|
|
33
|
-
'border-right-color:transparent',
|
|
34
|
-
].join(';');
|
|
35
|
-
|
|
36
|
-
const ARROW_STYLE_UP = [
|
|
37
|
-
'border-top-color:transparent',
|
|
38
|
-
'border-left-color:transparent',
|
|
39
|
-
'border-right-color:transparent',
|
|
40
|
-
].join(';');
|
|
41
|
-
|
|
42
|
-
type ComponentsT = {
|
|
43
|
-
container: HTMLDivElement;
|
|
44
|
-
arrow: HTMLDivElement;
|
|
45
|
-
content: HTMLDivElement;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type ThemeKeysT = 'appearance' | 'arrow' | 'content' | 'container';
|
|
49
|
-
|
|
50
|
-
type TooltipThemeT = Theme<ThemeKeysT>;
|
|
51
|
-
|
|
52
|
-
type TooltipRectsT = {
|
|
53
|
-
arrow: DOMRect;
|
|
54
|
-
container: DOMRect;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Generates bounding client rectangles for tooltip components.
|
|
59
|
-
* @ignore
|
|
60
|
-
* @param tooltip DOM references to the tooltip components.
|
|
61
|
-
* @param tooltip.arrow
|
|
62
|
-
* @param tooltip.container
|
|
63
|
-
* @return Object holding tooltip rectangles in
|
|
64
|
-
* two fields.
|
|
65
|
-
*/
|
|
66
|
-
function calcTooltipRects(tooltip: ComponentsT): TooltipRectsT {
|
|
67
|
-
return {
|
|
68
|
-
arrow: tooltip.arrow.getBoundingClientRect(),
|
|
69
|
-
container: tooltip.container.getBoundingClientRect(),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Calculates the document viewport size.
|
|
75
|
-
* @ignore
|
|
76
|
-
* @return {{x, y, width, height}}
|
|
77
|
-
*/
|
|
78
|
-
function calcViewportRect() {
|
|
79
|
-
const { scrollX, scrollY } = window;
|
|
80
|
-
const { documentElement: { clientHeight, clientWidth } } = document;
|
|
81
|
-
return {
|
|
82
|
-
bottom: scrollY + clientHeight,
|
|
83
|
-
left: scrollX,
|
|
84
|
-
right: scrollX + clientWidth,
|
|
85
|
-
top: scrollY,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Calculates tooltip and arrow positions for the placement just above
|
|
91
|
-
* the cursor.
|
|
92
|
-
* @ignore
|
|
93
|
-
* @param {number} x Cursor page-x position.
|
|
94
|
-
* @param {number} y Cursor page-y position.
|
|
95
|
-
* @param {object} tooltipRects Bounding client rectangles of tooltip parts.
|
|
96
|
-
* @param {object} tooltipRects.arrow
|
|
97
|
-
* @param {object} tooltipRects.container
|
|
98
|
-
* @return {object} Contains the following fields:
|
|
99
|
-
* - {number} arrowX
|
|
100
|
-
* - {number} arrowY
|
|
101
|
-
* - {number} containerX
|
|
102
|
-
* - {number} containerY
|
|
103
|
-
* - {string} baseArrowStyle
|
|
104
|
-
*/
|
|
105
|
-
function calcPositionAboveXY(
|
|
106
|
-
x: number,
|
|
107
|
-
y: number,
|
|
108
|
-
tooltipRects: TooltipRectsT,
|
|
109
|
-
) {
|
|
110
|
-
const { arrow, container } = tooltipRects;
|
|
111
|
-
return {
|
|
112
|
-
arrowX: 0.5 * (container.width - arrow.width),
|
|
113
|
-
arrowY: container.height,
|
|
114
|
-
containerX: x - container.width / 2,
|
|
115
|
-
containerY: y - container.height - arrow.height / 1.5,
|
|
116
|
-
|
|
117
|
-
// TODO: Instead of already setting the base style here, we should
|
|
118
|
-
// introduce a set of constants for arrow directions, which will help
|
|
119
|
-
// to do checks dependant on the arrow direction.
|
|
120
|
-
baseArrowStyle: ARROW_STYLE_DOWN,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// const HIT = {
|
|
125
|
-
// NONE: false,
|
|
126
|
-
// LEFT: 'LEFT',
|
|
127
|
-
// RIGHT: 'RIGHT',
|
|
128
|
-
// TOP: 'TOP',
|
|
129
|
-
// BOTTOM: 'BOTTOM',
|
|
130
|
-
// };
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Checks whether
|
|
134
|
-
* @param {object} pos
|
|
135
|
-
* @param {object} tooltipRects
|
|
136
|
-
* @param {object} viewportRect
|
|
137
|
-
* @return {HIT}
|
|
138
|
-
*/
|
|
139
|
-
// function checkViewportFit(pos, tooltipRects, viewportRect) {
|
|
140
|
-
// const { containerX, containerY } = pos;
|
|
141
|
-
// if (containerX < viewportRect.left + 6) return HIT.LEFT;
|
|
142
|
-
// if (containerX > viewportRect.right - 6) return HIT.RIGHT;
|
|
143
|
-
// return HIT.NONE;
|
|
144
|
-
// }
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Shifts tooltip horizontally to fit into the viewport, while keeping
|
|
148
|
-
* the arrow pointed to the XY point.
|
|
149
|
-
* @param {number} x
|
|
150
|
-
* @param {number} y
|
|
151
|
-
* @param {object} pos
|
|
152
|
-
* @param {number} pageXOffset
|
|
153
|
-
* @param {number} pageXWidth
|
|
154
|
-
*/
|
|
155
|
-
// function xPageFitCorrection(x, y, pos, pageXOffset, pageXWidth) {
|
|
156
|
-
// if (pos.containerX < pageXOffset + 6) {
|
|
157
|
-
// pos.containerX = pageXOffset + 6;
|
|
158
|
-
// pos.arrowX = Math.max(6, pageX - containerX - arrowRect.width / 2);
|
|
159
|
-
// } else {
|
|
160
|
-
// const maxX = pageXOffset + docRect.width - containerRect.width - 6;
|
|
161
|
-
// if (containerX > maxX) {
|
|
162
|
-
// containerX = maxX;
|
|
163
|
-
// arrowX = Math.min(
|
|
164
|
-
// containerRect.width - 6,
|
|
165
|
-
// pageX - containerX - arrowRect.width / 2,
|
|
166
|
-
// );
|
|
167
|
-
// }
|
|
168
|
-
// }
|
|
169
|
-
// }
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Sets positions of tooltip components to point the tooltip to the specified
|
|
173
|
-
* page point.
|
|
174
|
-
* @ignore
|
|
175
|
-
* @param pageX
|
|
176
|
-
* @param pageY
|
|
177
|
-
* @param placement
|
|
178
|
-
* @param element DOM reference to the element wrapped by the tooltip.
|
|
179
|
-
* @param tooltip
|
|
180
|
-
* @param tooltip.arrow DOM reference to the tooltip arrow.
|
|
181
|
-
* @param tooltip.container DOM reference to the tooltip container.
|
|
182
|
-
*/
|
|
183
|
-
function setComponentPositions(
|
|
184
|
-
pageX: number,
|
|
185
|
-
pageY: number,
|
|
186
|
-
placement: PLACEMENTS | undefined,
|
|
187
|
-
element: HTMLElement | undefined,
|
|
188
|
-
tooltip: ComponentsT,
|
|
189
|
-
) {
|
|
190
|
-
const tooltipRects = calcTooltipRects(tooltip);
|
|
191
|
-
const viewportRect = calcViewportRect();
|
|
192
|
-
|
|
193
|
-
/* Default container coords: tooltip at the top. */
|
|
194
|
-
const pos = calcPositionAboveXY(pageX, pageY, tooltipRects);
|
|
195
|
-
|
|
196
|
-
if (pos.containerX < viewportRect.left + 6) {
|
|
197
|
-
pos.containerX = viewportRect.left + 6;
|
|
198
|
-
pos.arrowX = Math.max(
|
|
199
|
-
6,
|
|
200
|
-
pageX - pos.containerX - tooltipRects.arrow.width / 2,
|
|
201
|
-
);
|
|
202
|
-
} else {
|
|
203
|
-
const maxX = viewportRect.right - 6 - tooltipRects.container.width;
|
|
204
|
-
if (pos.containerX > maxX) {
|
|
205
|
-
pos.containerX = maxX;
|
|
206
|
-
pos.arrowX = Math.min(
|
|
207
|
-
tooltipRects.container.width - 6,
|
|
208
|
-
pageX - pos.containerX - tooltipRects.arrow.width / 2,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/* If tooltip has not enough space on top - make it bottom tooltip. */
|
|
214
|
-
if (pos.containerY < viewportRect.top + 6) {
|
|
215
|
-
pos.containerY += tooltipRects.container.height
|
|
216
|
-
+ 2 * tooltipRects.arrow.height;
|
|
217
|
-
pos.arrowY -= tooltipRects.container.height
|
|
218
|
-
+ tooltipRects.arrow.height;
|
|
219
|
-
pos.baseArrowStyle = ARROW_STYLE_UP;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const containerStyle = `left:${pos.containerX}px;top:${pos.containerY}px`;
|
|
223
|
-
tooltip.container.setAttribute('style', containerStyle);
|
|
224
|
-
|
|
225
|
-
const arrowStyle = `${pos.baseArrowStyle};left:${pos.arrowX}px;top:${pos.arrowY}px`;
|
|
226
|
-
tooltip.arrow.setAttribute('style', arrowStyle);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/* The Tooltip component itself. */
|
|
230
|
-
const Tooltip: FunctionComponent<{
|
|
231
|
-
children?: ReactNode;
|
|
232
|
-
ref?: RefObject<unknown>;
|
|
233
|
-
theme: TooltipThemeT;
|
|
234
|
-
}> = ({ children, ref, theme }) => {
|
|
235
|
-
// NOTE: The way it has to be implemented, for clean mounting and unmounting
|
|
236
|
-
// at the client side, the <Tooltip> is fully mounted into DOM in the next
|
|
237
|
-
// rendering cycles, and only then it can be correctly measured and positioned.
|
|
238
|
-
// Thus, when we create the <Tooltip> we have to record its target positioning
|
|
239
|
-
// details, and then apply them when it is created.
|
|
240
|
-
|
|
241
|
-
const arrowRef = useRef<HTMLDivElement>(null);
|
|
242
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
243
|
-
const contentRef = useRef<HTMLDivElement>(null);
|
|
244
|
-
|
|
245
|
-
const pointTo = (
|
|
246
|
-
pageX: number,
|
|
247
|
-
pageY: number,
|
|
248
|
-
placement: PLACEMENTS,
|
|
249
|
-
element: HTMLElement,
|
|
250
|
-
) => {
|
|
251
|
-
if (!arrowRef.current || !containerRef.current || !contentRef.current) {
|
|
252
|
-
throw Error('Internal error');
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
setComponentPositions(pageX, pageY, placement, element, {
|
|
256
|
-
arrow: arrowRef.current,
|
|
257
|
-
container: containerRef.current,
|
|
258
|
-
content: contentRef.current,
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
useImperativeHandle(ref, () => ({ pointTo }));
|
|
262
|
-
|
|
263
|
-
return createPortal(
|
|
264
|
-
(
|
|
265
|
-
<div className={theme.container} ref={containerRef}>
|
|
266
|
-
<div className={theme.arrow} ref={arrowRef} />
|
|
267
|
-
<div className={theme.content} ref={contentRef}>{children}</div>
|
|
268
|
-
</div>
|
|
269
|
-
),
|
|
270
|
-
document.body,
|
|
271
|
-
);
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
export default Tooltip;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
@keyframes appearance {
|
|
2
|
-
from { opacity: 0; }
|
|
3
|
-
to { opacity: 1; }
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
*,
|
|
7
|
-
.ad.hoc,
|
|
8
|
-
.context {
|
|
9
|
-
&.arrow {
|
|
10
|
-
border: 0.6em solid grey;
|
|
11
|
-
pointer-events: none;
|
|
12
|
-
position: absolute;
|
|
13
|
-
width: 0;
|
|
14
|
-
height: 0;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
&.content { }
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
&.container {
|
|
22
|
-
background: grey;
|
|
23
|
-
border-radius: 0.3em;
|
|
24
|
-
color: white;
|
|
25
|
-
display: inline-block;
|
|
26
|
-
padding: 0 0.3em;
|
|
27
|
-
position: absolute;
|
|
28
|
-
top: 0;
|
|
29
|
-
left: 0;
|
|
30
|
-
animation: appearance 0.6s;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
&.wrapper {
|
|
34
|
-
display: inline-block;
|
|
35
|
-
}
|
|
36
|
-
}
|