@gravity-ui/dynamic-forms 1.7.1 → 1.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.8.1](https://github.com/gravity-ui/dynamic-forms/compare/v1.8.0...v1.8.1) (2023-05-30)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * fixed deleting numbers from arrays ([#50](https://github.com/gravity-ui/dynamic-forms/issues/50)) ([76fba69](https://github.com/gravity-ui/dynamic-forms/commit/76fba69c47e016fb806d5d2d06fa367f4672c524))
9
+
10
+ ## [1.8.0](https://github.com/gravity-ui/dynamic-forms/compare/v1.7.1...v1.8.0) (2023-05-25)
11
+
12
+
13
+ ### Features
14
+
15
+ * **Switch:** added new input switch ([#48](https://github.com/gravity-ui/dynamic-forms/issues/48)) ([47e2f51](https://github.com/gravity-ui/dynamic-forms/commit/47e2f51dcda0579b00f6fadc3008d2e78a2f47e7))
16
+
3
17
  ## [1.7.1](https://github.com/gravity-ui/dynamic-forms/compare/v1.7.0...v1.7.1) (2023-05-22)
4
18
 
5
19
 
@@ -55,7 +55,7 @@ const useField = ({ name, spec, initialValue, value: externalValue, validate: pr
55
55
  const _value = lodash_1.default.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
56
56
  const error = validate === null || validate === void 0 ? void 0 : validate(_value);
57
57
  let value = (0, utils_1.transformArrIn)(_value);
58
- if ((0, helpers_1.isNumberSpec)(spec) && value && !error) {
58
+ if ((0, helpers_1.isNumberSpec)(spec) && value && value !== constants_1.REMOVED_ITEM && !error) {
59
59
  value = Number(value);
60
60
  }
61
61
  let newChildErrors = Object.assign({}, state.childErrors);
@@ -0,0 +1,5 @@
1
+ .df-switch {
2
+ height: 28px;
3
+ display: flex;
4
+ align-items: center;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Switch = 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)('switch');
9
+ const Switch = ({ name, input, spec }) => {
10
+ const { value, onBlur, onChange, onFocus } = input;
11
+ const handleChange = react_1.default.useCallback((e) => onChange(e.target.checked), [onChange]);
12
+ return (react_1.default.createElement(uikit_1.Switch, { checked: value, onChange: handleChange, onBlur: onBlur, onFocus: onFocus, disabled: spec.viewSpec.disabled, className: b(), qa: name }));
13
+ };
14
+ exports.Switch = Switch;
@@ -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("./Switch"), exports);
@@ -12,6 +12,7 @@ tslib_1.__exportStar(require("./OneOf"), exports);
12
12
  tslib_1.__exportStar(require("./OneOfCard"), exports);
13
13
  tslib_1.__exportStar(require("./Secret"), exports);
14
14
  tslib_1.__exportStar(require("./Select"), exports);
15
+ tslib_1.__exportStar(require("./Switch"), exports);
15
16
  tslib_1.__exportStar(require("./TableArrayInput"), exports);
16
17
  tslib_1.__exportStar(require("./Text"), exports);
17
18
  tslib_1.__exportStar(require("./TextArea"), exports);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ArrayBaseView = 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
7
  const core_1 = require("../../../core");
7
8
  const ArrayBaseView = ({ spec, name, value = [] }) => {
8
9
  const itemSpecCorrect = react_1.default.useMemo(() => (0, core_1.isCorrectSpec)(spec.items), [spec.items]);
@@ -16,7 +17,7 @@ const ArrayBaseView = ({ spec, name, value = [] }) => {
16
17
  : `${idx + 1}` });
17
18
  return itemSpec;
18
19
  }, [spec.items, itemSpecCorrect]);
19
- const items = react_1.default.useMemo(() => value.map((__, idx) => {
20
+ const items = react_1.default.useMemo(() => lodash_1.default.map(value, (__, idx) => {
20
21
  const itemSpec = getItemSpec(idx);
21
22
  if (!itemSpec) {
22
23
  return null;
@@ -30,6 +30,7 @@ exports.dynamicConfig = {
30
30
  boolean: {
31
31
  inputs: {
32
32
  base: { Component: components_1.Checkbox },
33
+ switch: { Component: components_1.Switch },
33
34
  },
34
35
  layouts: {
35
36
  row: components_1.Row,
@@ -132,6 +133,7 @@ exports.dynamicCardConfig = {
132
133
  boolean: {
133
134
  inputs: {
134
135
  base: { Component: components_1.Checkbox },
136
+ switch: { Component: components_1.Switch },
135
137
  },
136
138
  layouts: {
137
139
  row: components_1.Row2,
@@ -224,6 +226,7 @@ exports.dynamicViewConfig = {
224
226
  boolean: {
225
227
  views: {
226
228
  base: { Component: components_1.BaseView },
229
+ switch: { Component: components_1.BaseView },
227
230
  },
228
231
  layouts: {
229
232
  row: components_1.ViewRow,
@@ -306,6 +309,7 @@ exports.dynamicViewCardConfig = {
306
309
  boolean: {
307
310
  views: {
308
311
  base: { Component: components_1.BaseView },
312
+ switch: { Component: components_1.BaseView },
309
313
  },
310
314
  layouts: {
311
315
  row: components_1.ViewRow2,
@@ -51,7 +51,7 @@ export const useField = ({ name, spec, initialValue, value: externalValue, valid
51
51
  const _value = _.isFunction(valOrSetter) ? valOrSetter(state.value) : valOrSetter;
52
52
  const error = validate === null || validate === void 0 ? void 0 : validate(_value);
53
53
  let value = transformArrIn(_value);
54
- if (isNumberSpec(spec) && value && !error) {
54
+ if (isNumberSpec(spec) && value && value !== REMOVED_ITEM && !error) {
55
55
  value = Number(value);
56
56
  }
57
57
  let newChildErrors = Object.assign({}, state.childErrors);
@@ -0,0 +1,5 @@
1
+ .df-switch {
2
+ height: 28px;
3
+ display: flex;
4
+ align-items: center;
5
+ }
@@ -0,0 +1,3 @@
1
+ import { BooleanInput } from '../../../../core';
2
+ import './Switch.css';
3
+ export declare const Switch: BooleanInput;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { Switch as SwitchBase } from '@gravity-ui/uikit';
3
+ import { block } from '../../../utils';
4
+ import './Switch.css';
5
+ const b = block('switch');
6
+ export const Switch = ({ name, input, spec }) => {
7
+ const { value, onBlur, onChange, onFocus } = input;
8
+ const handleChange = React.useCallback((e) => onChange(e.target.checked), [onChange]);
9
+ return (React.createElement(SwitchBase, { checked: value, onChange: handleChange, onBlur: onBlur, onFocus: onFocus, disabled: spec.viewSpec.disabled, className: b(), qa: name }));
10
+ };
@@ -0,0 +1 @@
1
+ export * from './Switch';
@@ -0,0 +1 @@
1
+ export * from './Switch';
@@ -9,6 +9,7 @@ export * from './OneOf';
9
9
  export * from './OneOfCard';
10
10
  export * from './Secret';
11
11
  export * from './Select';
12
+ export * from './Switch';
12
13
  export * from './TableArrayInput';
13
14
  export * from './Text';
14
15
  export * from './TextArea';
@@ -9,6 +9,7 @@ export * from './OneOf';
9
9
  export * from './OneOfCard';
10
10
  export * from './Secret';
11
11
  export * from './Select';
12
+ export * from './Switch';
12
13
  export * from './TableArrayInput';
13
14
  export * from './Text';
14
15
  export * from './TextArea';
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import _ from 'lodash';
2
3
  import { ViewController, isCorrectSpec } from '../../../core';
3
4
  export const ArrayBaseView = ({ spec, name, value = [] }) => {
4
5
  const itemSpecCorrect = React.useMemo(() => isCorrectSpec(spec.items), [spec.items]);
@@ -12,7 +13,7 @@ export const ArrayBaseView = ({ spec, name, value = [] }) => {
12
13
  : `${idx + 1}` });
13
14
  return itemSpec;
14
15
  }, [spec.items, itemSpecCorrect]);
15
- const items = React.useMemo(() => value.map((__, idx) => {
16
+ const items = React.useMemo(() => _.map(value, (__, idx) => {
16
17
  const itemSpec = getItemSpec(idx);
17
18
  if (!itemSpec) {
18
19
  return null;
@@ -1,4 +1,4 @@
1
- import { Accordeon, AccordeonCardLayout, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoInputCard, MonacoView, MonacoViewCard, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfCard, OneOfCardView, OneOfFlat, OneOfFlatView, OneOfView, Row, Row2, RowVerbose, Secret, Section, Section2, SectionCard, SectionCard2, SectionWithSubtitle, SectionWithSubtitle2, Select, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextLink, TextLinkView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewRow2, ViewSection, ViewSection2, ViewSectionCard, ViewSectionCard2, ViewTableCell, ViewTransparent, } from '../components';
1
+ import { Accordeon, AccordeonCardLayout, ArrayBase, ArrayBaseView, BaseView, CardAccordeon, CardOneOf, CardOneOfView, CardSection, Checkbox, FileInput, FileInputView, Group, Group2, MonacoInput, MonacoInputCard, MonacoView, MonacoViewCard, MultiSelect, MultiSelectView, NumberWithScale, NumberWithScaleView, ObjectBase, ObjectBaseView, ObjectValueInput, ObjectValueInputView, OneOf, OneOfCard, OneOfCardView, OneOfFlat, OneOfFlatView, OneOfView, Row, Row2, RowVerbose, Secret, Section, Section2, SectionCard, SectionCard2, SectionWithSubtitle, SectionWithSubtitle2, Select, Switch, TableArrayInput, TableArrayView, TableCell, Text, TextArea, TextAreaView, TextContent, TextLink, TextLinkView, Transparent, ViewAccordeon, ViewAccordeonCard, ViewCardAccordeon, ViewCardSection, ViewGroup, ViewGroup2, ViewRow, ViewRow2, ViewSection, ViewSection2, ViewSectionCard, ViewSectionCard2, ViewTableCell, ViewTransparent, } from '../components';
2
2
  import { getArrayValidator, getBooleanValidator, getNumberValidator, getObjectValidator, getStringValidator, } from '../validators';
3
3
  export const dynamicConfig = {
4
4
  array: {
@@ -27,6 +27,7 @@ export const dynamicConfig = {
27
27
  boolean: {
28
28
  inputs: {
29
29
  base: { Component: Checkbox },
30
+ switch: { Component: Switch },
30
31
  },
31
32
  layouts: {
32
33
  row: Row,
@@ -129,6 +130,7 @@ export const dynamicCardConfig = {
129
130
  boolean: {
130
131
  inputs: {
131
132
  base: { Component: Checkbox },
133
+ switch: { Component: Switch },
132
134
  },
133
135
  layouts: {
134
136
  row: Row2,
@@ -221,6 +223,7 @@ export const dynamicViewConfig = {
221
223
  boolean: {
222
224
  views: {
223
225
  base: { Component: BaseView },
226
+ switch: { Component: BaseView },
224
227
  },
225
228
  layouts: {
226
229
  row: ViewRow,
@@ -303,6 +306,7 @@ export const dynamicViewCardConfig = {
303
306
  boolean: {
304
307
  views: {
305
308
  base: { Component: BaseView },
309
+ switch: { Component: BaseView },
306
310
  },
307
311
  layouts: {
308
312
  row: ViewRow2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "1.7.1",
3
+ "version": "1.8.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",