@gravity-ui/dynamic-forms 4.7.1 → 4.7.3
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/cjs/lib/kit/components/CopyButton/CopyButton.css +8 -1
- package/build/cjs/lib/kit/components/CopyButton/CopyButton.js +2 -1
- package/build/cjs/lib/kit/components/LongValue/LongValue.css +6 -3
- package/build/cjs/lib/kit/components/LongValue/LongValue.js +28 -18
- package/build/esm/lib/kit/components/CopyButton/CopyButton.css +8 -1
- package/build/esm/lib/kit/components/CopyButton/CopyButton.js +2 -1
- package/build/esm/lib/kit/components/LongValue/LongValue.css +6 -3
- package/build/esm/lib/kit/components/LongValue/LongValue.d.ts +2 -2
- package/build/esm/lib/kit/components/LongValue/LongValue.js +29 -18
- package/package.json +1 -1
|
@@ -13,7 +13,8 @@ const b = (0, utils_1.block)('copy-button');
|
|
|
13
13
|
*/
|
|
14
14
|
const CopyButton = ({ spec, value }) => {
|
|
15
15
|
if (((0, core_1.isStringSpec)(spec) || (0, core_1.isNumberSpec)(spec)) && spec.viewSpec.copy) {
|
|
16
|
-
return react_1.default.createElement(
|
|
16
|
+
return (react_1.default.createElement("div", { className: b() },
|
|
17
|
+
react_1.default.createElement(uikit_1.ClipboardButton, { className: b('button'), text: `${value}`, size: "xs" })));
|
|
17
18
|
}
|
|
18
19
|
return null;
|
|
19
20
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
.df-long-value {
|
|
2
2
|
max-width: 100%;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
text-overflow: ellipsis;
|
|
5
|
+
}
|
|
6
|
+
.df-long-value_open {
|
|
7
|
+
white-space: pre-wrap;
|
|
8
|
+
word-wrap: break-word;
|
|
3
9
|
}
|
|
4
10
|
.df-long-value_long {
|
|
5
11
|
cursor: pointer;
|
|
6
12
|
}
|
|
7
13
|
.df-long-value_long:hover {
|
|
8
14
|
color: var(--g-color-text-secondary);
|
|
9
|
-
}
|
|
10
|
-
.df-long-value__container {
|
|
11
|
-
display: flex;
|
|
12
15
|
}
|
|
@@ -3,29 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LongValue = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const once_1 = tslib_1.__importDefault(require("lodash/once"));
|
|
6
7
|
const uikit_1 = require("@gravity-ui/uikit");
|
|
7
8
|
const utils_1 = require("../../utils");
|
|
8
9
|
const b = (0, utils_1.block)('long-value');
|
|
9
|
-
const LongValue = (
|
|
10
|
-
|
|
10
|
+
const LongValue = (_a) => {
|
|
11
|
+
var { value, className } = _a, restProps = tslib_1.__rest(_a, ["value", "className"]);
|
|
11
12
|
const ref = react_1.default.useRef(null);
|
|
12
13
|
const [open, setOpen] = react_1.default.useState(false);
|
|
13
14
|
const [long, setLong] = react_1.default.useState(false);
|
|
14
15
|
const handleClick = react_1.default.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
15
|
-
const currentTextProperies = react_1.default.useMemo(() => {
|
|
16
|
-
let wordBreak;
|
|
17
|
-
let whiteSpace;
|
|
18
|
-
if (open) {
|
|
19
|
-
wordBreak = 'break-all';
|
|
20
|
-
whiteSpace = 'break-spaces';
|
|
21
|
-
}
|
|
22
|
-
return { wordBreak, whiteSpace };
|
|
23
|
-
}, [open]);
|
|
24
16
|
react_1.default.useEffect(() => {
|
|
25
17
|
if (ref.current) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
18
|
+
const { offsetWidth, scrollWidth } = ref.current;
|
|
19
|
+
const setFlags = (0, once_1.default)((offsetW, scrollW) => {
|
|
20
|
+
if (offsetW < scrollW) {
|
|
29
21
|
if (!long) {
|
|
30
22
|
setLong(true);
|
|
31
23
|
}
|
|
@@ -38,11 +30,29 @@ const LongValue = ({ value, className }) => {
|
|
|
38
30
|
setOpen(false);
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
|
-
|
|
33
|
+
});
|
|
34
|
+
// element has been rendered, but is not displayed on the page
|
|
35
|
+
if (offsetWidth === 0 && scrollWidth === 0) {
|
|
36
|
+
const observer = new IntersectionObserver((entries) => {
|
|
37
|
+
const entry = entries.find((e) => e.target === ref.current);
|
|
38
|
+
if (entry && entry.isIntersecting) {
|
|
39
|
+
const target = entry.target;
|
|
40
|
+
setFlags(target.offsetWidth, target.scrollWidth);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
observer.observe(ref.current);
|
|
44
|
+
return () => {
|
|
45
|
+
observer.disconnect();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
setFlags(offsetWidth, scrollWidth);
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
return;
|
|
53
|
+
}, [value]);
|
|
54
|
+
return (react_1.default.createElement(uikit_1.Text, Object.assign({ as: "div" }, restProps, { ref: ref, className: b({ open, long }, className),
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
onClick: long ? handleClick : undefined }), value));
|
|
47
57
|
};
|
|
48
58
|
exports.LongValue = LongValue;
|
|
@@ -10,7 +10,8 @@ const b = block('copy-button');
|
|
|
10
10
|
*/
|
|
11
11
|
export const CopyButton = ({ spec, value }) => {
|
|
12
12
|
if ((isStringSpec(spec) || isNumberSpec(spec)) && spec.viewSpec.copy) {
|
|
13
|
-
return React.createElement(
|
|
13
|
+
return (React.createElement("div", { className: b() },
|
|
14
|
+
React.createElement(ClipboardButton, { className: b('button'), text: `${value}`, size: "xs" })));
|
|
14
15
|
}
|
|
15
16
|
return null;
|
|
16
17
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
.df-long-value {
|
|
2
2
|
max-width: 100%;
|
|
3
|
+
overflow: hidden;
|
|
4
|
+
text-overflow: ellipsis;
|
|
5
|
+
}
|
|
6
|
+
.df-long-value_open {
|
|
7
|
+
white-space: pre-wrap;
|
|
8
|
+
word-wrap: break-word;
|
|
3
9
|
}
|
|
4
10
|
.df-long-value_long {
|
|
5
11
|
cursor: pointer;
|
|
6
12
|
}
|
|
7
13
|
.df-long-value_long:hover {
|
|
8
14
|
color: var(--g-color-text-secondary);
|
|
9
|
-
}
|
|
10
|
-
.df-long-value__container {
|
|
11
|
-
display: flex;
|
|
12
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type TextProps } from '@gravity-ui/uikit';
|
|
2
3
|
import './LongValue.css';
|
|
3
|
-
export interface LongValueProps {
|
|
4
|
+
export interface LongValueProps extends TextProps {
|
|
4
5
|
value?: string | number | boolean;
|
|
5
|
-
className?: string;
|
|
6
6
|
}
|
|
7
7
|
export declare const LongValue: React.FC<LongValueProps>;
|
|
@@ -1,28 +1,21 @@
|
|
|
1
|
+
import { __rest } from "tslib";
|
|
1
2
|
import React from 'react';
|
|
3
|
+
import once from 'lodash/once';
|
|
2
4
|
import { Text } from '@gravity-ui/uikit';
|
|
3
5
|
import { block } from '../../utils';
|
|
4
6
|
import './LongValue.css';
|
|
5
7
|
const b = block('long-value');
|
|
6
|
-
export const LongValue = (
|
|
7
|
-
|
|
8
|
+
export const LongValue = (_a) => {
|
|
9
|
+
var { value, className } = _a, restProps = __rest(_a, ["value", "className"]);
|
|
8
10
|
const ref = React.useRef(null);
|
|
9
11
|
const [open, setOpen] = React.useState(false);
|
|
10
12
|
const [long, setLong] = React.useState(false);
|
|
11
13
|
const handleClick = React.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
12
|
-
const currentTextProperies = React.useMemo(() => {
|
|
13
|
-
let wordBreak;
|
|
14
|
-
let whiteSpace;
|
|
15
|
-
if (open) {
|
|
16
|
-
wordBreak = 'break-all';
|
|
17
|
-
whiteSpace = 'break-spaces';
|
|
18
|
-
}
|
|
19
|
-
return { wordBreak, whiteSpace };
|
|
20
|
-
}, [open]);
|
|
21
14
|
React.useEffect(() => {
|
|
22
15
|
if (ref.current) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (
|
|
16
|
+
const { offsetWidth, scrollWidth } = ref.current;
|
|
17
|
+
const setFlags = once((offsetW, scrollW) => {
|
|
18
|
+
if (offsetW < scrollW) {
|
|
26
19
|
if (!long) {
|
|
27
20
|
setLong(true);
|
|
28
21
|
}
|
|
@@ -35,10 +28,28 @@ export const LongValue = ({ value, className }) => {
|
|
|
35
28
|
setOpen(false);
|
|
36
29
|
}
|
|
37
30
|
}
|
|
38
|
-
|
|
31
|
+
});
|
|
32
|
+
// element has been rendered, but is not displayed on the page
|
|
33
|
+
if (offsetWidth === 0 && scrollWidth === 0) {
|
|
34
|
+
const observer = new IntersectionObserver((entries) => {
|
|
35
|
+
const entry = entries.find((e) => e.target === ref.current);
|
|
36
|
+
if (entry && entry.isIntersecting) {
|
|
37
|
+
const target = entry.target;
|
|
38
|
+
setFlags(target.offsetWidth, target.scrollWidth);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
observer.observe(ref.current);
|
|
42
|
+
return () => {
|
|
43
|
+
observer.disconnect();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
setFlags(offsetWidth, scrollWidth);
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
return;
|
|
51
|
+
}, [value]);
|
|
52
|
+
return (React.createElement(Text, Object.assign({ as: "div" }, restProps, { ref: ref, className: b({ open, long }, className),
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
onClick: long ? handleClick : undefined }), value));
|
|
44
55
|
};
|