@gravity-ui/dynamic-forms 4.7.2 → 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.
|
@@ -3,20 +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
16
|
react_1.default.useEffect(() => {
|
|
16
17
|
if (ref.current) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
18
|
+
const { offsetWidth, scrollWidth } = ref.current;
|
|
19
|
+
const setFlags = (0, once_1.default)((offsetW, scrollW) => {
|
|
20
|
+
if (offsetW < scrollW) {
|
|
20
21
|
if (!long) {
|
|
21
22
|
setLong(true);
|
|
22
23
|
}
|
|
@@ -29,12 +30,29 @@ const LongValue = ({ value, className }) => {
|
|
|
29
30
|
setOpen(false);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
|
|
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);
|
|
33
50
|
}
|
|
34
51
|
}
|
|
35
|
-
|
|
36
|
-
|
|
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),
|
|
37
55
|
// @ts-ignore
|
|
38
|
-
onClick: long ? handleClick : undefined }, value));
|
|
56
|
+
onClick: long ? handleClick : undefined }), value));
|
|
39
57
|
};
|
|
40
58
|
exports.LongValue = LongValue;
|
|
@@ -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,19 +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
14
|
React.useEffect(() => {
|
|
13
15
|
if (ref.current) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
16
|
+
const { offsetWidth, scrollWidth } = ref.current;
|
|
17
|
+
const setFlags = once((offsetW, scrollW) => {
|
|
18
|
+
if (offsetW < scrollW) {
|
|
17
19
|
if (!long) {
|
|
18
20
|
setLong(true);
|
|
19
21
|
}
|
|
@@ -26,11 +28,28 @@ export const LongValue = ({ value, className }) => {
|
|
|
26
28
|
setOpen(false);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
|
|
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);
|
|
30
48
|
}
|
|
31
49
|
}
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
return;
|
|
51
|
+
}, [value]);
|
|
52
|
+
return (React.createElement(Text, Object.assign({ as: "div" }, restProps, { ref: ref, className: b({ open, long }, className),
|
|
34
53
|
// @ts-ignore
|
|
35
|
-
onClick: long ? handleClick : undefined }, value));
|
|
54
|
+
onClick: long ? handleClick : undefined }), value));
|
|
36
55
|
};
|