@gravity-ui/dynamic-forms 3.6.1 → 3.8.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.
Files changed (35) hide show
  1. package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.css +6 -0
  2. package/build/cjs/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +11 -5
  3. package/build/cjs/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +4 -4
  4. package/build/cjs/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.css +6 -0
  5. package/build/cjs/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.js +16 -9
  6. package/build/cjs/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +4 -4
  7. package/build/cjs/lib/kit/components/Views/OneOfView/OneOfView.js +15 -4
  8. package/build/cjs/lib/kit/constants/common.js +2 -1
  9. package/build/cjs/lib/kit/constants/config.js +2 -0
  10. package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.css +5 -0
  11. package/build/cjs/lib/kit/hooks/useOneOf/useOneOf.js +35 -7
  12. package/build/cjs/lib/kit/utils/index.js +1 -0
  13. package/build/cjs/lib/kit/utils/objectInline.js +1 -1
  14. package/build/cjs/lib/kit/utils/objectKeys.js +7 -0
  15. package/build/cjs/lib/kit/validators/validators.js +5 -5
  16. package/build/esm/lib/core/types/specs.d.ts +3 -1
  17. package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.css +6 -0
  18. package/build/esm/lib/kit/components/Inputs/ObjectBase/ObjectBase.js +12 -6
  19. package/build/esm/lib/kit/components/Inputs/ObjectValueInput/ObjectValueInput.js +1 -1
  20. package/build/esm/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.css +6 -0
  21. package/build/esm/lib/kit/components/Views/ObjectBaseView/ObjectBaseView.js +16 -9
  22. package/build/esm/lib/kit/components/Views/ObjectValueInputView/ObjectValueInputView.js +1 -1
  23. package/build/esm/lib/kit/components/Views/OneOfView/OneOfView.js +16 -5
  24. package/build/esm/lib/kit/constants/common.d.ts +1 -0
  25. package/build/esm/lib/kit/constants/common.js +1 -0
  26. package/build/esm/lib/kit/constants/config.js +2 -0
  27. package/build/esm/lib/kit/hooks/useOneOf/useOneOf.css +5 -0
  28. package/build/esm/lib/kit/hooks/useOneOf/useOneOf.js +37 -9
  29. package/build/esm/lib/kit/utils/index.d.ts +1 -0
  30. package/build/esm/lib/kit/utils/index.js +1 -0
  31. package/build/esm/lib/kit/utils/objectInline.js +2 -2
  32. package/build/esm/lib/kit/utils/objectKeys.d.ts +4 -0
  33. package/build/esm/lib/kit/utils/objectKeys.js +3 -0
  34. package/build/esm/lib/kit/validators/validators.js +5 -5
  35. package/package.json +1 -1
@@ -8,4 +8,10 @@
8
8
  }
9
9
  .df-object-base__content_inline > .df-use-search:last-child {
10
10
  margin-right: 0;
11
+ }
12
+ .df-object-base__delimiter {
13
+ display: flex;
14
+ margin-right: 8px;
15
+ align-items: center;
16
+ white-space: nowrap;
11
17
  }
@@ -5,7 +5,8 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const icons_1 = require("@gravity-ui/icons");
7
7
  const uikit_1 = require("@gravity-ui/uikit");
8
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
8
+ const isObjectLike_1 = tslib_1.__importDefault(require("lodash/isObjectLike"));
9
+ const set_1 = tslib_1.__importDefault(require("lodash/set"));
9
10
  const core_1 = require("../../../../core");
10
11
  const utils_1 = require("../../../utils");
11
12
  const b = (0, utils_1.block)('object-base');
@@ -17,10 +18,10 @@ const ObjectBase = (_a) => {
17
18
  react_1.default.createElement(uikit_1.Icon, { data: icons_1.Plus, size: 14 }),
18
19
  spec.viewSpec.layoutTitle || null));
19
20
  }, [spec.defaultValue, spec.viewSpec.layoutTitle, restProps.input.onChange]);
20
- const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${restProps.input.name}.`).join(''), childValue), childErrors), [restProps.input.onChange, restProps.input.name]);
21
+ const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) => (0, set_1.default)(Object.assign({}, currentValue), childName.split(`${restProps.input.name}.`).join(''), childValue), childErrors), [restProps.input.onChange, restProps.input.name]);
21
22
  const content = react_1.default.useMemo(() => {
22
23
  if (!spec.properties ||
23
- !lodash_1.default.isObjectLike(spec.properties) ||
24
+ !(0, isObjectLike_1.default)(spec.properties) ||
24
25
  !Object.keys(spec.properties || {}).length) {
25
26
  return null;
26
27
  }
@@ -30,12 +31,17 @@ const ObjectBase = (_a) => {
30
31
  const specProperties = inline
31
32
  ? (0, utils_1.filterPropertiesForObjectInline)(spec.properties)
32
33
  : spec.properties;
33
- return (react_1.default.createElement("div", { className: b('content', { inline }) }, (spec.viewSpec.order || Object.keys(specProperties)).map((property) => {
34
+ const delimiter = spec.viewSpec.delimiter;
35
+ const orderProperties = spec.viewSpec.order || Object.keys(specProperties);
36
+ return (react_1.default.createElement("div", { className: b('content', { inline }) }, orderProperties.map((property) => {
34
37
  var _a;
35
- return specProperties[property] ? (react_1.default.createElement(core_1.Controller, { value: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: restProps.input.parentOnUnmount, key: `${name ? name + '.' : ''}${property}` })) : null;
38
+ return specProperties[property] ? (react_1.default.createElement(react_1.default.Fragment, { key: `${name ? name + '.' : ''}${property}` },
39
+ react_1.default.createElement(core_1.Controller, { value: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: restProps.input.parentOnUnmount }),
40
+ delimiter && delimiter[property] ? (react_1.default.createElement(uikit_1.Text, { className: b('delimiter') }, delimiter[property])) : null)) : null;
36
41
  })));
37
42
  }, [
38
43
  spec.properties,
44
+ spec.viewSpec.delimiter,
39
45
  spec.viewSpec.order,
40
46
  restProps.input.value,
41
47
  restProps.input.parentOnUnmount,
@@ -5,15 +5,15 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const core_1 = require("../../../../core");
8
- const OBJECT_VALUE_PROPERTY_NAME = 'value';
8
+ const common_1 = require("../../../constants/common");
9
9
  const ObjectValueInput = (props) => {
10
10
  var _a;
11
11
  const { spec, input, name, Layout } = props;
12
12
  const parentOnChange = react_1.default.useCallback((childName, childValue, childErrors) => input.onChange((currentValue) => lodash_1.default.set(Object.assign({}, currentValue), childName.split(`${name}.`).join(''), childValue), childErrors), [input.onChange, input.name]);
13
13
  const childSpec = react_1.default.useMemo(() => {
14
14
  var _a;
15
- if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[OBJECT_VALUE_PROPERTY_NAME]) {
16
- const childSpec = lodash_1.default.cloneDeep(spec.properties[OBJECT_VALUE_PROPERTY_NAME]);
15
+ if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[common_1.OBJECT_VALUE_PROPERTY_NAME]) {
16
+ const childSpec = lodash_1.default.cloneDeep(spec.properties[common_1.OBJECT_VALUE_PROPERTY_NAME]);
17
17
  childSpec.viewSpec.layout = 'transparent';
18
18
  return childSpec;
19
19
  }
@@ -22,7 +22,7 @@ const ObjectValueInput = (props) => {
22
22
  if (!childSpec) {
23
23
  return null;
24
24
  }
25
- const content = (react_1.default.createElement(core_1.Controller, { value: (_a = input.value) === null || _a === void 0 ? void 0 : _a[OBJECT_VALUE_PROPERTY_NAME], spec: childSpec, name: `${name}.${OBJECT_VALUE_PROPERTY_NAME}`, key: `${name}.${OBJECT_VALUE_PROPERTY_NAME}`, parentOnChange: parentOnChange, parentOnUnmount: input.parentOnUnmount }));
25
+ const content = (react_1.default.createElement(core_1.Controller, { value: (_a = input.value) === null || _a === void 0 ? void 0 : _a[common_1.OBJECT_VALUE_PROPERTY_NAME], spec: childSpec, name: `${name}.${common_1.OBJECT_VALUE_PROPERTY_NAME}`, key: `${name}.${common_1.OBJECT_VALUE_PROPERTY_NAME}`, parentOnChange: parentOnChange, parentOnUnmount: input.parentOnUnmount }));
26
26
  if (Layout) {
27
27
  return react_1.default.createElement(Layout, Object.assign({}, props), content);
28
28
  }
@@ -8,4 +8,10 @@
8
8
  }
9
9
  .df-object-base-view__content_inline > div:last-child {
10
10
  margin-right: 0;
11
+ }
12
+ .df-object-base-view__delimiter {
13
+ display: flex;
14
+ margin-right: 8px;
15
+ align-items: center;
16
+ white-space: nowrap;
11
17
  }
@@ -3,20 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObjectInlineView = exports.ObjectBaseView = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const uikit_1 = require("@gravity-ui/uikit");
7
+ const isObjectLike_1 = tslib_1.__importDefault(require("lodash/isObjectLike"));
7
8
  const core_1 = require("../../../../core");
8
9
  const utils_1 = require("../../../utils");
9
10
  const b = (0, utils_1.block)('object-base-view');
10
11
  const ObjectBaseView = (_a) => {
11
12
  var { inline, spec, name, Layout } = _a, restProps = tslib_1.__rest(_a, ["inline", "spec", "name", "Layout"]);
12
- if (!spec.properties || !lodash_1.default.isObjectLike(spec.properties)) {
13
- return null;
14
- }
15
- const specProperties = inline
16
- ? (0, utils_1.filterPropertiesForObjectInline)(spec.properties)
17
- : spec.properties;
18
- const content = (react_1.default.createElement("div", { className: b('content', { inline }) }, (spec.viewSpec.order || Object.keys(specProperties)).map((property) => specProperties[property] ? (react_1.default.createElement(core_1.ViewController, { spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, key: `${name ? name + '.' : ''}${property}` })) : null)));
19
- if (!Layout) {
13
+ const content = react_1.default.useMemo(() => {
14
+ if (!spec.properties || !(0, isObjectLike_1.default)(spec.properties)) {
15
+ return null;
16
+ }
17
+ const specProperties = inline
18
+ ? (0, utils_1.filterPropertiesForObjectInline)(spec.properties)
19
+ : spec.properties;
20
+ const delimiter = spec.viewSpec.delimiter;
21
+ const orderProperties = spec.viewSpec.order || Object.keys(specProperties);
22
+ return (react_1.default.createElement("div", { className: b('content', { inline }) }, orderProperties.map((property) => specProperties[property] ? (react_1.default.createElement(react_1.default.Fragment, { key: `${name ? name + '.' : ''}${property}` },
23
+ react_1.default.createElement(core_1.ViewController, { spec: specProperties[property], name: `${name ? name + '.' : ''}${property}` }),
24
+ delimiter && delimiter[property] ? (react_1.default.createElement(uikit_1.Text, { className: b('delimiter') }, delimiter[property])) : null)) : null)));
25
+ }, [inline, name, spec.properties, spec.viewSpec.delimiter, spec.viewSpec.order]);
26
+ if (!Layout || !content) {
20
27
  return content;
21
28
  }
22
29
  return (react_1.default.createElement(Layout, Object.assign({ spec: spec, name: name }, restProps), content));
@@ -5,13 +5,13 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const core_1 = require("../../../../core");
8
- const OBJECT_VALUE_PROPERTY_NAME = 'value';
8
+ const common_1 = require("../../../constants/common");
9
9
  const ObjectValueInputView = (_a) => {
10
10
  var { spec, name, Layout } = _a, restProps = tslib_1.__rest(_a, ["spec", "name", "Layout"]);
11
11
  const childSpec = react_1.default.useMemo(() => {
12
12
  var _a;
13
- if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[OBJECT_VALUE_PROPERTY_NAME]) {
14
- const childSpec = lodash_1.default.cloneDeep(spec.properties[OBJECT_VALUE_PROPERTY_NAME]);
13
+ if ((_a = spec.properties) === null || _a === void 0 ? void 0 : _a[common_1.OBJECT_VALUE_PROPERTY_NAME]) {
14
+ const childSpec = lodash_1.default.cloneDeep(spec.properties[common_1.OBJECT_VALUE_PROPERTY_NAME]);
15
15
  childSpec.viewSpec.layout = '';
16
16
  return childSpec;
17
17
  }
@@ -20,7 +20,7 @@ const ObjectValueInputView = (_a) => {
20
20
  if (!childSpec) {
21
21
  return null;
22
22
  }
23
- const content = (react_1.default.createElement(core_1.ViewController, { spec: childSpec, name: `${name ? name + '.' : ''}${OBJECT_VALUE_PROPERTY_NAME}` }));
23
+ const content = (react_1.default.createElement(core_1.ViewController, { spec: childSpec, name: `${name ? name + '.' : ''}${common_1.OBJECT_VALUE_PROPERTY_NAME}` }));
24
24
  if (Layout) {
25
25
  return (react_1.default.createElement(Layout, Object.assign({ spec: spec, name: name }, restProps), content));
26
26
  }
@@ -9,15 +9,26 @@ const core_1 = require("../../../../core");
9
9
  const utils_1 = require("../../../utils");
10
10
  const b = (0, utils_1.block)('oneof-view');
11
11
  const OneOfViewComponent = (props) => {
12
+ var _a, _b;
12
13
  const { value = {}, spec, Layout, name } = props;
13
14
  const specProperties = react_1.default.useMemo(() => (lodash_1.default.isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
15
+ const specBooleanMap = react_1.default.useMemo(() => { var _a; return (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap; }, [(_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap]);
14
16
  const valueKey = react_1.default.useMemo(() => Object.keys(value)[0], [value]);
15
17
  const valueName = react_1.default.useMemo(() => {
16
- var _a, _b;
17
- return (((_a = spec.description) === null || _a === void 0 ? void 0 : _a[valueKey]) ||
18
- ((_b = specProperties[valueKey]) === null || _b === void 0 ? void 0 : _b.viewSpec.layoutTitle) ||
18
+ var _a, _b, _c;
19
+ if (((_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler) === 'checkbox' && specBooleanMap) {
20
+ return (0, utils_1.objectKeys)(specBooleanMap).find((key) => specBooleanMap[key] === valueKey);
21
+ }
22
+ return (((_b = spec.description) === null || _b === void 0 ? void 0 : _b[valueKey]) ||
23
+ ((_c = specProperties[valueKey]) === null || _c === void 0 ? void 0 : _c.viewSpec.layoutTitle) ||
19
24
  valueKey);
20
- }, [valueKey, spec.description, specProperties]);
25
+ }, [
26
+ valueKey,
27
+ spec.description,
28
+ specProperties,
29
+ (_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler,
30
+ specBooleanMap,
31
+ ]);
21
32
  const wrappedValue = react_1.default.useMemo(() => {
22
33
  if (Layout) {
23
34
  return (react_1.default.createElement(Layout, Object.assign({}, props, { value: valueName }),
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COMMON_TITLE_MAX_WIDTH = exports.COMMON_POPOVER_PLACEMENT = void 0;
3
+ exports.OBJECT_VALUE_PROPERTY_NAME = exports.COMMON_TITLE_MAX_WIDTH = exports.COMMON_POPOVER_PLACEMENT = void 0;
4
4
  exports.COMMON_POPOVER_PLACEMENT = ['bottom', 'top'];
5
5
  exports.COMMON_TITLE_MAX_WIDTH = 533;
6
+ exports.OBJECT_VALUE_PROPERTY_NAME = 'value';
@@ -37,6 +37,7 @@ exports.dynamicConfig = {
37
37
  row: components_1.Row,
38
38
  row_verbose: components_1.RowVerbose,
39
39
  table_item: components_1.TableCell,
40
+ transparent: components_1.Transparent,
40
41
  },
41
42
  validators: {
42
43
  base: (0, validators_1.getBooleanValidator)(),
@@ -145,6 +146,7 @@ exports.dynamicViewConfig = {
145
146
  row: components_1.ViewRow,
146
147
  row_verbose: components_1.ViewRow,
147
148
  table_item: components_1.ViewTableCell,
149
+ transparent: components_1.ViewTransparent,
148
150
  },
149
151
  },
150
152
  number: {
@@ -11,4 +11,9 @@
11
11
  }
12
12
  .df-use-oneof__card > :first-child {
13
13
  margin-right: 8px;
14
+ }
15
+ .df-use-oneof__checkbox {
16
+ height: 28px;
17
+ display: flex;
18
+ align-items: center;
14
19
  }
@@ -4,18 +4,20 @@ exports.useOneOf = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const uikit_1 = require("@gravity-ui/uikit");
7
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
+ const isObjectLike_1 = tslib_1.__importDefault(require("lodash/isObjectLike"));
8
+ const some_1 = tslib_1.__importDefault(require("lodash/some"));
8
9
  const components_1 = require("../../components");
9
10
  const utils_1 = require("../../utils");
10
11
  const b = (0, utils_1.block)('use-oneof');
11
12
  const MAX_TAB_TITLE_LENGTH = 20;
12
13
  const useOneOf = ({ props, onTogglerChange }) => {
13
- var _a;
14
+ var _a, _b;
14
15
  const { name, input, spec, Layout } = props;
15
- const specProperties = react_1.default.useMemo(() => (lodash_1.default.isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
16
+ const specProperties = react_1.default.useMemo(() => ((0, isObjectLike_1.default)(spec.properties) ? spec.properties : {}), [spec.properties]);
17
+ const specBooleanMap = react_1.default.useMemo(() => { var _a; return (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap; }, [(_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap]);
16
18
  const [oneOfValue, setOneOfValue] = react_1.default.useState(() => {
17
19
  let valueKeys;
18
- if (lodash_1.default.isObjectLike(input.value)) {
20
+ if ((0, isObjectLike_1.default)(input.value)) {
19
21
  const keys = Object.keys(input.value);
20
22
  if (keys.length) {
21
23
  valueKeys = keys;
@@ -30,6 +32,20 @@ const useOneOf = ({ props, onTogglerChange }) => {
30
32
  onTogglerChange === null || onTogglerChange === void 0 ? void 0 : onTogglerChange(newValue);
31
33
  }
32
34
  }, [setOneOfValue, input.onChange, oneOfValue]);
35
+ const onCheckboxChange = react_1.default.useCallback((checked) => {
36
+ if (specBooleanMap) {
37
+ const value = String(checked);
38
+ const newValue = specBooleanMap[value];
39
+ onOneOfChange([newValue]);
40
+ }
41
+ }, [onOneOfChange, specBooleanMap]);
42
+ const checkboxValue = react_1.default.useMemo(() => {
43
+ if (specBooleanMap) {
44
+ const keyBooleanMap = (0, utils_1.objectKeys)(specBooleanMap).find((key) => specBooleanMap[key] === oneOfValue);
45
+ return keyBooleanMap === 'true';
46
+ }
47
+ return undefined;
48
+ }, [oneOfValue, specBooleanMap]);
33
49
  const options = react_1.default.useMemo(() => (spec.viewSpec.order || Object.keys(specProperties)).map((value) => {
34
50
  var _a, _b;
35
51
  const title = ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[value]) ||
@@ -43,18 +59,23 @@ const useOneOf = ({ props, onTogglerChange }) => {
43
59
  };
44
60
  }), [spec.description, spec.viewSpec.order, specProperties]);
45
61
  const togglerType = react_1.default.useMemo(() => {
46
- var _a, _b, _c;
62
+ var _a, _b, _c, _d;
47
63
  if (((_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler) === 'card' && options.length < 3) {
48
64
  return 'card';
49
65
  }
50
66
  if (((_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler) !== 'radio' &&
51
67
  (((_c = spec.viewSpec.oneOfParams) === null || _c === void 0 ? void 0 : _c.toggler) === 'select' ||
52
68
  options.length > 3 ||
53
- lodash_1.default.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))) {
69
+ (0, some_1.default)(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))) {
54
70
  return 'select';
55
71
  }
72
+ if (((_d = spec.viewSpec.oneOfParams) === null || _d === void 0 ? void 0 : _d.toggler) === 'checkbox' &&
73
+ options.length === 2 &&
74
+ specBooleanMap) {
75
+ return 'checkbox';
76
+ }
56
77
  return 'radio';
57
- }, [options, (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler]);
78
+ }, [options, (_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler, specBooleanMap]);
58
79
  const togglerInput = react_1.default.useMemo(() => {
59
80
  if (togglerType === 'card') {
60
81
  return (react_1.default.createElement("div", { className: b('card') }, options.map(({ value }) => {
@@ -68,15 +89,22 @@ const useOneOf = ({ props, onTogglerChange }) => {
68
89
  if (togglerType === 'select') {
69
90
  return (react_1.default.createElement(uikit_1.Select, { width: "max", value: [oneOfValue], onUpdate: onOneOfChange, options: options, disabled: spec.viewSpec.disabled, filterable: options.length > 7, qa: name }));
70
91
  }
92
+ if (togglerType === 'checkbox') {
93
+ return (react_1.default.createElement("div", { className: b('checkbox') },
94
+ react_1.default.createElement(uikit_1.Checkbox, { checked: checkboxValue, onUpdate: onCheckboxChange, disabled: spec.viewSpec.disabled, qa: name })));
95
+ }
71
96
  return (react_1.default.createElement(uikit_1.RadioButton, { value: oneOfValue, onChange: (event) => onOneOfChange([event.target.value]), disabled: spec.viewSpec.disabled, qa: name }, options.map((option) => (react_1.default.createElement(uikit_1.RadioButton.Option, { key: option.value, value: option.value }, option.title)))));
72
97
  }, [
73
98
  togglerType,
74
99
  oneOfValue,
75
100
  spec.viewSpec.disabled,
101
+ spec.description,
76
102
  name,
77
103
  options,
78
104
  onOneOfChange,
79
105
  specProperties,
106
+ onCheckboxChange,
107
+ checkboxValue,
80
108
  ]);
81
109
  const toggler = react_1.default.useMemo(() => {
82
110
  if (Layout) {
@@ -5,3 +5,4 @@ tslib_1.__exportStar(require("./cn"), exports);
5
5
  tslib_1.__exportStar(require("./common"), exports);
6
6
  tslib_1.__exportStar(require("./bigIntMath"), exports);
7
7
  tslib_1.__exportStar(require("./objectInline"), exports);
8
+ tslib_1.__exportStar(require("./objectKeys"), exports);
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.filterPropertiesForObjectInline = void 0;
4
4
  const core_1 = require("../../core");
5
5
  const filterPropertiesForObjectInline = (properties) => {
6
- return Object.fromEntries(Object.entries(properties).filter(([, propSpec]) => (0, core_1.isStringSpec)(propSpec) || (0, core_1.isNumberSpec)(propSpec)));
6
+ return Object.fromEntries(Object.entries(properties).filter(([, propSpec]) => (0, core_1.isStringSpec)(propSpec) || (0, core_1.isNumberSpec)(propSpec) || (0, core_1.isBooleanSpec)(propSpec)));
7
7
  };
8
8
  exports.filterPropertiesForObjectInline = filterPropertiesForObjectInline;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectKeys = void 0;
4
+ function objectKeys(obj) {
5
+ return Object.keys(obj);
6
+ }
7
+ exports.objectKeys = objectKeys;
@@ -7,8 +7,8 @@ const validators_1 = require("../validators");
7
7
  const helpers_1 = require("./helpers");
8
8
  const getArrayValidator = (params = {}) => {
9
9
  const { ignoreRequiredCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, customErrorMessages } = params;
10
- const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
11
10
  return (spec, value) => {
11
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
12
12
  const valueLength = (value === null || value === void 0 ? void 0 : value.length) || 0;
13
13
  if (!ignoreRequiredCheck && spec.required && !lodash_1.default.isArray(value)) {
14
14
  return errorMessages.REQUIRED;
@@ -29,8 +29,8 @@ const getArrayValidator = (params = {}) => {
29
29
  exports.getArrayValidator = getArrayValidator;
30
30
  const getBooleanValidator = (params = {}) => {
31
31
  const { ignoreRequiredCheck, customErrorMessages } = params;
32
- const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
33
32
  return (spec, value) => {
33
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
34
34
  if (!ignoreRequiredCheck && spec.required && !value) {
35
35
  return errorMessages.REQUIRED;
36
36
  }
@@ -40,9 +40,9 @@ const getBooleanValidator = (params = {}) => {
40
40
  exports.getBooleanValidator = getBooleanValidator;
41
41
  const getNumberValidator = (params = {}) => {
42
42
  const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreNumberCheck, ignoreMaximumCheck, ignoreMinimumCheck, ignoreIntCheck, ignoreDotEnd, ignoreZeroStart, customErrorMessages, } = params;
43
- const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
44
43
  // eslint-disable-next-line complexity
45
44
  return (spec, value = '') => {
45
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
46
46
  const stringValue = String(value);
47
47
  if (!ignoreRequiredCheck && spec.required && !stringValue.length) {
48
48
  return errorMessages.REQUIRED;
@@ -91,8 +91,8 @@ const getNumberValidator = (params = {}) => {
91
91
  exports.getNumberValidator = getNumberValidator;
92
92
  const getObjectValidator = (params = {}) => {
93
93
  const { ignoreRequiredCheck, customErrorMessages } = params;
94
- const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
95
94
  return (spec, value) => {
95
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
96
96
  if (!ignoreRequiredCheck && spec.required && !value) {
97
97
  return errorMessages.REQUIRED;
98
98
  }
@@ -102,9 +102,9 @@ const getObjectValidator = (params = {}) => {
102
102
  exports.getObjectValidator = getObjectValidator;
103
103
  const getStringValidator = (params = {}) => {
104
104
  const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, ignoreRegExpCheck, customErrorMessages, } = params;
105
- const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
106
105
  // eslint-disable-next-line complexity
107
106
  return (spec, value = '') => {
107
+ const errorMessages = Object.assign(Object.assign({}, validators_1.ErrorMessages), customErrorMessages);
108
108
  const valueLength = value === null || value === void 0 ? void 0 : value.length;
109
109
  if (!ignoreRequiredCheck && spec.required && !valueLength) {
110
110
  return errorMessages.REQUIRED;
@@ -95,12 +95,14 @@ export interface ObjectSpec<LinkType = any, InputComponentProps extends Record<s
95
95
  order?: string[];
96
96
  link?: LinkType;
97
97
  oneOfParams?: {
98
- toggler?: 'select' | 'radio' | 'card';
98
+ toggler?: 'select' | 'radio' | 'card' | 'checkbox';
99
+ booleanMap?: Record<'true' | 'false', string>;
99
100
  };
100
101
  placeholder?: string;
101
102
  hidden?: boolean;
102
103
  inputProps?: InputComponentProps;
103
104
  layoutProps?: LayoutComponentProps;
105
+ delimiter?: Record<string, string>;
104
106
  };
105
107
  }
106
108
  export interface StringSpec<LinkType = any, InputComponentProps extends Record<string, any> = {}, LayoutComponentProps extends Record<string, any> = {}> {
@@ -8,4 +8,10 @@
8
8
  }
9
9
  .df-object-base__content_inline > .df-use-search:last-child {
10
10
  margin-right: 0;
11
+ }
12
+ .df-object-base__delimiter {
13
+ display: flex;
14
+ margin-right: 8px;
15
+ align-items: center;
16
+ white-space: nowrap;
11
17
  }
@@ -1,8 +1,9 @@
1
1
  import { __rest } from "tslib";
2
2
  import React from 'react';
3
3
  import { Plus } from '@gravity-ui/icons';
4
- import { Button, Icon } from '@gravity-ui/uikit';
5
- import _ from 'lodash';
4
+ import { Button, Icon, Text } from '@gravity-ui/uikit';
5
+ import isObjectLike from 'lodash/isObjectLike';
6
+ import set from 'lodash/set';
6
7
  import { Controller, transformArrIn, } from '../../../../core';
7
8
  import { block, filterPropertiesForObjectInline } from '../../../utils';
8
9
  import './ObjectBase.css';
@@ -15,10 +16,10 @@ export const ObjectBase = (_a) => {
15
16
  React.createElement(Icon, { data: Plus, size: 14 }),
16
17
  spec.viewSpec.layoutTitle || null));
17
18
  }, [spec.defaultValue, spec.viewSpec.layoutTitle, restProps.input.onChange]);
18
- const parentOnChange = React.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) => _.set(Object.assign({}, currentValue), childName.split(`${restProps.input.name}.`).join(''), childValue), childErrors), [restProps.input.onChange, restProps.input.name]);
19
+ const parentOnChange = React.useCallback((childName, childValue, childErrors) => restProps.input.onChange((currentValue) => set(Object.assign({}, currentValue), childName.split(`${restProps.input.name}.`).join(''), childValue), childErrors), [restProps.input.onChange, restProps.input.name]);
19
20
  const content = React.useMemo(() => {
20
21
  if (!spec.properties ||
21
- !_.isObjectLike(spec.properties) ||
22
+ !isObjectLike(spec.properties) ||
22
23
  !Object.keys(spec.properties || {}).length) {
23
24
  return null;
24
25
  }
@@ -28,12 +29,17 @@ export const ObjectBase = (_a) => {
28
29
  const specProperties = inline
29
30
  ? filterPropertiesForObjectInline(spec.properties)
30
31
  : spec.properties;
31
- return (React.createElement("div", { className: b('content', { inline }) }, (spec.viewSpec.order || Object.keys(specProperties)).map((property) => {
32
+ const delimiter = spec.viewSpec.delimiter;
33
+ const orderProperties = spec.viewSpec.order || Object.keys(specProperties);
34
+ return (React.createElement("div", { className: b('content', { inline }) }, orderProperties.map((property) => {
32
35
  var _a;
33
- return specProperties[property] ? (React.createElement(Controller, { value: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: restProps.input.parentOnUnmount, key: `${name ? name + '.' : ''}${property}` })) : null;
36
+ return specProperties[property] ? (React.createElement(React.Fragment, { key: `${name ? name + '.' : ''}${property}` },
37
+ React.createElement(Controller, { value: (_a = restProps.input.value) === null || _a === void 0 ? void 0 : _a[property], spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, parentOnChange: parentOnChange, parentOnUnmount: restProps.input.parentOnUnmount }),
38
+ delimiter && delimiter[property] ? (React.createElement(Text, { className: b('delimiter') }, delimiter[property])) : null)) : null;
34
39
  })));
35
40
  }, [
36
41
  spec.properties,
42
+ spec.viewSpec.delimiter,
37
43
  spec.viewSpec.order,
38
44
  restProps.input.value,
39
45
  restProps.input.parentOnUnmount,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import _ from 'lodash';
3
3
  import { Controller } from '../../../../core';
4
- const OBJECT_VALUE_PROPERTY_NAME = 'value';
4
+ import { OBJECT_VALUE_PROPERTY_NAME } from '../../../constants/common';
5
5
  export const ObjectValueInput = (props) => {
6
6
  var _a;
7
7
  const { spec, input, name, Layout } = props;
@@ -8,4 +8,10 @@
8
8
  }
9
9
  .df-object-base-view__content_inline > div:last-child {
10
10
  margin-right: 0;
11
+ }
12
+ .df-object-base-view__delimiter {
13
+ display: flex;
14
+ margin-right: 8px;
15
+ align-items: center;
16
+ white-space: nowrap;
11
17
  }
@@ -1,20 +1,27 @@
1
1
  import { __rest } from "tslib";
2
2
  import React from 'react';
3
- import _ from 'lodash';
3
+ import { Text } from '@gravity-ui/uikit';
4
+ import isObjectLike from 'lodash/isObjectLike';
4
5
  import { ViewController } from '../../../../core';
5
6
  import { block, filterPropertiesForObjectInline } from '../../../utils';
6
7
  import './ObjectBaseView.css';
7
8
  const b = block('object-base-view');
8
9
  export const ObjectBaseView = (_a) => {
9
10
  var { inline, spec, name, Layout } = _a, restProps = __rest(_a, ["inline", "spec", "name", "Layout"]);
10
- if (!spec.properties || !_.isObjectLike(spec.properties)) {
11
- return null;
12
- }
13
- const specProperties = inline
14
- ? filterPropertiesForObjectInline(spec.properties)
15
- : spec.properties;
16
- const content = (React.createElement("div", { className: b('content', { inline }) }, (spec.viewSpec.order || Object.keys(specProperties)).map((property) => specProperties[property] ? (React.createElement(ViewController, { spec: specProperties[property], name: `${name ? name + '.' : ''}${property}`, key: `${name ? name + '.' : ''}${property}` })) : null)));
17
- if (!Layout) {
11
+ const content = React.useMemo(() => {
12
+ if (!spec.properties || !isObjectLike(spec.properties)) {
13
+ return null;
14
+ }
15
+ const specProperties = inline
16
+ ? filterPropertiesForObjectInline(spec.properties)
17
+ : spec.properties;
18
+ const delimiter = spec.viewSpec.delimiter;
19
+ const orderProperties = spec.viewSpec.order || Object.keys(specProperties);
20
+ return (React.createElement("div", { className: b('content', { inline }) }, orderProperties.map((property) => specProperties[property] ? (React.createElement(React.Fragment, { key: `${name ? name + '.' : ''}${property}` },
21
+ React.createElement(ViewController, { spec: specProperties[property], name: `${name ? name + '.' : ''}${property}` }),
22
+ delimiter && delimiter[property] ? (React.createElement(Text, { className: b('delimiter') }, delimiter[property])) : null)) : null)));
23
+ }, [inline, name, spec.properties, spec.viewSpec.delimiter, spec.viewSpec.order]);
24
+ if (!Layout || !content) {
18
25
  return content;
19
26
  }
20
27
  return (React.createElement(Layout, Object.assign({ spec: spec, name: name }, restProps), content));
@@ -2,7 +2,7 @@ import { __rest } from "tslib";
2
2
  import React from 'react';
3
3
  import _ from 'lodash';
4
4
  import { ViewController } from '../../../../core';
5
- const OBJECT_VALUE_PROPERTY_NAME = 'value';
5
+ import { OBJECT_VALUE_PROPERTY_NAME } from '../../../constants/common';
6
6
  export const ObjectValueInputView = (_a) => {
7
7
  var { spec, name, Layout } = _a, restProps = __rest(_a, ["spec", "name", "Layout"]);
8
8
  const childSpec = React.useMemo(() => {
@@ -2,19 +2,30 @@ import React from 'react';
2
2
  import _ from 'lodash';
3
3
  import { GroupIndent } from '../../';
4
4
  import { ViewController } from '../../../../core';
5
- import { block } from '../../../utils';
5
+ import { block, objectKeys } from '../../../utils';
6
6
  import './OneOfView.css';
7
7
  const b = block('oneof-view');
8
8
  const OneOfViewComponent = (props) => {
9
+ var _a, _b;
9
10
  const { value = {}, spec, Layout, name } = props;
10
11
  const specProperties = React.useMemo(() => (_.isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
12
+ const specBooleanMap = React.useMemo(() => { var _a; return (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap; }, [(_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap]);
11
13
  const valueKey = React.useMemo(() => Object.keys(value)[0], [value]);
12
14
  const valueName = React.useMemo(() => {
13
- var _a, _b;
14
- return (((_a = spec.description) === null || _a === void 0 ? void 0 : _a[valueKey]) ||
15
- ((_b = specProperties[valueKey]) === null || _b === void 0 ? void 0 : _b.viewSpec.layoutTitle) ||
15
+ var _a, _b, _c;
16
+ if (((_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler) === 'checkbox' && specBooleanMap) {
17
+ return objectKeys(specBooleanMap).find((key) => specBooleanMap[key] === valueKey);
18
+ }
19
+ return (((_b = spec.description) === null || _b === void 0 ? void 0 : _b[valueKey]) ||
20
+ ((_c = specProperties[valueKey]) === null || _c === void 0 ? void 0 : _c.viewSpec.layoutTitle) ||
16
21
  valueKey);
17
- }, [valueKey, spec.description, specProperties]);
22
+ }, [
23
+ valueKey,
24
+ spec.description,
25
+ specProperties,
26
+ (_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler,
27
+ specBooleanMap,
28
+ ]);
18
29
  const wrappedValue = React.useMemo(() => {
19
30
  if (Layout) {
20
31
  return (React.createElement(Layout, Object.assign({}, props, { value: valueName }),
@@ -1,3 +1,4 @@
1
1
  import type { PopoverProps } from '@gravity-ui/uikit';
2
2
  export declare const COMMON_POPOVER_PLACEMENT: PopoverProps['placement'];
3
3
  export declare const COMMON_TITLE_MAX_WIDTH = 533;
4
+ export declare const OBJECT_VALUE_PROPERTY_NAME = "value";
@@ -1,2 +1,3 @@
1
1
  export const COMMON_POPOVER_PLACEMENT = ['bottom', 'top'];
2
2
  export const COMMON_TITLE_MAX_WIDTH = 533;
3
+ export const OBJECT_VALUE_PROPERTY_NAME = 'value';
@@ -34,6 +34,7 @@ export const dynamicConfig = {
34
34
  row: Row,
35
35
  row_verbose: RowVerbose,
36
36
  table_item: TableCell,
37
+ transparent: Transparent,
37
38
  },
38
39
  validators: {
39
40
  base: getBooleanValidator(),
@@ -142,6 +143,7 @@ export const dynamicViewConfig = {
142
143
  row: ViewRow,
143
144
  row_verbose: ViewRow,
144
145
  table_item: ViewTableCell,
146
+ transparent: ViewTransparent,
145
147
  },
146
148
  },
147
149
  number: {
@@ -11,4 +11,9 @@
11
11
  }
12
12
  .df-use-oneof__card > :first-child {
13
13
  margin-right: 8px;
14
+ }
15
+ .df-use-oneof__checkbox {
16
+ height: 28px;
17
+ display: flex;
18
+ align-items: center;
14
19
  }
@@ -1,18 +1,20 @@
1
1
  import React from 'react';
2
- import { RadioButton, Select } from '@gravity-ui/uikit';
3
- import _ from 'lodash';
2
+ import { Checkbox, RadioButton, Select } from '@gravity-ui/uikit';
3
+ import isObjectLike from 'lodash/isObjectLike';
4
+ import some from 'lodash/some';
4
5
  import { TogglerCard } from '../../components';
5
- import { block } from '../../utils';
6
+ import { block, objectKeys } from '../../utils';
6
7
  import './useOneOf.css';
7
8
  const b = block('use-oneof');
8
9
  const MAX_TAB_TITLE_LENGTH = 20;
9
10
  export const useOneOf = ({ props, onTogglerChange }) => {
10
- var _a;
11
+ var _a, _b;
11
12
  const { name, input, spec, Layout } = props;
12
- const specProperties = React.useMemo(() => (_.isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
13
+ const specProperties = React.useMemo(() => (isObjectLike(spec.properties) ? spec.properties : {}), [spec.properties]);
14
+ const specBooleanMap = React.useMemo(() => { var _a; return (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap; }, [(_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.booleanMap]);
13
15
  const [oneOfValue, setOneOfValue] = React.useState(() => {
14
16
  let valueKeys;
15
- if (_.isObjectLike(input.value)) {
17
+ if (isObjectLike(input.value)) {
16
18
  const keys = Object.keys(input.value);
17
19
  if (keys.length) {
18
20
  valueKeys = keys;
@@ -27,6 +29,20 @@ export const useOneOf = ({ props, onTogglerChange }) => {
27
29
  onTogglerChange === null || onTogglerChange === void 0 ? void 0 : onTogglerChange(newValue);
28
30
  }
29
31
  }, [setOneOfValue, input.onChange, oneOfValue]);
32
+ const onCheckboxChange = React.useCallback((checked) => {
33
+ if (specBooleanMap) {
34
+ const value = String(checked);
35
+ const newValue = specBooleanMap[value];
36
+ onOneOfChange([newValue]);
37
+ }
38
+ }, [onOneOfChange, specBooleanMap]);
39
+ const checkboxValue = React.useMemo(() => {
40
+ if (specBooleanMap) {
41
+ const keyBooleanMap = objectKeys(specBooleanMap).find((key) => specBooleanMap[key] === oneOfValue);
42
+ return keyBooleanMap === 'true';
43
+ }
44
+ return undefined;
45
+ }, [oneOfValue, specBooleanMap]);
30
46
  const options = React.useMemo(() => (spec.viewSpec.order || Object.keys(specProperties)).map((value) => {
31
47
  var _a, _b;
32
48
  const title = ((_a = spec.description) === null || _a === void 0 ? void 0 : _a[value]) ||
@@ -40,18 +56,23 @@ export const useOneOf = ({ props, onTogglerChange }) => {
40
56
  };
41
57
  }), [spec.description, spec.viewSpec.order, specProperties]);
42
58
  const togglerType = React.useMemo(() => {
43
- var _a, _b, _c;
59
+ var _a, _b, _c, _d;
44
60
  if (((_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler) === 'card' && options.length < 3) {
45
61
  return 'card';
46
62
  }
47
63
  if (((_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler) !== 'radio' &&
48
64
  (((_c = spec.viewSpec.oneOfParams) === null || _c === void 0 ? void 0 : _c.toggler) === 'select' ||
49
65
  options.length > 3 ||
50
- _.some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))) {
66
+ some(options, ({ title }) => title.length > MAX_TAB_TITLE_LENGTH))) {
51
67
  return 'select';
52
68
  }
69
+ if (((_d = spec.viewSpec.oneOfParams) === null || _d === void 0 ? void 0 : _d.toggler) === 'checkbox' &&
70
+ options.length === 2 &&
71
+ specBooleanMap) {
72
+ return 'checkbox';
73
+ }
53
74
  return 'radio';
54
- }, [options, (_a = spec.viewSpec.oneOfParams) === null || _a === void 0 ? void 0 : _a.toggler]);
75
+ }, [options, (_b = spec.viewSpec.oneOfParams) === null || _b === void 0 ? void 0 : _b.toggler, specBooleanMap]);
55
76
  const togglerInput = React.useMemo(() => {
56
77
  if (togglerType === 'card') {
57
78
  return (React.createElement("div", { className: b('card') }, options.map(({ value }) => {
@@ -65,15 +86,22 @@ export const useOneOf = ({ props, onTogglerChange }) => {
65
86
  if (togglerType === 'select') {
66
87
  return (React.createElement(Select, { width: "max", value: [oneOfValue], onUpdate: onOneOfChange, options: options, disabled: spec.viewSpec.disabled, filterable: options.length > 7, qa: name }));
67
88
  }
89
+ if (togglerType === 'checkbox') {
90
+ return (React.createElement("div", { className: b('checkbox') },
91
+ React.createElement(Checkbox, { checked: checkboxValue, onUpdate: onCheckboxChange, disabled: spec.viewSpec.disabled, qa: name })));
92
+ }
68
93
  return (React.createElement(RadioButton, { value: oneOfValue, onChange: (event) => onOneOfChange([event.target.value]), disabled: spec.viewSpec.disabled, qa: name }, options.map((option) => (React.createElement(RadioButton.Option, { key: option.value, value: option.value }, option.title)))));
69
94
  }, [
70
95
  togglerType,
71
96
  oneOfValue,
72
97
  spec.viewSpec.disabled,
98
+ spec.description,
73
99
  name,
74
100
  options,
75
101
  onOneOfChange,
76
102
  specProperties,
103
+ onCheckboxChange,
104
+ checkboxValue,
77
105
  ]);
78
106
  const toggler = React.useMemo(() => {
79
107
  if (Layout) {
@@ -2,3 +2,4 @@ export * from './cn';
2
2
  export * from './common';
3
3
  export * from './bigIntMath';
4
4
  export * from './objectInline';
5
+ export * from './objectKeys';
@@ -2,3 +2,4 @@ export * from './cn';
2
2
  export * from './common';
3
3
  export * from './bigIntMath';
4
4
  export * from './objectInline';
5
+ export * from './objectKeys';
@@ -1,4 +1,4 @@
1
- import { isNumberSpec, isStringSpec } from '../../core';
1
+ import { isBooleanSpec, isNumberSpec, isStringSpec } from '../../core';
2
2
  export const filterPropertiesForObjectInline = (properties) => {
3
- return Object.fromEntries(Object.entries(properties).filter(([, propSpec]) => isStringSpec(propSpec) || isNumberSpec(propSpec)));
3
+ return Object.fromEntries(Object.entries(properties).filter(([, propSpec]) => isStringSpec(propSpec) || isNumberSpec(propSpec) || isBooleanSpec(propSpec)));
4
4
  };
@@ -0,0 +1,4 @@
1
+ type Dictionary<T> = Record<string, T>;
2
+ type KeysOf<T> = T extends Dictionary<unknown> ? `${Exclude<keyof T, symbol>}` : never;
3
+ export declare function objectKeys<T extends Dictionary<unknown>>(obj: T): KeysOf<T>[];
4
+ export {};
@@ -0,0 +1,3 @@
1
+ export function objectKeys(obj) {
2
+ return Object.keys(obj);
3
+ }
@@ -3,8 +3,8 @@ import { ErrorMessages } from '../validators';
3
3
  import { isFloat, isInt } from './helpers';
4
4
  export const getArrayValidator = (params = {}) => {
5
5
  const { ignoreRequiredCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, customErrorMessages } = params;
6
- const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
7
6
  return (spec, value) => {
7
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
8
8
  const valueLength = (value === null || value === void 0 ? void 0 : value.length) || 0;
9
9
  if (!ignoreRequiredCheck && spec.required && !_.isArray(value)) {
10
10
  return errorMessages.REQUIRED;
@@ -24,8 +24,8 @@ export const getArrayValidator = (params = {}) => {
24
24
  };
25
25
  export const getBooleanValidator = (params = {}) => {
26
26
  const { ignoreRequiredCheck, customErrorMessages } = params;
27
- const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
28
27
  return (spec, value) => {
28
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
29
29
  if (!ignoreRequiredCheck && spec.required && !value) {
30
30
  return errorMessages.REQUIRED;
31
31
  }
@@ -34,9 +34,9 @@ export const getBooleanValidator = (params = {}) => {
34
34
  };
35
35
  export const getNumberValidator = (params = {}) => {
36
36
  const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreNumberCheck, ignoreMaximumCheck, ignoreMinimumCheck, ignoreIntCheck, ignoreDotEnd, ignoreZeroStart, customErrorMessages, } = params;
37
- const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
38
37
  // eslint-disable-next-line complexity
39
38
  return (spec, value = '') => {
39
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
40
40
  const stringValue = String(value);
41
41
  if (!ignoreRequiredCheck && spec.required && !stringValue.length) {
42
42
  return errorMessages.REQUIRED;
@@ -84,8 +84,8 @@ export const getNumberValidator = (params = {}) => {
84
84
  };
85
85
  export const getObjectValidator = (params = {}) => {
86
86
  const { ignoreRequiredCheck, customErrorMessages } = params;
87
- const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
88
87
  return (spec, value) => {
88
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
89
89
  if (!ignoreRequiredCheck && spec.required && !value) {
90
90
  return errorMessages.REQUIRED;
91
91
  }
@@ -94,9 +94,9 @@ export const getObjectValidator = (params = {}) => {
94
94
  };
95
95
  export const getStringValidator = (params = {}) => {
96
96
  const { ignoreRequiredCheck, ignoreSpaceStartCheck, ignoreSpaceEndCheck, ignoreMaxLengthCheck, ignoreMinLengthCheck, ignoreRegExpCheck, customErrorMessages, } = params;
97
- const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
98
97
  // eslint-disable-next-line complexity
99
98
  return (spec, value = '') => {
99
+ const errorMessages = Object.assign(Object.assign({}, ErrorMessages), customErrorMessages);
100
100
  const valueLength = value === null || value === void 0 ? void 0 : value.length;
101
101
  if (!ignoreRequiredCheck && spec.required && !valueLength) {
102
102
  return errorMessages.REQUIRED;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "3.6.1",
3
+ "version": "3.8.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",