@gravity-ui/dynamic-forms 5.0.0-beta.0 → 5.0.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/CardOneOf/CardOneOf.js +8 -2
- package/build/cjs/lib/kit/components/Inputs/TextContent/TextContent.js +1 -1
- package/build/cjs/lib/kit/components/Layouts/Accordeon/Accordeon.js +2 -1
- package/build/cjs/lib/kit/components/Layouts/Section/Section.js +21 -2
- package/build/cjs/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.js +2 -2
- package/build/cjs/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -1
- package/build/cjs/lib/kit/components/Views/CardOneOfView.js +13 -3
- package/build/cjs/lib/kit/utils/common.js +9 -8
- package/build/esm/lib/core/components/View/types/layout.d.ts +1 -1
- package/build/esm/lib/core/components/View/types/views.d.ts +1 -1
- package/build/esm/lib/core/types/specs.d.ts +2 -1
- package/build/esm/lib/kit/components/Inputs/CardOneOf/CardOneOf.js +8 -2
- package/build/esm/lib/kit/components/Inputs/TextContent/TextContent.js +1 -1
- package/build/esm/lib/kit/components/Layouts/Accordeon/Accordeon.d.ts +6 -1
- package/build/esm/lib/kit/components/Layouts/Accordeon/Accordeon.js +2 -1
- package/build/esm/lib/kit/components/Layouts/Section/Section.js +21 -2
- package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.d.ts +2 -0
- package/build/esm/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.js +2 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.d.ts +7 -2
- package/build/esm/lib/kit/components/ViewLayouts/ViewAccordeon/ViewAccordeon.js +2 -1
- package/build/esm/lib/kit/components/Views/CardOneOfView.js +13 -3
- package/build/esm/lib/kit/utils/common.js +9 -8
- package/package.json +4 -4
|
@@ -11,7 +11,7 @@ const Layouts_1 = require("../../Layouts");
|
|
|
11
11
|
const RemoveButton_1 = require("../../RemoveButton");
|
|
12
12
|
const CardOneOf = (props) => {
|
|
13
13
|
var _a;
|
|
14
|
-
const { input, meta, spec, name } = props;
|
|
14
|
+
const { input, meta, spec, name, Layout } = props;
|
|
15
15
|
const [open, setOpen] = react_1.default.useState(true);
|
|
16
16
|
const onToggle = react_1.default.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
17
17
|
const onOpen = react_1.default.useCallback(() => setOpen(true), [setOpen]);
|
|
@@ -19,7 +19,13 @@ const CardOneOf = (props) => {
|
|
|
19
19
|
props,
|
|
20
20
|
onTogglerChange: onOpen,
|
|
21
21
|
});
|
|
22
|
-
const toggler = react_1.default.useMemo(() =>
|
|
22
|
+
const toggler = react_1.default.useMemo(() => {
|
|
23
|
+
const togglerProps = Object.assign(Object.assign({}, props), { name: '__stub-name', children: togglerInput });
|
|
24
|
+
if (Layout) {
|
|
25
|
+
return react_1.default.createElement(Layout, Object.assign({}, togglerProps));
|
|
26
|
+
}
|
|
27
|
+
return react_1.default.createElement(Layouts_1.Row, Object.assign({}, togglerProps));
|
|
28
|
+
}, [togglerInput, props, Layout]);
|
|
23
29
|
const actions = react_1.default.useMemo(() => {
|
|
24
30
|
if ((0, core_1.isArrayItem)(name)) {
|
|
25
31
|
return react_1.default.createElement(RemoveButton_1.RemoveButton, { onDrop: input.onDrop, name: name });
|
|
@@ -25,7 +25,7 @@ const TextContentComponent = ({ spec, value, Layout, }) => {
|
|
|
25
25
|
: undefined;
|
|
26
26
|
content = (react_1.default.createElement(uikit_1.Alert, { icon: iconLib, message: content,
|
|
27
27
|
// 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 }));
|
|
28
|
+
title: titleAlert, theme: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert, view: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.viewAlert }));
|
|
29
29
|
}
|
|
30
30
|
else if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeLabel) {
|
|
31
31
|
content = (react_1.default.createElement(uikit_1.Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value: value, icon: iconLib }, content));
|
|
@@ -10,6 +10,7 @@ const RemoveButton_1 = require("../../RemoveButton");
|
|
|
10
10
|
const SimpleVerticalAccordeon_1 = require("../../SimpleVerticalAccordeon");
|
|
11
11
|
const Accordeon = ({ name, spec, input, meta, children, }) => {
|
|
12
12
|
var _a;
|
|
13
|
+
const { variantTitle } = spec.viewSpec.layoutProps || {};
|
|
13
14
|
const [open, setOpen] = react_1.default.useState(Boolean((_a = spec.viewSpec) === null || _a === void 0 ? void 0 : _a.layoutOpen));
|
|
14
15
|
const onDrop = react_1.default.useCallback(() => {
|
|
15
16
|
setOpen(false);
|
|
@@ -22,7 +23,7 @@ const Accordeon = ({ name, spec, input, meta, children, }) => {
|
|
|
22
23
|
return react_1.default.createElement(RemoveButton_1.RemoveButton, { name: name, onDrop: onDrop });
|
|
23
24
|
}, [spec.required, input.value, onDrop, name]);
|
|
24
25
|
(0, hooks_1.useErrorChecker)({ name, meta, open, setOpen });
|
|
25
|
-
return (react_1.default.createElement(SimpleVerticalAccordeon_1.SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', note: spec.viewSpec.layoutDescription || '', open: open, onOpenChange: setOpen, headerActionsTemplate: removeButton, hideInsteadOfDestroy: true, withBranchView: true },
|
|
26
|
+
return (react_1.default.createElement(SimpleVerticalAccordeon_1.SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', note: spec.viewSpec.layoutDescription || '', open: open, onOpenChange: setOpen, headerActionsTemplate: removeButton, hideInsteadOfDestroy: true, withBranchView: true, variantTitle: variantTitle },
|
|
26
27
|
react_1.default.createElement(components_1.ErrorWrapper, { name: name, meta: meta, withoutChildErrorStyles: true }, children)));
|
|
27
28
|
};
|
|
28
29
|
exports.Accordeon = Accordeon;
|
|
@@ -18,6 +18,25 @@ const SectionBase = (_a) => {
|
|
|
18
18
|
const arrOrObjFlag = (0, core_1.isArraySpec)(spec) || (0, core_1.isObjectSpec)(spec);
|
|
19
19
|
const titleRef = react_1.default.useRef(null);
|
|
20
20
|
let content = children;
|
|
21
|
+
const { variantTitle: variantTitleProp } = spec.viewSpec.layoutProps || {};
|
|
22
|
+
const { sizeTitle, variantTitle } = react_1.default.useMemo(() => {
|
|
23
|
+
if (variantTitleProp) {
|
|
24
|
+
return {
|
|
25
|
+
sizeTitle: undefined,
|
|
26
|
+
variantTitle: variantTitleProp,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (titleSize === 'm') {
|
|
30
|
+
return {
|
|
31
|
+
sizeTitle: titleSize,
|
|
32
|
+
variantTitle: 'body-2',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
sizeTitle: titleSize,
|
|
37
|
+
variantTitle: 'body-1',
|
|
38
|
+
};
|
|
39
|
+
}, [variantTitleProp, titleSize]);
|
|
21
40
|
const removeButton = react_1.default.useMemo(() => {
|
|
22
41
|
if ((input === null || input === void 0 ? void 0 : input.value) && (input === null || input === void 0 ? void 0 : input.onDrop) && (0, core_1.isArrayItem)(name)) {
|
|
23
42
|
return (react_1.default.createElement(RemoveButton_1.RemoveButton, { name: name, onDrop: input.onDrop, switcherClassName: b('remove-button') }));
|
|
@@ -49,10 +68,10 @@ const SectionBase = (_a) => {
|
|
|
49
68
|
return (react_1.default.createElement("section", { className: b() },
|
|
50
69
|
layoutTitle ? (react_1.default.createElement("div", { className: b('header', {
|
|
51
70
|
'with-popover': !descriptionAsSubtitle,
|
|
52
|
-
size:
|
|
71
|
+
size: sizeTitle,
|
|
53
72
|
}) },
|
|
54
73
|
react_1.default.createElement(uikit_1.Popover, { className: b('popover'), content: layoutTitle, placement: __2.COMMON_POPOVER_PLACEMENT, disabled: layoutTitlePopoverDisabled },
|
|
55
|
-
react_1.default.createElement(uikit_1.Text, { className: b('title'), variant:
|
|
74
|
+
react_1.default.createElement(uikit_1.Text, { className: b('title'), variant: variantTitle, ref: titleRef, ellipsis: true }, layoutTitle)),
|
|
56
75
|
description,
|
|
57
76
|
removeButton)) : null,
|
|
58
77
|
react_1.default.createElement("div", { className: b('content') }, content)));
|
|
@@ -51,7 +51,7 @@ class SimpleVerticalAccordeon extends react_1.default.Component {
|
|
|
51
51
|
}
|
|
52
52
|
render() {
|
|
53
53
|
var _a;
|
|
54
|
-
const { children, headerActionsTemplate, className, contentClassName, buttonClassName, hideInsteadOfDestroy, withBranchView, viewLayout, name, } = this.props;
|
|
54
|
+
const { children, headerActionsTemplate, className, contentClassName, buttonClassName, hideInsteadOfDestroy, withBranchView, viewLayout, name, variantTitle, } = this.props;
|
|
55
55
|
const { open, hidden, isFirstRender } = this.state;
|
|
56
56
|
const content = hideInsteadOfDestroy ? (react_1.default.createElement("div", { ref: this.componentRef, className: b('body', { hidden: !open }) }, children)) : (open && (react_1.default.createElement("div", { ref: this.componentRef, className: b('body', contentClassName) }, children)));
|
|
57
57
|
if (viewLayout && !isFirstRender && hidden) {
|
|
@@ -59,7 +59,7 @@ class SimpleVerticalAccordeon extends react_1.default.Component {
|
|
|
59
59
|
}
|
|
60
60
|
const title = this.getTitle();
|
|
61
61
|
const titlePopoverDisabled = (((_a = this.titleRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0) <= TITLE_TEXT_MAX_WIDTH;
|
|
62
|
-
const currentTitleVariant = this.getCurrentTitleVariant();
|
|
62
|
+
const currentTitleVariant = variantTitle || this.getCurrentTitleVariant();
|
|
63
63
|
return (Boolean(react_1.default.Children.count(children)) && (react_1.default.createElement("div", { className: b({ branch: withBranchView, view: viewLayout }, className) },
|
|
64
64
|
react_1.default.createElement("div", { className: b('header') },
|
|
65
65
|
react_1.default.createElement(uikit_1.Popover, { content: title, disabled: titlePopoverDisabled, placement: common_1.COMMON_POPOVER_PLACEMENT, className: b('popover'), hasArrow: true },
|
|
@@ -10,11 +10,12 @@ const SimpleVerticalAccordeon_1 = require("../../SimpleVerticalAccordeon");
|
|
|
10
10
|
const ViewAccordeon = ({ name, value, spec, children, }) => {
|
|
11
11
|
const { showLayoutDescription } = (0, core_1.useDynamicFormsCtx)();
|
|
12
12
|
const [open, setOpen] = react_1.default.useState((0, isBoolean_1.default)(spec.viewSpec.layoutOpen) ? spec.viewSpec.layoutOpen : true);
|
|
13
|
+
const { variantTitle } = spec.viewSpec.layoutProps || {};
|
|
13
14
|
if (!(0, utils_1.isNotEmptyValue)(value, spec)) {
|
|
14
15
|
return null;
|
|
15
16
|
}
|
|
16
17
|
return (react_1.default.createElement(SimpleVerticalAccordeon_1.SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', note: showLayoutDescription && spec.viewSpec.layoutDescription
|
|
17
18
|
? spec.viewSpec.layoutDescription
|
|
18
|
-
: undefined, open: open, onOpenChange: setOpen, hideInsteadOfDestroy: true, withBranchView: true, viewLayout: true }, children));
|
|
19
|
+
: undefined, open: open, onOpenChange: setOpen, hideInsteadOfDestroy: true, withBranchView: true, viewLayout: true, variantTitle: variantTitle }, children));
|
|
19
20
|
};
|
|
20
21
|
exports.ViewAccordeon = ViewAccordeon;
|
|
@@ -7,7 +7,7 @@ const isObjectLike_1 = tslib_1.__importDefault(require("lodash/isObjectLike"));
|
|
|
7
7
|
const __1 = require("../");
|
|
8
8
|
const core_1 = require("../../../core");
|
|
9
9
|
const CardOneOfView = (props) => {
|
|
10
|
-
const { value = {}, spec, name } = props;
|
|
10
|
+
const { value = {}, spec, name, Layout } = props;
|
|
11
11
|
const [open, setOpen] = react_1.default.useState(true);
|
|
12
12
|
const onToggle = react_1.default.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
13
13
|
const specProperties = react_1.default.useMemo(() => ((0, isObjectLike_1.default)(spec.properties) ? spec.properties : {}), [spec.properties]);
|
|
@@ -18,8 +18,18 @@ const CardOneOfView = (props) => {
|
|
|
18
18
|
((_b = specProperties[valueKey]) === null || _b === void 0 ? void 0 : _b.viewSpec.layoutTitle) ||
|
|
19
19
|
valueKey);
|
|
20
20
|
}, [valueKey, spec.description, specProperties]);
|
|
21
|
-
const title = react_1.default.useMemo(() =>
|
|
22
|
-
|
|
21
|
+
const title = react_1.default.useMemo(() => {
|
|
22
|
+
const titleProps = {
|
|
23
|
+
spec: spec,
|
|
24
|
+
value: valueName,
|
|
25
|
+
name: name,
|
|
26
|
+
children: react_1.default.createElement(react_1.default.Fragment, null, valueName),
|
|
27
|
+
};
|
|
28
|
+
if (Layout) {
|
|
29
|
+
return react_1.default.createElement(Layout, Object.assign({}, titleProps));
|
|
30
|
+
}
|
|
31
|
+
return react_1.default.createElement(__1.ViewRow, Object.assign({}, titleProps));
|
|
32
|
+
}, [spec, name, valueName, Layout]);
|
|
23
33
|
if (!value || !Object.keys(value).length) {
|
|
24
34
|
return null;
|
|
25
35
|
}
|
|
@@ -42,7 +42,7 @@ const isNotEmptyValue = (value, spec) => {
|
|
|
42
42
|
};
|
|
43
43
|
exports.isNotEmptyValue = isNotEmptyValue;
|
|
44
44
|
const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) => {
|
|
45
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
46
46
|
if ((0, isObjectLike_1.default)(spec)) {
|
|
47
47
|
const result = (0, cloneDeep_1.default)(spec);
|
|
48
48
|
if ((0, isString_1.default)(result.type)) {
|
|
@@ -54,7 +54,7 @@ const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) => {
|
|
|
54
54
|
try {
|
|
55
55
|
_defaultValue = JSON.parse(result.defaultValue);
|
|
56
56
|
}
|
|
57
|
-
catch (
|
|
57
|
+
catch (_m) {
|
|
58
58
|
_defaultValue = undefined;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -75,20 +75,21 @@ const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) => {
|
|
|
75
75
|
if ((0, isString_1.default)((_c = result.viewSpec) === null || _c === void 0 ? void 0 : _c.addButtonPosition)) {
|
|
76
76
|
result.viewSpec.addButtonPosition = result.viewSpec.addButtonPosition.toLowerCase();
|
|
77
77
|
}
|
|
78
|
-
if ((0, isString_1.default)((_d = result.viewSpec) === null || _d === void 0 ? void 0 : _d.
|
|
79
|
-
result.viewSpec.textContentParams = Object.assign(Object.assign({}, result.viewSpec.textContentParams), { themeLabel: result.viewSpec.themeLabel.toLowerCase() });
|
|
80
|
-
}
|
|
81
|
-
if ((0, isString_1.default)((_f = (_e = result.viewSpec) === null || _e === void 0 ? void 0 : _e.oneOfParams) === null || _f === void 0 ? void 0 : _f.toggler)) {
|
|
78
|
+
if ((0, isString_1.default)((_e = (_d = result.viewSpec) === null || _d === void 0 ? void 0 : _d.oneOfParams) === null || _e === void 0 ? void 0 : _e.toggler)) {
|
|
82
79
|
result.viewSpec.oneOfParams.toggler = result.viewSpec.oneOfParams.toggler.toLowerCase();
|
|
83
80
|
}
|
|
84
|
-
if ((0, isString_1.default)((
|
|
81
|
+
if ((0, isString_1.default)((_g = (_f = result.viewSpec) === null || _f === void 0 ? void 0 : _f.textContentParams) === null || _g === void 0 ? void 0 : _g.themeLabel)) {
|
|
85
82
|
result.viewSpec.textContentParams.themeLabel =
|
|
86
83
|
result.viewSpec.textContentParams.themeLabel.toLowerCase();
|
|
87
84
|
}
|
|
88
|
-
if ((0, isString_1.default)((
|
|
85
|
+
if ((0, isString_1.default)((_j = (_h = result.viewSpec) === null || _h === void 0 ? void 0 : _h.textContentParams) === null || _j === void 0 ? void 0 : _j.themeAlert)) {
|
|
89
86
|
result.viewSpec.textContentParams.themeAlert =
|
|
90
87
|
result.viewSpec.textContentParams.themeAlert.toLowerCase();
|
|
91
88
|
}
|
|
89
|
+
if ((0, isString_1.default)((_l = (_k = result.viewSpec) === null || _k === void 0 ? void 0 : _k.textContentParams) === null || _l === void 0 ? void 0 : _l.viewAlert)) {
|
|
90
|
+
result.viewSpec.textContentParams.viewAlert =
|
|
91
|
+
result.viewSpec.textContentParams.viewAlert.toLowerCase();
|
|
92
|
+
}
|
|
92
93
|
if ((0, isString_1.default)(result.validator)) {
|
|
93
94
|
result.validator = result.validator.toLowerCase();
|
|
94
95
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FormValue, Spec } from '../../../';
|
|
3
3
|
import { ViewProps } from './';
|
|
4
|
-
export type ViewLayoutProps<Value extends FormValue, SpecType extends Spec> = {
|
|
4
|
+
export type ViewLayoutProps<Value extends FormValue, SpecType extends Spec<undefined, undefined, Record<string, any> | undefined> = Spec> = {
|
|
5
5
|
children: React.ReactElement;
|
|
6
6
|
} & ViewProps<Value, SpecType>;
|
|
7
7
|
export type ViewLayoutType<Value extends FormValue, SpecType extends Spec> = (props: ViewLayoutProps<Value, SpecType>) => React.ReactElement | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FormValue, Spec } from '../../../';
|
|
3
3
|
import { ViewLayoutType } from './';
|
|
4
|
-
export type ViewProps<Value extends FormValue, SpecType extends Spec> = {
|
|
4
|
+
export type ViewProps<Value extends FormValue, SpecType extends Spec<undefined, undefined, Record<string, any> | undefined> = Spec> = {
|
|
5
5
|
spec: SpecType;
|
|
6
6
|
name: string;
|
|
7
7
|
value?: Value;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AlertProps, LabelProps } from '@gravity-ui/uikit';
|
|
1
|
+
import type { AlertProps, LabelProps } from '@gravity-ui/uikit';
|
|
2
2
|
import { ColorTextBaseProps } from '@gravity-ui/uikit/build/esm/components/Text/colorText/colorText';
|
|
3
3
|
import { ReadAsMethod, SpecTypes } from '../constants';
|
|
4
4
|
import { ArrayValue, ObjectValue } from './';
|
|
@@ -151,6 +151,7 @@ export interface StringSpec<LinkType = any, InputComponentProps extends Record<s
|
|
|
151
151
|
iconColor?: ColorTextBaseProps['color'];
|
|
152
152
|
titleAlert?: string;
|
|
153
153
|
themeAlert?: AlertProps['theme'];
|
|
154
|
+
viewAlert?: AlertProps['view'];
|
|
154
155
|
};
|
|
155
156
|
fileInput?: {
|
|
156
157
|
accept?: string;
|
|
@@ -7,7 +7,7 @@ import { Row } from '../../Layouts';
|
|
|
7
7
|
import { RemoveButton } from '../../RemoveButton';
|
|
8
8
|
export const CardOneOf = (props) => {
|
|
9
9
|
var _a;
|
|
10
|
-
const { input, meta, spec, name } = props;
|
|
10
|
+
const { input, meta, spec, name, Layout } = props;
|
|
11
11
|
const [open, setOpen] = React.useState(true);
|
|
12
12
|
const onToggle = React.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
13
13
|
const onOpen = React.useCallback(() => setOpen(true), [setOpen]);
|
|
@@ -15,7 +15,13 @@ export const CardOneOf = (props) => {
|
|
|
15
15
|
props,
|
|
16
16
|
onTogglerChange: onOpen,
|
|
17
17
|
});
|
|
18
|
-
const toggler = React.useMemo(() =>
|
|
18
|
+
const toggler = React.useMemo(() => {
|
|
19
|
+
const togglerProps = Object.assign(Object.assign({}, props), { name: '__stub-name', children: togglerInput });
|
|
20
|
+
if (Layout) {
|
|
21
|
+
return React.createElement(Layout, Object.assign({}, togglerProps));
|
|
22
|
+
}
|
|
23
|
+
return React.createElement(Row, Object.assign({}, togglerProps));
|
|
24
|
+
}, [togglerInput, props, Layout]);
|
|
19
25
|
const actions = React.useMemo(() => {
|
|
20
26
|
if (isArrayItem(name)) {
|
|
21
27
|
return React.createElement(RemoveButton, { onDrop: input.onDrop, name: name });
|
|
@@ -22,7 +22,7 @@ export const TextContentComponent = ({ spec, value, Layout, }) => {
|
|
|
22
22
|
: undefined;
|
|
23
23
|
content = (React.createElement(Alert, { icon: iconLib, message: content,
|
|
24
24
|
// 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 }));
|
|
25
|
+
title: titleAlert, theme: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeAlert, view: textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.viewAlert }));
|
|
26
26
|
}
|
|
27
27
|
else if (textContentParams === null || textContentParams === void 0 ? void 0 : textContentParams.themeLabel) {
|
|
28
28
|
content = (React.createElement(Label, { size: "m", theme: textContentParams.themeLabel, className: b(), value: value, icon: iconLib }, content));
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import { TextProps } from '@gravity-ui/uikit';
|
|
1
2
|
import { ArrayLayoutProps, ObjectLayoutProps } from '../../../../core';
|
|
2
|
-
|
|
3
|
+
interface AccordeonLayoutProps {
|
|
4
|
+
variantTitle?: TextProps['variant'];
|
|
5
|
+
}
|
|
6
|
+
export declare const Accordeon: <T extends ArrayLayoutProps<Record<string, any> | undefined, AccordeonLayoutProps | undefined> | ObjectLayoutProps<Record<string, any> | undefined, AccordeonLayoutProps | undefined>>({ name, spec, input, meta, children, }: T) => JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -6,6 +6,7 @@ import { RemoveButton } from '../../RemoveButton';
|
|
|
6
6
|
import { SimpleVerticalAccordeon } from '../../SimpleVerticalAccordeon';
|
|
7
7
|
export const Accordeon = ({ name, spec, input, meta, children, }) => {
|
|
8
8
|
var _a;
|
|
9
|
+
const { variantTitle } = spec.viewSpec.layoutProps || {};
|
|
9
10
|
const [open, setOpen] = React.useState(Boolean((_a = spec.viewSpec) === null || _a === void 0 ? void 0 : _a.layoutOpen));
|
|
10
11
|
const onDrop = React.useCallback(() => {
|
|
11
12
|
setOpen(false);
|
|
@@ -18,6 +19,6 @@ export const Accordeon = ({ name, spec, input, meta, children, }) => {
|
|
|
18
19
|
return React.createElement(RemoveButton, { name: name, onDrop: onDrop });
|
|
19
20
|
}, [spec.required, input.value, onDrop, name]);
|
|
20
21
|
useErrorChecker({ name, meta, open, setOpen });
|
|
21
|
-
return (React.createElement(SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', note: spec.viewSpec.layoutDescription || '', open: open, onOpenChange: setOpen, headerActionsTemplate: removeButton, hideInsteadOfDestroy: true, withBranchView: true },
|
|
22
|
+
return (React.createElement(SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', note: spec.viewSpec.layoutDescription || '', open: open, onOpenChange: setOpen, headerActionsTemplate: removeButton, hideInsteadOfDestroy: true, withBranchView: true, variantTitle: variantTitle },
|
|
22
23
|
React.createElement(ErrorWrapper, { name: name, meta: meta, withoutChildErrorStyles: true }, children)));
|
|
23
24
|
};
|
|
@@ -16,6 +16,25 @@ const SectionBase = (_a) => {
|
|
|
16
16
|
const arrOrObjFlag = isArraySpec(spec) || isObjectSpec(spec);
|
|
17
17
|
const titleRef = React.useRef(null);
|
|
18
18
|
let content = children;
|
|
19
|
+
const { variantTitle: variantTitleProp } = spec.viewSpec.layoutProps || {};
|
|
20
|
+
const { sizeTitle, variantTitle } = React.useMemo(() => {
|
|
21
|
+
if (variantTitleProp) {
|
|
22
|
+
return {
|
|
23
|
+
sizeTitle: undefined,
|
|
24
|
+
variantTitle: variantTitleProp,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (titleSize === 'm') {
|
|
28
|
+
return {
|
|
29
|
+
sizeTitle: titleSize,
|
|
30
|
+
variantTitle: 'body-2',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
sizeTitle: titleSize,
|
|
35
|
+
variantTitle: 'body-1',
|
|
36
|
+
};
|
|
37
|
+
}, [variantTitleProp, titleSize]);
|
|
19
38
|
const removeButton = React.useMemo(() => {
|
|
20
39
|
if ((input === null || input === void 0 ? void 0 : input.value) && (input === null || input === void 0 ? void 0 : input.onDrop) && isArrayItem(name)) {
|
|
21
40
|
return (React.createElement(RemoveButton, { name: name, onDrop: input.onDrop, switcherClassName: b('remove-button') }));
|
|
@@ -47,10 +66,10 @@ const SectionBase = (_a) => {
|
|
|
47
66
|
return (React.createElement("section", { className: b() },
|
|
48
67
|
layoutTitle ? (React.createElement("div", { className: b('header', {
|
|
49
68
|
'with-popover': !descriptionAsSubtitle,
|
|
50
|
-
size:
|
|
69
|
+
size: sizeTitle,
|
|
51
70
|
}) },
|
|
52
71
|
React.createElement(Popover, { className: b('popover'), content: layoutTitle, placement: COMMON_POPOVER_PLACEMENT, disabled: layoutTitlePopoverDisabled },
|
|
53
|
-
React.createElement(Text, { className: b('title'), variant:
|
|
72
|
+
React.createElement(Text, { className: b('title'), variant: variantTitle, ref: titleRef, ellipsis: true }, layoutTitle)),
|
|
54
73
|
description,
|
|
55
74
|
removeButton)) : null,
|
|
56
75
|
React.createElement("div", { className: b('content') }, content)));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { TextProps } from '@gravity-ui/uikit';
|
|
2
3
|
import './SimpleVerticalAccordeon.css';
|
|
3
4
|
interface SimpleVerticalAccordeonProps {
|
|
4
5
|
children: React.ReactNode;
|
|
@@ -16,6 +17,7 @@ interface SimpleVerticalAccordeonProps {
|
|
|
16
17
|
hideInsteadOfDestroy?: boolean;
|
|
17
18
|
withBranchView?: boolean;
|
|
18
19
|
viewLayout?: boolean;
|
|
20
|
+
variantTitle?: TextProps['variant'];
|
|
19
21
|
}
|
|
20
22
|
interface SimpleVerticalAccordeonState {
|
|
21
23
|
open: boolean;
|
|
@@ -48,7 +48,7 @@ export class SimpleVerticalAccordeon extends React.Component {
|
|
|
48
48
|
}
|
|
49
49
|
render() {
|
|
50
50
|
var _a;
|
|
51
|
-
const { children, headerActionsTemplate, className, contentClassName, buttonClassName, hideInsteadOfDestroy, withBranchView, viewLayout, name, } = this.props;
|
|
51
|
+
const { children, headerActionsTemplate, className, contentClassName, buttonClassName, hideInsteadOfDestroy, withBranchView, viewLayout, name, variantTitle, } = this.props;
|
|
52
52
|
const { open, hidden, isFirstRender } = this.state;
|
|
53
53
|
const content = hideInsteadOfDestroy ? (React.createElement("div", { ref: this.componentRef, className: b('body', { hidden: !open }) }, children)) : (open && (React.createElement("div", { ref: this.componentRef, className: b('body', contentClassName) }, children)));
|
|
54
54
|
if (viewLayout && !isFirstRender && hidden) {
|
|
@@ -56,7 +56,7 @@ export class SimpleVerticalAccordeon extends React.Component {
|
|
|
56
56
|
}
|
|
57
57
|
const title = this.getTitle();
|
|
58
58
|
const titlePopoverDisabled = (((_a = this.titleRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0) <= TITLE_TEXT_MAX_WIDTH;
|
|
59
|
-
const currentTitleVariant = this.getCurrentTitleVariant();
|
|
59
|
+
const currentTitleVariant = variantTitle || this.getCurrentTitleVariant();
|
|
60
60
|
return (Boolean(React.Children.count(children)) && (React.createElement("div", { className: b({ branch: withBranchView, view: viewLayout }, className) },
|
|
61
61
|
React.createElement("div", { className: b('header') },
|
|
62
62
|
React.createElement(Popover, { content: title, disabled: titlePopoverDisabled, placement: COMMON_POPOVER_PLACEMENT, className: b('popover'), hasArrow: true },
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { TextProps } from '@gravity-ui/uikit';
|
|
2
|
+
import { ArrayValue, ObjectValue, Spec, ViewLayoutProps } from '../../../../core';
|
|
3
|
+
interface ViewAccordeonLayoutProps {
|
|
4
|
+
variantTitle?: TextProps['variant'];
|
|
5
|
+
}
|
|
6
|
+
export declare const ViewAccordeon: <T extends ViewLayoutProps<ArrayValue | ObjectValue, Spec<any, any, ViewAccordeonLayoutProps>>>({ name, value, spec, children, }: T) => JSX.Element | null;
|
|
7
|
+
export {};
|
|
@@ -6,10 +6,11 @@ import { SimpleVerticalAccordeon } from '../../SimpleVerticalAccordeon';
|
|
|
6
6
|
export const ViewAccordeon = ({ name, value, spec, children, }) => {
|
|
7
7
|
const { showLayoutDescription } = useDynamicFormsCtx();
|
|
8
8
|
const [open, setOpen] = React.useState(isBoolean(spec.viewSpec.layoutOpen) ? spec.viewSpec.layoutOpen : true);
|
|
9
|
+
const { variantTitle } = spec.viewSpec.layoutProps || {};
|
|
9
10
|
if (!isNotEmptyValue(value, spec)) {
|
|
10
11
|
return null;
|
|
11
12
|
}
|
|
12
13
|
return (React.createElement(SimpleVerticalAccordeon, { name: name, title: spec.viewSpec.layoutTitle || '', note: showLayoutDescription && spec.viewSpec.layoutDescription
|
|
13
14
|
? spec.viewSpec.layoutDescription
|
|
14
|
-
: undefined, open: open, onOpenChange: setOpen, hideInsteadOfDestroy: true, withBranchView: true, viewLayout: true }, children));
|
|
15
|
+
: undefined, open: open, onOpenChange: setOpen, hideInsteadOfDestroy: true, withBranchView: true, viewLayout: true, variantTitle: variantTitle }, children));
|
|
15
16
|
};
|
|
@@ -3,7 +3,7 @@ import isObjectLike from 'lodash/isObjectLike';
|
|
|
3
3
|
import { Card, ViewRow } from '../';
|
|
4
4
|
import { ViewController } from '../../../core';
|
|
5
5
|
export const CardOneOfView = (props) => {
|
|
6
|
-
const { value = {}, spec, name } = props;
|
|
6
|
+
const { value = {}, spec, name, Layout } = props;
|
|
7
7
|
const [open, setOpen] = React.useState(true);
|
|
8
8
|
const onToggle = React.useCallback(() => setOpen((f) => !f), [setOpen]);
|
|
9
9
|
const specProperties = React.useMemo(() => (isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
|
|
@@ -14,8 +14,18 @@ export const CardOneOfView = (props) => {
|
|
|
14
14
|
((_b = specProperties[valueKey]) === null || _b === void 0 ? void 0 : _b.viewSpec.layoutTitle) ||
|
|
15
15
|
valueKey);
|
|
16
16
|
}, [valueKey, spec.description, specProperties]);
|
|
17
|
-
const title = React.useMemo(() =>
|
|
18
|
-
|
|
17
|
+
const title = React.useMemo(() => {
|
|
18
|
+
const titleProps = {
|
|
19
|
+
spec: spec,
|
|
20
|
+
value: valueName,
|
|
21
|
+
name: name,
|
|
22
|
+
children: React.createElement(React.Fragment, null, valueName),
|
|
23
|
+
};
|
|
24
|
+
if (Layout) {
|
|
25
|
+
return React.createElement(Layout, Object.assign({}, titleProps));
|
|
26
|
+
}
|
|
27
|
+
return React.createElement(ViewRow, Object.assign({}, titleProps));
|
|
28
|
+
}, [spec, name, valueName, Layout]);
|
|
19
29
|
if (!value || !Object.keys(value).length) {
|
|
20
30
|
return null;
|
|
21
31
|
}
|
|
@@ -37,7 +37,7 @@ export const isNotEmptyValue = (value, spec) => {
|
|
|
37
37
|
return true;
|
|
38
38
|
};
|
|
39
39
|
export const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) => {
|
|
40
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
41
41
|
if (isObjectLike(spec)) {
|
|
42
42
|
const result = cloneDeep(spec);
|
|
43
43
|
if (isString(result.type)) {
|
|
@@ -49,7 +49,7 @@ export const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) =
|
|
|
49
49
|
try {
|
|
50
50
|
_defaultValue = JSON.parse(result.defaultValue);
|
|
51
51
|
}
|
|
52
|
-
catch (
|
|
52
|
+
catch (_m) {
|
|
53
53
|
_defaultValue = undefined;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -70,20 +70,21 @@ export const prepareSpec = (spec, parseJsonDefaultValue, overridePatternError) =
|
|
|
70
70
|
if (isString((_c = result.viewSpec) === null || _c === void 0 ? void 0 : _c.addButtonPosition)) {
|
|
71
71
|
result.viewSpec.addButtonPosition = result.viewSpec.addButtonPosition.toLowerCase();
|
|
72
72
|
}
|
|
73
|
-
if (isString((_d = result.viewSpec) === null || _d === void 0 ? void 0 : _d.
|
|
74
|
-
result.viewSpec.textContentParams = Object.assign(Object.assign({}, result.viewSpec.textContentParams), { themeLabel: result.viewSpec.themeLabel.toLowerCase() });
|
|
75
|
-
}
|
|
76
|
-
if (isString((_f = (_e = result.viewSpec) === null || _e === void 0 ? void 0 : _e.oneOfParams) === null || _f === void 0 ? void 0 : _f.toggler)) {
|
|
73
|
+
if (isString((_e = (_d = result.viewSpec) === null || _d === void 0 ? void 0 : _d.oneOfParams) === null || _e === void 0 ? void 0 : _e.toggler)) {
|
|
77
74
|
result.viewSpec.oneOfParams.toggler = result.viewSpec.oneOfParams.toggler.toLowerCase();
|
|
78
75
|
}
|
|
79
|
-
if (isString((
|
|
76
|
+
if (isString((_g = (_f = result.viewSpec) === null || _f === void 0 ? void 0 : _f.textContentParams) === null || _g === void 0 ? void 0 : _g.themeLabel)) {
|
|
80
77
|
result.viewSpec.textContentParams.themeLabel =
|
|
81
78
|
result.viewSpec.textContentParams.themeLabel.toLowerCase();
|
|
82
79
|
}
|
|
83
|
-
if (isString((
|
|
80
|
+
if (isString((_j = (_h = result.viewSpec) === null || _h === void 0 ? void 0 : _h.textContentParams) === null || _j === void 0 ? void 0 : _j.themeAlert)) {
|
|
84
81
|
result.viewSpec.textContentParams.themeAlert =
|
|
85
82
|
result.viewSpec.textContentParams.themeAlert.toLowerCase();
|
|
86
83
|
}
|
|
84
|
+
if (isString((_l = (_k = result.viewSpec) === null || _k === void 0 ? void 0 : _k.textContentParams) === null || _l === void 0 ? void 0 : _l.viewAlert)) {
|
|
85
|
+
result.viewSpec.textContentParams.viewAlert =
|
|
86
|
+
result.viewSpec.textContentParams.viewAlert.toLowerCase();
|
|
87
|
+
}
|
|
87
88
|
if (isString(result.validator)) {
|
|
88
89
|
result.validator = result.validator.toLowerCase();
|
|
89
90
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/dynamic-forms",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "build/cjs/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@bem-react/classname": "^1.6.0",
|
|
48
|
-
"@gravity-ui/date-components": "^3.0.0
|
|
48
|
+
"@gravity-ui/date-components": "^3.0.0",
|
|
49
49
|
"@gravity-ui/date-utils": "^2.5.5",
|
|
50
50
|
"@gravity-ui/i18n": "^1.2.0",
|
|
51
51
|
"@gravity-ui/icons": "^2.12.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@gravity-ui/prettier-config": "^1.1.0",
|
|
61
61
|
"@gravity-ui/stylelint-config": "^4.0.1",
|
|
62
62
|
"@gravity-ui/tsconfig": "^1.0.0",
|
|
63
|
-
"@gravity-ui/uikit": "^7.
|
|
63
|
+
"@gravity-ui/uikit": "^7.1.0",
|
|
64
64
|
"@playwright/experimental-ct-react": "^1.40.0",
|
|
65
65
|
"@playwright/test": "^1.40.0",
|
|
66
66
|
"@storybook/addon-essentials": "^7.0.27",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"uuid": "^9.0.1"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
|
-
"@gravity-ui/uikit": "^7.0.0
|
|
117
|
+
"@gravity-ui/uikit": "^7.0.0",
|
|
118
118
|
"final-form": "^4.20.2",
|
|
119
119
|
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
120
120
|
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0",
|