@dr.pogodin/react-utils 1.28.1 → 1.29.1
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/index.js +36 -84
- package/build/development/index.js.map +1 -1
- package/build/development/shared/components/Button/index.js +2 -1
- package/build/development/shared/components/Button/index.js.map +1 -1
- package/build/development/shared/components/Checkbox/index.js +2 -1
- package/build/development/shared/components/Checkbox/index.js.map +1 -1
- package/build/development/shared/components/Dropdown/index.js +14 -9
- package/build/development/shared/components/Dropdown/index.js.map +1 -1
- package/build/development/shared/components/Input/index.js +2 -1
- package/build/development/shared/components/Input/index.js.map +1 -1
- package/build/development/shared/components/Modal/index.js +2 -1
- package/build/development/shared/components/Modal/index.js.map +1 -1
- package/build/development/shared/components/PageLayout/index.js +2 -1
- package/build/development/shared/components/PageLayout/index.js.map +1 -1
- package/build/development/shared/components/TextArea/index.js +94 -0
- package/build/development/shared/components/TextArea/index.js.map +1 -0
- package/build/development/shared/components/Throbber/index.js +2 -1
- package/build/development/shared/components/Throbber/index.js.map +1 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js +2 -1
- package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
- package/build/development/shared/components/WithTooltip/index.js +1 -0
- package/build/development/shared/components/WithTooltip/index.js.map +1 -1
- package/build/development/shared/components/YouTubeVideo/index.js +2 -1
- package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/development/shared/components/index.js +7 -0
- package/build/development/shared/components/index.js.map +1 -1
- package/build/development/style.css +89 -0
- package/build/development/web.bundle.js +33 -13
- package/build/production/index.js +1 -1
- package/build/production/index.js.map +1 -1
- package/build/production/shared/components/Button/index.js +2 -2
- package/build/production/shared/components/Button/index.js.map +1 -1
- package/build/production/shared/components/Checkbox/index.js +2 -2
- package/build/production/shared/components/Checkbox/index.js.map +1 -1
- package/build/production/shared/components/Dropdown/index.js +2 -2
- package/build/production/shared/components/Dropdown/index.js.map +1 -1
- package/build/production/shared/components/Input/index.js +2 -2
- package/build/production/shared/components/Input/index.js.map +1 -1
- package/build/production/shared/components/Modal/index.js +2 -2
- package/build/production/shared/components/Modal/index.js.map +1 -1
- package/build/production/shared/components/PageLayout/index.js +2 -2
- package/build/production/shared/components/PageLayout/index.js.map +1 -1
- package/build/production/shared/components/TextArea/index.js +10 -0
- package/build/production/shared/components/TextArea/index.js.map +1 -0
- package/build/production/shared/components/Throbber/index.js +2 -2
- package/build/production/shared/components/Throbber/index.js.map +1 -1
- package/build/production/shared/components/WithTooltip/Tooltip.js +2 -2
- package/build/production/shared/components/WithTooltip/Tooltip.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 +2 -2
- package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
- package/build/production/shared/components/index.js +1 -1
- package/build/production/shared/components/index.js.map +1 -1
- package/build/production/style.css +1 -1
- package/build/production/style.css.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/index.d.ts +1 -1
- package/build/types-code/shared/components/Button/index.d.ts +2 -5
- package/build/types-code/shared/components/Checkbox/index.d.ts +2 -5
- package/build/types-code/shared/components/Dropdown/index.d.ts +2 -8
- package/build/types-code/shared/components/Input/index.d.ts +2 -5
- package/build/types-code/shared/components/Modal/index.d.ts +2 -4
- package/build/types-code/shared/components/PageLayout/index.d.ts +2 -7
- package/build/types-code/shared/components/TextArea/index.d.ts +12 -0
- package/build/types-code/shared/components/Throbber/index.d.ts +2 -5
- package/build/types-code/shared/components/WithTooltip/Tooltip.d.ts +1 -6
- package/build/types-code/shared/components/WithTooltip/index.d.ts +3 -4
- package/build/types-code/shared/components/YouTubeVideo/index.d.ts +2 -4
- package/build/types-code/shared/components/index.d.ts +1 -0
- package/build/types-scss/src/shared/components/Dropdown/theme.scss.d.ts +1 -0
- package/build/types-scss/src/shared/components/TextArea/style.scss.d.ts +6 -0
- package/package.json +33 -33
- package/src/index.ts +1 -16
- package/src/shared/components/Button/index.tsx +4 -10
- package/src/shared/components/Checkbox/index.tsx +9 -10
- package/src/shared/components/Dropdown/index.tsx +28 -25
- package/src/shared/components/Dropdown/theme.scss +6 -0
- package/src/shared/components/Input/index.tsx +8 -10
- package/src/shared/components/Modal/index.tsx +4 -8
- package/src/shared/components/PageLayout/index.tsx +15 -14
- package/src/shared/components/TextArea/index.tsx +107 -0
- package/src/shared/components/TextArea/style.scss +37 -0
- package/src/shared/components/Throbber/index.tsx +8 -10
- package/src/shared/components/WithTooltip/Tooltip.tsx +10 -6
- package/src/shared/components/WithTooltip/index.tsx +7 -4
- package/src/shared/components/YouTubeVideo/index.tsx +4 -8
- package/src/shared/components/index.ts +2 -0
|
@@ -5,17 +5,19 @@ import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
|
5
5
|
|
|
6
6
|
import baseTheme from './base-theme.scss';
|
|
7
7
|
|
|
8
|
+
const validThemeKeys = [
|
|
9
|
+
'container',
|
|
10
|
+
'leftSidePanel',
|
|
11
|
+
'mainPanel',
|
|
12
|
+
'rightSidePanel',
|
|
13
|
+
'sidePanel',
|
|
14
|
+
] as const;
|
|
15
|
+
|
|
8
16
|
type PropsT = {
|
|
9
17
|
children?: ReactNode;
|
|
10
18
|
leftSidePanelContent?: ReactNode;
|
|
11
19
|
rightSidePanelContent?: ReactNode;
|
|
12
|
-
theme: Theme
|
|
13
|
-
container?: string;
|
|
14
|
-
mainPanel?: string;
|
|
15
|
-
sidePanel?: string;
|
|
16
|
-
leftSidePanel?: string;
|
|
17
|
-
rightSidePanel?: string;
|
|
18
|
-
};
|
|
20
|
+
theme: Theme<typeof validThemeKeys>;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -52,13 +54,12 @@ const PageLayout: React.FunctionComponent<PropsT> = ({
|
|
|
52
54
|
</div>
|
|
53
55
|
);
|
|
54
56
|
|
|
55
|
-
const ThemedPageLayout = themed(
|
|
56
|
-
|
|
57
|
-
'
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
], baseTheme);
|
|
57
|
+
const ThemedPageLayout = themed(
|
|
58
|
+
PageLayout,
|
|
59
|
+
'PageLayout',
|
|
60
|
+
validThemeKeys,
|
|
61
|
+
baseTheme,
|
|
62
|
+
);
|
|
62
63
|
|
|
63
64
|
PageLayout.propTypes = {
|
|
64
65
|
children: PT.node,
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import PT from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
5
|
+
|
|
6
|
+
import defaultTheme from './style.scss';
|
|
7
|
+
|
|
8
|
+
const validThemeKeys = [
|
|
9
|
+
'container',
|
|
10
|
+
'hidden',
|
|
11
|
+
'textarea',
|
|
12
|
+
] as const;
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
onChange?: React.ChangeEventHandler<HTMLTextAreaElement>;
|
|
16
|
+
onKeyDown?: React.KeyboardEventHandler<HTMLTextAreaElement>;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
theme: Theme<typeof validThemeKeys>;
|
|
19
|
+
value?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const TextArea: React.FunctionComponent<Props> = ({
|
|
23
|
+
onChange,
|
|
24
|
+
onKeyDown,
|
|
25
|
+
placeholder,
|
|
26
|
+
theme,
|
|
27
|
+
value,
|
|
28
|
+
}) => {
|
|
29
|
+
const hiddenAreaRef = useRef<HTMLTextAreaElement>(null);
|
|
30
|
+
const [height, setHeight] = useState<number | undefined>();
|
|
31
|
+
|
|
32
|
+
const [localValue, setLocalValue] = useState(value || '');
|
|
33
|
+
if (value !== undefined && localValue !== value) setLocalValue(value);
|
|
34
|
+
|
|
35
|
+
// This resizes text area's height when its width is changed for any reason.
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const el = hiddenAreaRef.current;
|
|
38
|
+
if (!el) return undefined;
|
|
39
|
+
|
|
40
|
+
const cb = () => {
|
|
41
|
+
setHeight(el.scrollHeight);
|
|
42
|
+
};
|
|
43
|
+
const observer = new ResizeObserver(cb);
|
|
44
|
+
observer.observe(el);
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
observer.disconnect();
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
// This resizes the text area when its content is modified.
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const el = hiddenAreaRef.current;
|
|
54
|
+
if (el) setHeight(el.scrollHeight);
|
|
55
|
+
}, [localValue]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div className={theme.container}>
|
|
59
|
+
<textarea
|
|
60
|
+
// This text area is hidden underneath the primary one below,
|
|
61
|
+
// and it is used for text measurements, to implement auto-scaling
|
|
62
|
+
// of the primary textarea's height.
|
|
63
|
+
readOnly
|
|
64
|
+
ref={hiddenAreaRef}
|
|
65
|
+
className={`${theme.textarea} ${theme.hidden}`}
|
|
66
|
+
value={localValue}
|
|
67
|
+
/>
|
|
68
|
+
<textarea
|
|
69
|
+
// When value is "undefined" the text area is not-managed, and we should
|
|
70
|
+
// manage it internally for the measurement / resizing functionality
|
|
71
|
+
// to work.
|
|
72
|
+
onChange={value === undefined ? ((e) => {
|
|
73
|
+
setLocalValue(e.target.value);
|
|
74
|
+
}) : onChange}
|
|
75
|
+
onKeyDown={onKeyDown}
|
|
76
|
+
placeholder={placeholder}
|
|
77
|
+
style={{ height }}
|
|
78
|
+
className={theme.textarea}
|
|
79
|
+
value={localValue}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const ThemedTextArea = themed(
|
|
86
|
+
TextArea,
|
|
87
|
+
'TextArea',
|
|
88
|
+
validThemeKeys,
|
|
89
|
+
defaultTheme,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
TextArea.propTypes = {
|
|
93
|
+
onChange: PT.func,
|
|
94
|
+
onKeyDown: PT.func,
|
|
95
|
+
placeholder: PT.string,
|
|
96
|
+
theme: ThemedTextArea.themeType.isRequired,
|
|
97
|
+
value: PT.string,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
TextArea.defaultProps = {
|
|
101
|
+
onChange: undefined,
|
|
102
|
+
onKeyDown: undefined,
|
|
103
|
+
placeholder: '',
|
|
104
|
+
value: undefined,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default ThemedTextArea;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@import "styles/mixins";
|
|
2
|
+
|
|
3
|
+
*,
|
|
4
|
+
.context,
|
|
5
|
+
.ad.hoc {
|
|
6
|
+
&.container {
|
|
7
|
+
margin: 0.1em;
|
|
8
|
+
position: relative;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&.textarea {
|
|
12
|
+
background: white;
|
|
13
|
+
border: 1px solid gray;
|
|
14
|
+
border-radius: 0.3em;
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
font: inherit;
|
|
17
|
+
height: 0;
|
|
18
|
+
outline: none;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
padding: 0.3em 0.3em calc(0.3em + 1px);
|
|
21
|
+
resize: none;
|
|
22
|
+
|
|
23
|
+
&:focus {
|
|
24
|
+
border-color: blue;
|
|
25
|
+
box-shadow: 0 0 3px 1px lightblue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&::placeholder {
|
|
29
|
+
color: gray;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&.hidden {
|
|
34
|
+
position: absolute;
|
|
35
|
+
z-index: -1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -2,12 +2,14 @@ import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
|
2
2
|
|
|
3
3
|
import defaultTheme from './theme.scss';
|
|
4
4
|
|
|
5
|
+
const validThemeKeys = [
|
|
6
|
+
'bouncing',
|
|
7
|
+
'circle',
|
|
8
|
+
'container',
|
|
9
|
+
] as const;
|
|
10
|
+
|
|
5
11
|
type PropsT = {
|
|
6
|
-
theme: Theme
|
|
7
|
-
bouncing?: string;
|
|
8
|
-
container?: string;
|
|
9
|
-
circle?: string;
|
|
10
|
-
};
|
|
12
|
+
theme: Theme<typeof validThemeKeys>;
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -30,11 +32,7 @@ const Throbber: React.FunctionComponent<PropsT> = ({ theme }) => (
|
|
|
30
32
|
const ThemedThrobber = themed(
|
|
31
33
|
Throbber,
|
|
32
34
|
'Throbber',
|
|
33
|
-
|
|
34
|
-
'bouncing',
|
|
35
|
-
'circle',
|
|
36
|
-
'container',
|
|
37
|
-
],
|
|
35
|
+
validThemeKeys,
|
|
38
36
|
defaultTheme,
|
|
39
37
|
);
|
|
40
38
|
|
|
@@ -18,6 +18,8 @@ import { createPortal } from 'react-dom';
|
|
|
18
18
|
|
|
19
19
|
import PT from 'prop-types';
|
|
20
20
|
|
|
21
|
+
import type { Theme } from '@dr.pogodin/react-themes';
|
|
22
|
+
|
|
21
23
|
/* Valid placements of the rendered tooltip. They will be overriden when
|
|
22
24
|
* necessary to fit the tooltip within the viewport. */
|
|
23
25
|
export enum PLACEMENTS {
|
|
@@ -52,12 +54,14 @@ type HeapT = {
|
|
|
52
54
|
lastPlacement?: PLACEMENTS | undefined;
|
|
53
55
|
};
|
|
54
56
|
|
|
55
|
-
export
|
|
56
|
-
appearance
|
|
57
|
-
arrow
|
|
58
|
-
content
|
|
59
|
-
container
|
|
60
|
-
|
|
57
|
+
export const validThemeKeys = [
|
|
58
|
+
'appearance',
|
|
59
|
+
'arrow',
|
|
60
|
+
'content',
|
|
61
|
+
'container',
|
|
62
|
+
] as const;
|
|
63
|
+
|
|
64
|
+
type TooltipThemeT = Theme<typeof validThemeKeys>;
|
|
61
65
|
|
|
62
66
|
/**
|
|
63
67
|
* Creates tooltip components.
|
|
@@ -10,17 +10,20 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import themed, { type Theme } from '@dr.pogodin/react-themes';
|
|
12
12
|
|
|
13
|
-
import Tooltip, {
|
|
13
|
+
import Tooltip, {
|
|
14
|
+
PLACEMENTS,
|
|
15
|
+
validThemeKeys as validTooltipThemeKeys,
|
|
16
|
+
} from './Tooltip';
|
|
14
17
|
|
|
15
18
|
import defaultTheme from './default-theme.scss';
|
|
16
19
|
|
|
20
|
+
const validThemeKeys = [...validTooltipThemeKeys, 'wrapper'] as const;
|
|
21
|
+
|
|
17
22
|
type PropsT = {
|
|
18
23
|
children?: ReactNode;
|
|
19
24
|
placement?: PLACEMENTS;
|
|
20
25
|
tip?: ReactNode;
|
|
21
|
-
theme: Theme
|
|
22
|
-
wrapper?: string;
|
|
23
|
-
};
|
|
26
|
+
theme: Theme<typeof validThemeKeys>;
|
|
24
27
|
};
|
|
25
28
|
|
|
26
29
|
type TooltipRefT = {
|
|
@@ -9,10 +9,9 @@ import Throbber from 'components/Throbber';
|
|
|
9
9
|
import baseTheme from './base.scss';
|
|
10
10
|
import throbberTheme from './throbber.scss';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
12
|
+
const validThemeKeys = ['container', 'video'] as const;
|
|
13
|
+
|
|
14
|
+
type ComponentThemeT = Theme<typeof validThemeKeys>;
|
|
16
15
|
|
|
17
16
|
type PropsT = {
|
|
18
17
|
autoplay?: boolean;
|
|
@@ -74,10 +73,7 @@ const YouTubeVideo: React.FunctionComponent<PropsT> = ({
|
|
|
74
73
|
const ThemedYouTubeVideo = themed(
|
|
75
74
|
YouTubeVideo,
|
|
76
75
|
'YouTubeVideo',
|
|
77
|
-
|
|
78
|
-
'container',
|
|
79
|
-
'video',
|
|
80
|
-
],
|
|
76
|
+
validThemeKeys,
|
|
81
77
|
baseTheme,
|
|
82
78
|
);
|
|
83
79
|
|
|
@@ -15,3 +15,5 @@ export { default as ScalableRect } from 'components/ScalableRect';
|
|
|
15
15
|
export { default as Throbber } from 'components/Throbber';
|
|
16
16
|
export { default as WithTooltip } from 'components/WithTooltip';
|
|
17
17
|
export { default as YouTubeVideo } from 'components/YouTubeVideo';
|
|
18
|
+
|
|
19
|
+
export { default as TextArea } from './TextArea';
|