@gravity-ui/dynamic-forms 5.11.0 → 5.12.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.
@@ -38,4 +38,10 @@
38
38
  }
39
39
  .df-array-base__add-button_right {
40
40
  margin-left: var(--df-array-base-add-button-right-margin-left, var(--g-spacing-1));
41
+ }
42
+ .df-array-base_add-button-right > div:last-child {
43
+ transition: margin-bottom 0.2s ease-in-out;
44
+ }
45
+ .df-array-base_add-button-right_error {
46
+ margin-bottom: var(--df-array-base-add-button-right-error-margin-bottom, 18px);
41
47
  }
@@ -9,7 +9,7 @@ const set_1 = tslib_1.__importDefault(require("lodash/set"));
9
9
  const core_1 = require("../../../../core");
10
10
  const utils_1 = require("../../../utils");
11
11
  const b = (0, utils_1.block)('array-base');
12
- const ArrayBase = ({ spec, name, arrayInput, input }) => {
12
+ const ArrayBase = ({ spec, name, arrayInput, input, meta }) => {
13
13
  const keys = react_1.default.useMemo(() => Object.keys(arrayInput.value || {})
14
14
  .filter((k) => k !== core_1.OBJECT_ARRAY_FLAG && k !== core_1.OBJECT_ARRAY_CNT)
15
15
  .map((k) => k.split('<').join('').split('>').join(''))
@@ -72,6 +72,14 @@ const ArrayBase = ({ spec, name, arrayInput, input }) => {
72
72
  input.value,
73
73
  spec.viewSpec.itemPrefix,
74
74
  ]);
75
+ const hasErrorInLastItem = react_1.default.useMemo(() => {
76
+ if (keys.length === 0) {
77
+ return false;
78
+ }
79
+ const lastKey = keys[keys.length - 1];
80
+ const lastItemName = `${name}.<${lastKey}>`;
81
+ return Boolean(meta.childErrors[lastItemName]);
82
+ }, [keys, name, meta.childErrors]);
75
83
  if (!itemSpecCorrect) {
76
84
  return null;
77
85
  }
@@ -80,6 +88,9 @@ const ArrayBase = ({ spec, name, arrayInput, input }) => {
80
88
  'add-button-down': spec.viewSpec.addButtonPosition !== 'right' && keys.length > 0,
81
89
  'items-primitive': itemsPrimitive,
82
90
  }) }, items),
83
- react_1.default.createElement(AddButton, null)));
91
+ react_1.default.createElement("div", { className: b({
92
+ 'add-button-right_error': spec.viewSpec.addButtonPosition === 'right' && hasErrorInLastItem,
93
+ }) },
94
+ react_1.default.createElement(AddButton, null))));
84
95
  };
85
96
  exports.ArrayBase = ArrayBase;
@@ -38,4 +38,10 @@
38
38
  }
39
39
  .df-array-base__add-button_right {
40
40
  margin-left: var(--df-array-base-add-button-right-margin-left, var(--g-spacing-1));
41
+ }
42
+ .df-array-base_add-button-right > div:last-child {
43
+ transition: margin-bottom 0.2s ease-in-out;
44
+ }
45
+ .df-array-base_add-button-right_error {
46
+ margin-bottom: var(--df-array-base-add-button-right-error-margin-bottom, 18px);
41
47
  }
@@ -6,7 +6,7 @@ import { Controller, OBJECT_ARRAY_CNT, OBJECT_ARRAY_FLAG, isBooleanSpec, isCorre
6
6
  import { block } from '../../../utils';
7
7
  import './ArrayBase.css';
8
8
  const b = block('array-base');
9
- export const ArrayBase = ({ spec, name, arrayInput, input }) => {
9
+ export const ArrayBase = ({ spec, name, arrayInput, input, meta }) => {
10
10
  const keys = React.useMemo(() => Object.keys(arrayInput.value || {})
11
11
  .filter((k) => k !== OBJECT_ARRAY_FLAG && k !== OBJECT_ARRAY_CNT)
12
12
  .map((k) => k.split('<').join('').split('>').join(''))
@@ -69,6 +69,14 @@ export const ArrayBase = ({ spec, name, arrayInput, input }) => {
69
69
  input.value,
70
70
  spec.viewSpec.itemPrefix,
71
71
  ]);
72
+ const hasErrorInLastItem = React.useMemo(() => {
73
+ if (keys.length === 0) {
74
+ return false;
75
+ }
76
+ const lastKey = keys[keys.length - 1];
77
+ const lastItemName = `${name}.<${lastKey}>`;
78
+ return Boolean(meta.childErrors[lastItemName]);
79
+ }, [keys, name, meta.childErrors]);
72
80
  if (!itemSpecCorrect) {
73
81
  return null;
74
82
  }
@@ -77,5 +85,8 @@ export const ArrayBase = ({ spec, name, arrayInput, input }) => {
77
85
  'add-button-down': spec.viewSpec.addButtonPosition !== 'right' && keys.length > 0,
78
86
  'items-primitive': itemsPrimitive,
79
87
  }) }, items),
80
- React.createElement(AddButton, null)));
88
+ React.createElement("div", { className: b({
89
+ 'add-button-right_error': spec.viewSpec.addButtonPosition === 'right' && hasErrorInLastItem,
90
+ }) },
91
+ React.createElement(AddButton, null))));
81
92
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "5.11.0",
3
+ "version": "5.12.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",