@gravity-ui/dynamic-forms 5.3.0 → 5.4.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.
@@ -13,7 +13,7 @@ const useMutators = (externalMutators) => {
13
13
  const mergeSpec = (a = {}, b) => {
14
14
  const result = (0, cloneDeep_1.default)(a);
15
15
  const getKeys = (parent) => {
16
- if ((0, isObjectLike_1.default)(parent)) {
16
+ if ((0, isObjectLike_1.default)(parent) && !Array.isArray(parent)) {
17
17
  return (0, keys_1.default)(parent).reduce((acc, parentKey) => {
18
18
  const childKeys = getKeys(parent[parentKey]);
19
19
  return [
@@ -31,7 +31,7 @@ const useMutators = (externalMutators) => {
31
31
  return result;
32
32
  };
33
33
  const mergeValuesOrErrors = (a = {}, b) => {
34
- const result = (0, cloneDeep_1.default)(a);
34
+ const result = Object.assign({}, a);
35
35
  Object.keys(b).forEach((key) => {
36
36
  (0, set_1.default)(result, [key, 'value'], b[key]);
37
37
  });
@@ -0,0 +1,28 @@
1
+ /*
2
+ @mixin variables {
3
+ --g-spacing-base: 4px;
4
+
5
+ --g-spacing-0: calc(var(--g-spacing-base) * 0); //0px
6
+ --g-spacing-half: calc(var(--g-spacing-base) * 0.5); //2px
7
+ --g-spacing-1: var(--g-spacing-base); // 4px
8
+ --g-spacing-2: calc(var(--g-spacing-base) * 2); // 8px
9
+ --g-spacing-3: calc(var(--g-spacing-base) * 3); // 12px
10
+ --g-spacing-4: calc(var(--g-spacing-base) * 4); // 16px
11
+ --g-spacing-5: calc(var(--g-spacing-base) * 5); // 20px
12
+ --g-spacing-6: calc(var(--g-spacing-base) * 6); // 24px
13
+ --g-spacing-7: calc(var(--g-spacing-base) * 7); // 28px
14
+ --g-spacing-8: calc(var(--g-spacing-base) * 8); // 32px
15
+ --g-spacing-9: calc(var(--g-spacing-base) * 9); // 36px
16
+ --g-spacing-10: calc(var(--g-spacing-base) * 10); // 40px
17
+ }
18
+ */
19
+ /* Border-radius */
20
+ .df-radio-group {
21
+ align-items: center;
22
+ height: var(--df-radio-group-height, 28px);
23
+ }
24
+ .df-radio-group_vertical {
25
+ align-items: flex-start;
26
+ margin-top: var(--df-radio-group-vertical-margin-top, var(--g-spacing-2));
27
+ height: auto;
28
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RadioGroup = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const uikit_1 = require("@gravity-ui/uikit");
7
+ const utils_1 = require("../../../utils");
8
+ const b = (0, utils_1.block)('radio-group');
9
+ const RadioGroup = ({ name, input, spec, inputProps }) => {
10
+ var _a, _b, _c;
11
+ const { value, onBlur, onChange, onFocus } = input;
12
+ const { withCustomOptions, options: externalOptions } = inputProps || {};
13
+ const options = react_1.default.useMemo(() => {
14
+ var _a;
15
+ return withCustomOptions
16
+ ? externalOptions || []
17
+ : ((_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((id) => {
18
+ var _a, _b, _c;
19
+ return ({
20
+ value: id,
21
+ content: ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[id]) || id,
22
+ disabled: ((_c = (_b = spec.viewSpec.radioGroupParams) === null || _b === void 0 ? void 0 : _b.disabled) === null || _c === void 0 ? void 0 : _c[id]) || false,
23
+ });
24
+ })) || [];
25
+ }, [
26
+ withCustomOptions,
27
+ externalOptions,
28
+ spec.enum,
29
+ spec.description,
30
+ (_a = spec.viewSpec.radioGroupParams) === null || _a === void 0 ? void 0 : _a.disabled,
31
+ ]);
32
+ if (options.length === 0) {
33
+ return null;
34
+ }
35
+ return (react_1.default.createElement(uikit_1.Flex, { className: b({ vertical: ((_b = spec.viewSpec.radioGroupParams) === null || _b === void 0 ? void 0 : _b.direction) === 'vertical' }) },
36
+ react_1.default.createElement(uikit_1.RadioGroup, Object.assign({}, inputProps, { name: name, qa: name, disabled: spec.viewSpec.disabled, onUpdate: onChange, onBlur: onBlur, onFocus: onFocus, value: value, options: options, direction: ((_c = spec.viewSpec.radioGroupParams) === null || _c === void 0 ? void 0 : _c.direction) || 'horizontal' }))));
37
+ };
38
+ exports.RadioGroup = RadioGroup;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./RadioGroup"), exports);
@@ -14,6 +14,7 @@ tslib_1.__exportStar(require("./NumberWithScale"), exports);
14
14
  tslib_1.__exportStar(require("./ObjectBase"), exports);
15
15
  tslib_1.__exportStar(require("./ObjectValueInput"), exports);
16
16
  tslib_1.__exportStar(require("./OneOf"), exports);
17
+ tslib_1.__exportStar(require("./RadioGroup"), exports);
17
18
  tslib_1.__exportStar(require("./Secret"), exports);
18
19
  tslib_1.__exportStar(require("./Select"), exports);
19
20
  tslib_1.__exportStar(require("./Switch"), exports);
@@ -104,6 +104,7 @@ exports.dynamicConfig = {
104
104
  number_with_scale: { Component: components_1.NumberWithScale },
105
105
  monaco_input: { Component: components_1.MonacoInput },
106
106
  text_content: { Component: components_1.TextContent, independent: true },
107
+ radio_group: { Component: components_1.RadioGroup },
107
108
  },
108
109
  layouts: {
109
110
  row: components_1.Row,
@@ -212,6 +213,7 @@ exports.dynamicViewConfig = {
212
213
  number_with_scale: { Component: components_1.NumberWithScaleView },
213
214
  monaco_input: { Component: components_1.MonacoView },
214
215
  text_content: { Component: components_1.TextContentView, independent: true },
216
+ radio_group: { Component: components_1.BaseView },
215
217
  },
216
218
  layouts: {
217
219
  row: components_1.ViewRow,
@@ -9,7 +9,7 @@ export const useMutators = (externalMutators) => {
9
9
  const mergeSpec = (a = {}, b) => {
10
10
  const result = cloneDeep(a);
11
11
  const getKeys = (parent) => {
12
- if (isObjectLike(parent)) {
12
+ if (isObjectLike(parent) && !Array.isArray(parent)) {
13
13
  return keys(parent).reduce((acc, parentKey) => {
14
14
  const childKeys = getKeys(parent[parentKey]);
15
15
  return [
@@ -27,7 +27,7 @@ export const useMutators = (externalMutators) => {
27
27
  return result;
28
28
  };
29
29
  const mergeValuesOrErrors = (a = {}, b) => {
30
- const result = cloneDeep(a);
30
+ const result = Object.assign({}, a);
31
31
  Object.keys(b).forEach((key) => {
32
32
  set(result, [key, 'value'], b[key]);
33
33
  });
@@ -168,6 +168,10 @@ export interface StringSpec<LinkType = any, InputComponentProps extends Record<s
168
168
  filterPlaceholder?: string;
169
169
  meta?: Record<string, string>;
170
170
  };
171
+ radioGroupParams?: {
172
+ direction?: 'horizontal' | 'vertical';
173
+ disabled?: Record<string, boolean>;
174
+ };
171
175
  inputProps?: InputComponentProps;
172
176
  layoutProps?: LayoutComponentProps;
173
177
  generateRandomValueButton?: boolean;
@@ -0,0 +1,28 @@
1
+ /*
2
+ @mixin variables {
3
+ --g-spacing-base: 4px;
4
+
5
+ --g-spacing-0: calc(var(--g-spacing-base) * 0); //0px
6
+ --g-spacing-half: calc(var(--g-spacing-base) * 0.5); //2px
7
+ --g-spacing-1: var(--g-spacing-base); // 4px
8
+ --g-spacing-2: calc(var(--g-spacing-base) * 2); // 8px
9
+ --g-spacing-3: calc(var(--g-spacing-base) * 3); // 12px
10
+ --g-spacing-4: calc(var(--g-spacing-base) * 4); // 16px
11
+ --g-spacing-5: calc(var(--g-spacing-base) * 5); // 20px
12
+ --g-spacing-6: calc(var(--g-spacing-base) * 6); // 24px
13
+ --g-spacing-7: calc(var(--g-spacing-base) * 7); // 28px
14
+ --g-spacing-8: calc(var(--g-spacing-base) * 8); // 32px
15
+ --g-spacing-9: calc(var(--g-spacing-base) * 9); // 36px
16
+ --g-spacing-10: calc(var(--g-spacing-base) * 10); // 40px
17
+ }
18
+ */
19
+ /* Border-radius */
20
+ .df-radio-group {
21
+ align-items: center;
22
+ height: var(--df-radio-group-height, 28px);
23
+ }
24
+ .df-radio-group_vertical {
25
+ align-items: flex-start;
26
+ margin-top: var(--df-radio-group-vertical-margin-top, var(--g-spacing-2));
27
+ height: auto;
28
+ }
@@ -0,0 +1,7 @@
1
+ import { type RadioGroupProps as RadioGroupBaseProps } from '@gravity-ui/uikit';
2
+ import type { StringInput } from '../../../../core';
3
+ import './RadioGroup.css';
4
+ export interface RadioGroupProps extends Omit<RadioGroupBaseProps, 'direction' | 'onChange' | 'onBlur' | 'onFocus' | 'disabled' | 'qa' | 'content'> {
5
+ withCustomOptions?: boolean;
6
+ }
7
+ export declare const RadioGroup: StringInput<RadioGroupProps>;
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { Flex, RadioGroup as RadioGroupBase, } from '@gravity-ui/uikit';
3
+ import { block } from '../../../utils';
4
+ import './RadioGroup.css';
5
+ const b = block('radio-group');
6
+ export const RadioGroup = ({ name, input, spec, inputProps }) => {
7
+ var _a, _b, _c;
8
+ const { value, onBlur, onChange, onFocus } = input;
9
+ const { withCustomOptions, options: externalOptions } = inputProps || {};
10
+ const options = React.useMemo(() => {
11
+ var _a;
12
+ return withCustomOptions
13
+ ? externalOptions || []
14
+ : ((_a = spec.enum) === null || _a === void 0 ? void 0 : _a.map((id) => {
15
+ var _a, _b, _c;
16
+ return ({
17
+ value: id,
18
+ content: ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[id]) || id,
19
+ disabled: ((_c = (_b = spec.viewSpec.radioGroupParams) === null || _b === void 0 ? void 0 : _b.disabled) === null || _c === void 0 ? void 0 : _c[id]) || false,
20
+ });
21
+ })) || [];
22
+ }, [
23
+ withCustomOptions,
24
+ externalOptions,
25
+ spec.enum,
26
+ spec.description,
27
+ (_a = spec.viewSpec.radioGroupParams) === null || _a === void 0 ? void 0 : _a.disabled,
28
+ ]);
29
+ if (options.length === 0) {
30
+ return null;
31
+ }
32
+ return (React.createElement(Flex, { className: b({ vertical: ((_b = spec.viewSpec.radioGroupParams) === null || _b === void 0 ? void 0 : _b.direction) === 'vertical' }) },
33
+ React.createElement(RadioGroupBase, Object.assign({}, inputProps, { name: name, qa: name, disabled: spec.viewSpec.disabled, onUpdate: onChange, onBlur: onBlur, onFocus: onFocus, value: value, options: options, direction: ((_c = spec.viewSpec.radioGroupParams) === null || _c === void 0 ? void 0 : _c.direction) || 'horizontal' }))));
34
+ };
@@ -0,0 +1 @@
1
+ export * from './RadioGroup';
@@ -0,0 +1 @@
1
+ export * from './RadioGroup';
@@ -11,6 +11,7 @@ export * from './NumberWithScale';
11
11
  export * from './ObjectBase';
12
12
  export * from './ObjectValueInput';
13
13
  export * from './OneOf';
14
+ export * from './RadioGroup';
14
15
  export * from './Secret';
15
16
  export * from './Select';
16
17
  export * from './Switch';
@@ -11,6 +11,7 @@ export * from './NumberWithScale';
11
11
  export * from './ObjectBase';
12
12
  export * from './ObjectValueInput';
13
13
  export * from './OneOf';
14
+ export * from './RadioGroup';
14
15
  export * from './Secret';
15
16
  export * from './Select';
16
17
  export * from './Switch';
@@ -1,4 +1,4 @@
1
- import { Accordeon, AccordeonCardForm, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, CheckboxGroup, CheckboxGroupView, Column, DateInput, DateView, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoView, MultiOneOf, MultiOneOfFlat, MultiOneOfFlatView, MultiOneOfView, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectInline, ObjectInlineView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfFlat, OneOfFlatView, OneOfView, Row, RowVerbose, Secret, Section, Section2, Select, Switch, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextContentView, TextLink, TextLinkView, TimeRangeSelector, TimeRangeSelectorView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewColumn, ViewGroup, ViewGroup2, ViewRow, ViewSection, ViewSection2, ViewTableCell, ViewTransparent, } from '../components';
1
+ import { Accordeon, AccordeonCardForm, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, CheckboxGroup, CheckboxGroupView, Column, DateInput, DateView, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoView, MultiOneOf, MultiOneOfFlat, MultiOneOfFlatView, MultiOneOfView, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectInline, ObjectInlineView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfFlat, OneOfFlatView, OneOfView, RadioGroup, Row, RowVerbose, Secret, Section, Section2, Select, Switch, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextContentView, TextLink, TextLinkView, TimeRangeSelector, TimeRangeSelectorView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewColumn, ViewGroup, ViewGroup2, ViewRow, ViewSection, ViewSection2, ViewTableCell, ViewTransparent, } from '../components';
2
2
  import { getArrayValidator, getBooleanValidator, getNumberValidator, getObjectValidator, getStringValidator, } from '../validators';
3
3
  export const dynamicConfig = {
4
4
  array: {
@@ -101,6 +101,7 @@ export const dynamicConfig = {
101
101
  number_with_scale: { Component: NumberWithScale },
102
102
  monaco_input: { Component: MonacoInput },
103
103
  text_content: { Component: TextContent, independent: true },
104
+ radio_group: { Component: RadioGroup },
104
105
  },
105
106
  layouts: {
106
107
  row: Row,
@@ -209,6 +210,7 @@ export const dynamicViewConfig = {
209
210
  number_with_scale: { Component: NumberWithScaleView },
210
211
  monaco_input: { Component: MonacoView },
211
212
  text_content: { Component: TextContentView, independent: true },
213
+ radio_group: { Component: BaseView },
212
214
  },
213
215
  layouts: {
214
216
  row: ViewRow,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "5.3.0",
3
+ "version": "5.4.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",