@gravity-ui/dynamic-forms 5.14.0 → 5.15.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/build/cjs/lib/kit/components/Inputs/TextContent/TextContent.css +3 -1
- package/build/cjs/lib/kit/components/Inputs/TextContent/TextContent.js +8 -3
- package/build/cjs/lib/kit/components/Inputs/TextContent/utils.js +5 -1
- package/build/cjs/lib/kit/components/Views/TextContentView.js +4 -3
- package/build/esm/lib/kit/components/Inputs/TextContent/TextContent.css +3 -1
- package/build/esm/lib/kit/components/Inputs/TextContent/TextContent.js +9 -4
- package/build/esm/lib/kit/components/Inputs/TextContent/utils.d.ts +2 -0
- package/build/esm/lib/kit/components/Inputs/TextContent/utils.js +3 -0
- package/build/esm/lib/kit/components/Views/TextContentView.js +4 -3
- package/package.json +1 -1
|
@@ -26,9 +26,11 @@
|
|
|
26
26
|
white-space: initial;
|
|
27
27
|
line-height: var(--_--height);
|
|
28
28
|
}
|
|
29
|
-
.df-text-content__icon {
|
|
29
|
+
.df-text-content__icon, .df-text-content__alert-icon {
|
|
30
30
|
display: flex;
|
|
31
31
|
align-items: center;
|
|
32
|
+
}
|
|
33
|
+
.df-text-content__icon {
|
|
32
34
|
margin-right: var(--df-text-content-icon-margin-right, var(--g-spacing-1));
|
|
33
35
|
}
|
|
34
36
|
.df-text-content__wrapper {
|
|
@@ -14,18 +14,23 @@ const TextContentComponent = ({ spec, value, Layout, }) => {
|
|
|
14
14
|
var _a;
|
|
15
15
|
const { textContentParams, layoutDescription } = spec.viewSpec;
|
|
16
16
|
const text = react_1.default.useMemo(() => ((textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text) ? textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text : layoutDescription), [layoutDescription, textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text]);
|
|
17
|
+
const iconName = textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon;
|
|
18
|
+
const alertView = textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.viewAlert;
|
|
19
|
+
const hasIconParam = typeof iconName === 'string';
|
|
20
|
+
const IconComponent = react_1.default.useMemo(() => (iconName ? (0, utils_2.loadIcon)(iconName) : undefined), [iconName]);
|
|
21
|
+
const iconLib = react_1.default.useMemo(() => (IconComponent ? react_1.default.createElement(LazyLoader_1.LazyLoader, { component: IconComponent }) : null), [IconComponent]);
|
|
22
|
+
const alertIcon = react_1.default.useMemo(() => (iconLib ? react_1.default.createElement("span", { className: b('alert-icon') }, iconLib) : null), [iconLib]);
|
|
17
23
|
if (!text) {
|
|
18
24
|
return null;
|
|
19
25
|
}
|
|
20
|
-
const iconLib = (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) ? (react_1.default.createElement(LazyLoader_1.LazyLoader, { component: (0, utils_2.loadIcon)(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) })) : undefined;
|
|
21
26
|
let content = react_1.default.createElement("span", { dangerouslySetInnerHTML: { __html: text } });
|
|
22
27
|
if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert) {
|
|
23
28
|
const titleAlert = (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.titleAlert) || !(0, lodash_1.isEmpty)(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.titleAlert)
|
|
24
29
|
? textContentParams.titleAlert
|
|
25
30
|
: undefined;
|
|
26
|
-
content = (react_1.default.createElement(uikit_1.Alert, { icon:
|
|
31
|
+
content = (react_1.default.createElement(uikit_1.Alert, Object.assign({}, (alertIcon || hasIconParam ? { icon: alertIcon } : {}), { message: content,
|
|
27
32
|
// If the title is an empty line, then you need to explicitly write undefined, otherwise there will be an additional indent
|
|
28
|
-
title: titleAlert, theme: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert, view:
|
|
33
|
+
title: titleAlert, theme: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert, view: (0, utils_2.isAlertView)(alertView) ? alertView : undefined })));
|
|
29
34
|
}
|
|
30
35
|
else if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeLabel) {
|
|
31
36
|
content = (react_1.default.createElement(uikit_1.Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value: value, icon: iconLib }, content));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadIcon = void 0;
|
|
3
|
+
exports.isAlertView = exports.loadIcon = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const loadIcon = (name) => {
|
|
@@ -20,3 +20,7 @@ const loadIcon = (name) => {
|
|
|
20
20
|
return Icon;
|
|
21
21
|
};
|
|
22
22
|
exports.loadIcon = loadIcon;
|
|
23
|
+
const isAlertView = (view) => {
|
|
24
|
+
return view === 'filled' || view === 'outlined';
|
|
25
|
+
};
|
|
26
|
+
exports.isAlertView = isAlertView;
|
|
@@ -5,16 +5,17 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
6
|
const Inputs_1 = require("../Inputs");
|
|
7
7
|
const TextContentView = ({ name, spec, Layout, value }) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const layoutValue = ((_a = spec.viewSpec.textContentParams) === null || _a === void 0 ? void 0 : _a.text) || spec.viewSpec.layoutDescription || value;
|
|
8
10
|
const WrappedLayout = react_1.default.useMemo(() => {
|
|
9
11
|
if (Layout) {
|
|
10
12
|
const Component = (props) => {
|
|
11
|
-
|
|
12
|
-
return react_1.default.createElement(Layout, Object.assign({ name: name, value: VALUE_STUB }, props));
|
|
13
|
+
return react_1.default.createElement(Layout, Object.assign({ name: name, value: layoutValue }, props));
|
|
13
14
|
};
|
|
14
15
|
return Component;
|
|
15
16
|
}
|
|
16
17
|
return undefined;
|
|
17
|
-
}, [Layout, name]);
|
|
18
|
+
}, [Layout, layoutValue, name]);
|
|
18
19
|
return react_1.default.createElement(Inputs_1.TextContentComponent, { spec: spec, value: value, Layout: WrappedLayout });
|
|
19
20
|
};
|
|
20
21
|
exports.TextContentView = TextContentView;
|
|
@@ -26,9 +26,11 @@
|
|
|
26
26
|
white-space: initial;
|
|
27
27
|
line-height: var(--_--height);
|
|
28
28
|
}
|
|
29
|
-
.df-text-content__icon {
|
|
29
|
+
.df-text-content__icon, .df-text-content__alert-icon {
|
|
30
30
|
display: flex;
|
|
31
31
|
align-items: center;
|
|
32
|
+
}
|
|
33
|
+
.df-text-content__icon {
|
|
32
34
|
margin-right: var(--df-text-content-icon-margin-right, var(--g-spacing-1));
|
|
33
35
|
}
|
|
34
36
|
.df-text-content__wrapper {
|
|
@@ -4,25 +4,30 @@ import { isEmpty } from 'lodash';
|
|
|
4
4
|
import cloneDeep from 'lodash/cloneDeep';
|
|
5
5
|
import { block } from '../../../utils';
|
|
6
6
|
import { LazyLoader } from '../../LazyLoader';
|
|
7
|
-
import { loadIcon } from './utils';
|
|
7
|
+
import { isAlertView, loadIcon } from './utils';
|
|
8
8
|
import './TextContent.css';
|
|
9
9
|
const b = block('text-content');
|
|
10
10
|
export const TextContentComponent = ({ spec, value, Layout, }) => {
|
|
11
11
|
var _a;
|
|
12
12
|
const { textContentParams, layoutDescription } = spec.viewSpec;
|
|
13
13
|
const text = React.useMemo(() => ((textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text) ? textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text : layoutDescription), [layoutDescription, textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.text]);
|
|
14
|
+
const iconName = textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon;
|
|
15
|
+
const alertView = textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.viewAlert;
|
|
16
|
+
const hasIconParam = typeof iconName === 'string';
|
|
17
|
+
const IconComponent = React.useMemo(() => (iconName ? loadIcon(iconName) : undefined), [iconName]);
|
|
18
|
+
const iconLib = React.useMemo(() => (IconComponent ? React.createElement(LazyLoader, { component: IconComponent }) : null), [IconComponent]);
|
|
19
|
+
const alertIcon = React.useMemo(() => (iconLib ? React.createElement("span", { className: b('alert-icon') }, iconLib) : null), [iconLib]);
|
|
14
20
|
if (!text) {
|
|
15
21
|
return null;
|
|
16
22
|
}
|
|
17
|
-
const iconLib = (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) ? (React.createElement(LazyLoader, { component: loadIcon(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.icon) })) : undefined;
|
|
18
23
|
let content = React.createElement("span", { dangerouslySetInnerHTML: { __html: text } });
|
|
19
24
|
if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert) {
|
|
20
25
|
const titleAlert = (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.titleAlert) || !isEmpty(textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.titleAlert)
|
|
21
26
|
? textContentParams.titleAlert
|
|
22
27
|
: undefined;
|
|
23
|
-
content = (React.createElement(Alert, { icon:
|
|
28
|
+
content = (React.createElement(Alert, Object.assign({}, (alertIcon || hasIconParam ? { icon: alertIcon } : {}), { message: content,
|
|
24
29
|
// If the title is an empty line, then you need to explicitly write undefined, otherwise there will be an additional indent
|
|
25
|
-
title: titleAlert, theme: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert, view:
|
|
30
|
+
title: titleAlert, theme: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert, view: isAlertView(alertView) ? alertView : undefined })));
|
|
26
31
|
}
|
|
27
32
|
else if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeLabel) {
|
|
28
33
|
content = (React.createElement(Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value: value, icon: iconLib }, content));
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TextContentComponent } from '../Inputs';
|
|
3
3
|
export const TextContentView = ({ name, spec, Layout, value }) => {
|
|
4
|
+
var _a;
|
|
5
|
+
const layoutValue = ((_a = spec.viewSpec.textContentParams) === null || _a === void 0 ? void 0 : _a.text) || spec.viewSpec.layoutDescription || value;
|
|
4
6
|
const WrappedLayout = React.useMemo(() => {
|
|
5
7
|
if (Layout) {
|
|
6
8
|
const Component = (props) => {
|
|
7
|
-
|
|
8
|
-
return React.createElement(Layout, Object.assign({ name: name, value: VALUE_STUB }, props));
|
|
9
|
+
return React.createElement(Layout, Object.assign({ name: name, value: layoutValue }, props));
|
|
9
10
|
};
|
|
10
11
|
return Component;
|
|
11
12
|
}
|
|
12
13
|
return undefined;
|
|
13
|
-
}, [Layout, name]);
|
|
14
|
+
}, [Layout, layoutValue, name]);
|
|
14
15
|
return React.createElement(TextContentComponent, { spec: spec, value: value, Layout: WrappedLayout });
|
|
15
16
|
};
|