iglooform 2.4.9 → 2.4.10

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 (47) hide show
  1. package/es/button/style/index.less +11 -25
  2. package/es/form/addable-section/index.d.ts +14 -0
  3. package/es/form/addable-section/index.js +188 -0
  4. package/es/form/addable-section/style/index.d.ts +1 -0
  5. package/es/form/addable-section/style/index.js +1 -0
  6. package/es/form/addable-section/style/index.less +22 -0
  7. package/es/form/element/index.js +11 -0
  8. package/es/form/section/index.js +1 -1
  9. package/es/free-form/addable-section/index.d.ts +13 -0
  10. package/es/free-form/addable-section/index.js +263 -0
  11. package/es/free-form/addable-section/style/index.d.ts +1 -0
  12. package/es/free-form/addable-section/style/index.js +1 -0
  13. package/es/free-form/addable-section/style/index.less +22 -0
  14. package/es/free-form/section/index.js +1 -1
  15. package/es/index.d.ts +1 -0
  16. package/es/index.js +2 -1
  17. package/es/input/style/index.less +9 -1
  18. package/es/locale/en-US/messages.json +2 -0
  19. package/es/locale/id-ID/messages.json +2 -0
  20. package/es/locale/th-TH/messages.json +2 -0
  21. package/es/locale/vi-VN/messages.json +2 -0
  22. package/es/locale/zh-CN/messages.json +2 -0
  23. package/es/utils/form-utils.js +1 -1
  24. package/lib/button/style/index.less +11 -25
  25. package/lib/form/addable-section/index.d.ts +14 -0
  26. package/lib/form/addable-section/index.js +209 -0
  27. package/lib/form/addable-section/style/index.d.ts +1 -0
  28. package/lib/form/addable-section/style/index.js +3 -0
  29. package/lib/form/addable-section/style/index.less +22 -0
  30. package/lib/form/element/index.js +12 -0
  31. package/lib/form/section/index.js +1 -1
  32. package/lib/free-form/addable-section/index.d.ts +13 -0
  33. package/lib/free-form/addable-section/index.js +283 -0
  34. package/lib/free-form/addable-section/style/index.d.ts +1 -0
  35. package/lib/free-form/addable-section/style/index.js +3 -0
  36. package/lib/free-form/addable-section/style/index.less +22 -0
  37. package/lib/free-form/section/index.js +1 -1
  38. package/lib/index.d.ts +1 -0
  39. package/lib/index.js +10 -1
  40. package/lib/input/style/index.less +9 -1
  41. package/lib/locale/en-US/messages.json +2 -0
  42. package/lib/locale/id-ID/messages.json +2 -0
  43. package/lib/locale/th-TH/messages.json +2 -0
  44. package/lib/locale/vi-VN/messages.json +2 -0
  45. package/lib/locale/zh-CN/messages.json +2 -0
  46. package/lib/utils/form-utils.js +1 -1
  47. package/package.json +1 -1
@@ -9,35 +9,20 @@
9
9
  box-shadow: none;
10
10
  &[disabled] {
11
11
  opacity: 0.3;
12
- border: none;
13
- }
14
- }
15
-
16
- .ant-btn-default {
17
- background-color: transparent;
18
- color: @primary-color;
19
- border: 1px solid @primary-color;
20
- &:hover {
21
- color: @btn-hover-color;
22
- border-color: @btn-hover-color;
23
- background-color: transparent;
24
- }
25
- &:active,
26
- &:focus {
27
- color: @btn-focus-color;
28
- border-color: @btn-focus-color;
29
- background-color: transparent;
30
- }
31
- &[disabled] {
32
12
  color: @primary-color;
33
- background-color: transparent;
34
13
  border: 1px solid @primary-color;
14
+ background-color: transparent;
35
15
 
36
- &:focus,
37
16
  &:hover {
38
- color: @primary-color;
17
+ color: @btn-hover-color;
18
+ border-color: @btn-hover-color;
19
+ background-color: transparent;
20
+ }
21
+ &:active,
22
+ &:focus {
23
+ color: @btn-focus-color;
24
+ border-color: @btn-focus-color;
39
25
  background-color: transparent;
40
- border: 1px solid @primary-color;
41
26
  }
42
27
  }
43
28
  }
@@ -81,6 +66,7 @@
81
66
  }
82
67
 
83
68
  &[disabled] {
69
+ border: none;
84
70
  color: @primary-color;
85
71
  &:hover {
86
72
  color: @primary-color;
@@ -103,8 +89,8 @@
103
89
  }
104
90
 
105
91
  &[disabled] {
92
+ border: none;
106
93
  color: @black;
107
-
108
94
  &:hover {
109
95
  color: @black;
110
96
  background-color: transparent;
@@ -0,0 +1,14 @@
1
+ import { FC } from 'react';
2
+ import { FormItemProps } from 'antd/es/form';
3
+ import { FormItemConfig, FormItemName } from '../../types';
4
+ import './style/index.less';
5
+ export interface AddableSectionProps {
6
+ parentName?: FormItemName;
7
+ formItemProps?: FormItemProps;
8
+ config: FormItemConfig;
9
+ preview?: boolean;
10
+ disabled?: boolean;
11
+ setShowStepButton?: (showButton: boolean) => void;
12
+ }
13
+ declare const AddableSection: FC<AddableSectionProps>;
14
+ export default AddableSection;
@@ -0,0 +1,188 @@
1
+ import "antd/es/row/style";
2
+ import _Row from "antd/es/row";
3
+ import "antd/es/col/style";
4
+ import _Col from "antd/es/col";
5
+
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7
+
8
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
+
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+
12
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
13
+
14
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+
16
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
+
18
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
+
20
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
+
22
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
+
24
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
+
26
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
27
+
28
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
29
+
30
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
+
32
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
33
+ import { useReducer, useContext } from 'react';
34
+ import Element from '../element';
35
+ import FormContext from '../context';
36
+ import { calcNamePath, calcFormItemProps } from '../../utils/form-utils';
37
+ import Typography from '../../typography';
38
+ import Button from '../../button';
39
+ import { LocaleContext } from '../../locale';
40
+ import './style/index.less';
41
+
42
+ var AddableSection = function AddableSection(_ref) {
43
+ var parentName = _ref.parentName,
44
+ config = _ref.config,
45
+ preview = _ref.preview,
46
+ disabled = _ref.disabled,
47
+ setShowStepButton = _ref.setShowStepButton;
48
+ var _config$elements = config.elements,
49
+ elements = _config$elements === void 0 ? [] : _config$elements,
50
+ name = config.name,
51
+ label = config.label,
52
+ _config$labelProps = config.labelProps,
53
+ labelProps = _config$labelProps === void 0 ? {} : _config$labelProps,
54
+ _config$contentProps = config.contentProps,
55
+ contentProps = _config$contentProps === void 0 ? {} : _config$contentProps,
56
+ _config$style = config.style,
57
+ style = _config$style === void 0 ? {} : _config$style,
58
+ _config$max = config.max,
59
+ max = _config$max === void 0 ? Number.MAX_SAFE_INTEGER : _config$max;
60
+
61
+ var _useContext = useContext(LocaleContext),
62
+ formatMessage = _useContext.formatMessage;
63
+
64
+ var _useContext2 = useContext(FormContext),
65
+ form = _useContext2.form,
66
+ requiredMark = _useContext2.requiredMark;
67
+
68
+ var namePath = calcNamePath(parentName, name);
69
+
70
+ var _useReducer = useReducer(function (state, action) {
71
+ if (action.type === 'add') {
72
+ return [].concat(_toConsumableArray(state), [action.key]);
73
+ }
74
+
75
+ var found = false;
76
+ return state.filter(function (key, index) {
77
+ if (key === action.key) {
78
+ found = true;
79
+ return false;
80
+ }
81
+
82
+ if (found) {
83
+ form === null || form === void 0 ? void 0 : form.setFields([{
84
+ name: calcNamePath(namePath, index - 1),
85
+ value: form.getFieldValue(calcNamePath(namePath, index))
86
+ }]);
87
+ }
88
+
89
+ return true;
90
+ });
91
+ }, [Date.now()]),
92
+ _useReducer2 = _slicedToArray(_useReducer, 2),
93
+ groupKeys = _useReducer2[0],
94
+ dispath = _useReducer2[1];
95
+
96
+ var _calcFormItemProps = calcFormItemProps(config, {
97
+ requiredMark: requiredMark
98
+ }, form, parentName),
99
+ formItemProps = _calcFormItemProps.formItemProps,
100
+ elementProps = _calcFormItemProps.elementProps,
101
+ display = _calcFormItemProps.display;
102
+
103
+ if (formItemProps.copiedValue.copied) {
104
+ var currentValue = form === null || form === void 0 ? void 0 : form.getFieldValue(namePath);
105
+
106
+ var value = _objectSpread(_objectSpread({}, currentValue), formItemProps.copiedValue.value);
107
+
108
+ form === null || form === void 0 ? void 0 : form.setFields([{
109
+ name: namePath,
110
+ value: value,
111
+ errors: []
112
+ }]);
113
+ }
114
+
115
+ if (!display) {
116
+ return null;
117
+ }
118
+
119
+ var groups = groupKeys.map(function (key, index) {
120
+ var parentName = calcNamePath(namePath, index);
121
+ return _jsxs(_Col, {
122
+ span: 24,
123
+ className: 'igloo-freeform-addable-section',
124
+ children: [label && _jsxs(_Row, {
125
+ justify: "space-between",
126
+ className: 'igloo-freeform-addable-section-label',
127
+ children: [_jsxs(Typography, _objectSpread(_objectSpread({}, labelProps), {}, {
128
+ level: "h4",
129
+ wrapElement: "div",
130
+ children: [label, " ", index + 1]
131
+ }), void 0), groupKeys.length > 1 && !preview && _jsx(Button, {
132
+ type: "link",
133
+ className: "igloo-freeform-addable-section-label-remove",
134
+ onClick: function onClick() {
135
+ return dispath({
136
+ type: 'remove',
137
+ key: key
138
+ });
139
+ },
140
+ children: formatMessage({
141
+ id: 'Remove'
142
+ })
143
+ }, void 0)]
144
+ }, void 0), _jsx("div", _objectSpread(_objectSpread({
145
+ className: 'igloo-freeform-addable-section-content'
146
+ }, contentProps), {}, {
147
+ children: _jsx(_Row, {
148
+ gutter: [32, preview ? 16 : 24],
149
+ children: elements.map(function (child, index) {
150
+ return _jsx(Element, {
151
+ parentName: parentName,
152
+ config: child,
153
+ disabled: elementProps.disabled || disabled,
154
+ preview: preview,
155
+ setShowStepButton: setShowStepButton
156
+ }, index);
157
+ })
158
+ }, void 0)
159
+ }), void 0)]
160
+ }, key);
161
+ });
162
+ return _jsxs("div", {
163
+ className: "igloo-freeform-addable-section-container",
164
+ style: {
165
+ width: '100%'
166
+ },
167
+ children: [groups, groupKeys.length < max && !preview && _jsx(_Col, {
168
+ span: 24,
169
+ style: {
170
+ marginTop: 16
171
+ },
172
+ children: _jsxs(Button, {
173
+ onClick: function onClick() {
174
+ return dispath({
175
+ type: 'add',
176
+ key: Date.now()
177
+ });
178
+ },
179
+ className: "igloo-freeform-addable-section-button",
180
+ children: [formatMessage({
181
+ id: 'Add'
182
+ }), " ", label]
183
+ }, void 0)
184
+ }, void 0)]
185
+ }, void 0);
186
+ };
187
+
188
+ export default AddableSection;
@@ -0,0 +1 @@
1
+ import './index.less';
@@ -0,0 +1 @@
1
+ import './index.less';
@@ -0,0 +1,22 @@
1
+ .igloo-freeform-addable-section-container {
2
+ .igloo-freeform-addable-section {
3
+ .igloo-freeform-addable-section-label {
4
+ .igloo-freeform-addable-section-label-remove {
5
+ height: auto;
6
+ border: none;
7
+ }
8
+ }
9
+
10
+ .igloo-freeform-addable-section-content {
11
+ margin-top: 16px;
12
+ }
13
+
14
+ & + .igloo-freeform-addable-section {
15
+ margin-top: 24px;
16
+ }
17
+ }
18
+
19
+ .igloo-freeform-addable-section-button {
20
+ min-width: 221px;
21
+ }
22
+ }
@@ -46,6 +46,7 @@ import { useContext, useEffect, useRef, useReducer } from 'react';
46
46
  import { CloseCircleFilled } from '@ant-design/icons';
47
47
  import { calcFormItemProps } from '../../utils/form-utils';
48
48
  import Section from '../section';
49
+ import AddableSection from '../addable-section';
49
50
  import useComponent from '../elements';
50
51
  import FormContext from '../context';
51
52
  import invariant from 'invariant';
@@ -151,6 +152,16 @@ var Element = function Element(_ref) {
151
152
  }, void 0);
152
153
  }
153
154
 
155
+ if (type === 'AddableSection') {
156
+ return _jsx(AddableSection, {
157
+ parentName: parentName,
158
+ config: config,
159
+ preview: preview,
160
+ disabled: disabled,
161
+ setShowStepButton: setShowStepButton
162
+ }, void 0);
163
+ }
164
+
154
165
  var _calcFormItemProps = calcFormItemProps(config, _objectSpread(_objectSpread({}, extraConfig), {}, {
155
166
  requiredMark: requiredMark
156
167
  }), form, parentName),
@@ -79,7 +79,7 @@ var Section = function Section(_ref) {
79
79
  className: 'igloo-section-content'
80
80
  }, contentProps), {}, {
81
81
  children: _jsx(_Row, {
82
- gutter: [32, 24],
82
+ gutter: [32, preview ? 16 : 24],
83
83
  children: elements.map(function (child, index) {
84
84
  return _jsx(Element, {
85
85
  parentName: namePath,
@@ -0,0 +1,13 @@
1
+ import { FC } from 'react';
2
+ import { FormItemProps } from 'antd/es/form';
3
+ import { FormItemConfig, FormItemName } from '../../types';
4
+ import './style/index.less';
5
+ export interface AddableSectionProps extends FormItemConfig {
6
+ parentName?: FormItemName;
7
+ formItemProps?: FormItemProps;
8
+ preview?: boolean;
9
+ disabledFromParent?: boolean;
10
+ setShowStepButton?: (showButton: boolean) => void;
11
+ }
12
+ declare const AddableSection: FC<AddableSectionProps>;
13
+ export default AddableSection;
@@ -0,0 +1,263 @@
1
+ import "antd/es/row/style";
2
+ import _Row from "antd/es/row";
3
+ import "antd/es/col/style";
4
+ import _Col from "antd/es/col";
5
+
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7
+
8
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
+
10
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+
12
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
13
+
14
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
+
16
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
+
18
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
+
20
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
21
+
22
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
23
+
24
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+
26
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
27
+
28
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
29
+
30
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
31
+
32
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
33
+
34
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
35
+ import { useReducer, useContext, useEffect, cloneElement, isValidElement } from 'react';
36
+ import FormContext from '../context';
37
+ import { calcNamePath, calcFormItemProps } from '../../utils/form-utils';
38
+ import Typography from '../../typography';
39
+ import Button from '../../button';
40
+ import { LocaleContext } from '../../locale';
41
+ import './style/index.less';
42
+
43
+ var AddableSection = function AddableSection(props) {
44
+ var _props$elements = props.elements,
45
+ elements = _props$elements === void 0 ? [] : _props$elements,
46
+ name = props.name,
47
+ label = props.label,
48
+ _props$labelProps = props.labelProps,
49
+ labelProps = _props$labelProps === void 0 ? {} : _props$labelProps,
50
+ _props$contentProps = props.contentProps,
51
+ contentProps = _props$contentProps === void 0 ? {} : _props$contentProps,
52
+ _props$max = props.max,
53
+ max = _props$max === void 0 ? Number.MAX_SAFE_INTEGER : _props$max,
54
+ parentName = props.parentName,
55
+ preview = props.preview,
56
+ disabledFromParent = props.disabledFromParent,
57
+ setShowStepButton = props.setShowStepButton,
58
+ children = props.children;
59
+
60
+ var _useReducer = useReducer(function (r) {
61
+ return r + 1;
62
+ }, 0),
63
+ _useReducer2 = _slicedToArray(_useReducer, 2),
64
+ _ = _useReducer2[0],
65
+ dispatch = _useReducer2[1];
66
+
67
+ var _useContext = useContext(LocaleContext),
68
+ formatMessage = _useContext.formatMessage;
69
+
70
+ var _useContext2 = useContext(FormContext),
71
+ form = _useContext2.form,
72
+ requiredMark = _useContext2.requiredMark,
73
+ registerDependencies = _useContext2.registerDependencies;
74
+
75
+ var namePath = calcNamePath(parentName, name);
76
+
77
+ var _useReducer3 = useReducer(function (state, action) {
78
+ if (action.type === 'add') {
79
+ return [].concat(_toConsumableArray(state), [action.key]);
80
+ }
81
+
82
+ var found = false;
83
+ return state.filter(function (key, index) {
84
+ if (key === action.key) {
85
+ found = true;
86
+ return false;
87
+ }
88
+
89
+ if (found) {
90
+ form === null || form === void 0 ? void 0 : form.setFields([{
91
+ name: calcNamePath(namePath, index - 1),
92
+ value: form.getFieldValue(calcNamePath(namePath, index))
93
+ }]);
94
+ }
95
+
96
+ return true;
97
+ });
98
+ }, [Date.now()]),
99
+ _useReducer4 = _slicedToArray(_useReducer3, 2),
100
+ groupKeys = _useReducer4[0],
101
+ dispath = _useReducer4[1];
102
+
103
+ useEffect(function () {
104
+ var dependencies = props.dependencies,
105
+ asserts = props.asserts,
106
+ copyValue = props.copyValue,
107
+ selectValue = props.selectValue,
108
+ shouldRender = props.shouldRender,
109
+ subscribedFields = props.subscribedFields,
110
+ disabled = props.disabled;
111
+ var dependentField = dependencies || [];
112
+
113
+ if (Array.isArray(subscribedFields)) {
114
+ dependentField.push.apply(dependentField, _toConsumableArray(subscribedFields));
115
+ }
116
+
117
+ if (asserts && asserts.length) {
118
+ asserts.forEach(function (_ref) {
119
+ var field = _ref.field;
120
+ return dependentField.push(field);
121
+ });
122
+ }
123
+
124
+ if (copyValue) {
125
+ dependentField.push(copyValue.assert.field);
126
+ }
127
+
128
+ if (selectValue && selectValue.length) {
129
+ selectValue.forEach(function (_ref2) {
130
+ var assert = _ref2.assert;
131
+ return dependentField.push(assert.field);
132
+ });
133
+ }
134
+
135
+ if (shouldRender && !Array.isArray(subscribedFields)) {
136
+ dependentField.push('SUBSCRIBE_ALL');
137
+ }
138
+
139
+ if (Array.isArray(disabled)) {
140
+ disabled.forEach(function (_ref3) {
141
+ var field = _ref3.field;
142
+ return dependentField.push(field);
143
+ });
144
+ } else if (_typeof(disabled) === 'object') {
145
+ dependentField.push(disabled.field);
146
+ }
147
+
148
+ registerDependencies(dependentField, dispatch);
149
+ }, []);
150
+
151
+ var _calcFormItemProps = calcFormItemProps(props, {
152
+ requiredMark: requiredMark
153
+ }, form, parentName),
154
+ formItemProps = _calcFormItemProps.formItemProps,
155
+ elementProps = _calcFormItemProps.elementProps,
156
+ display = _calcFormItemProps.display;
157
+
158
+ if (formItemProps.copiedValue.copied) {
159
+ var currentValue = form === null || form === void 0 ? void 0 : form.getFieldValue(namePath);
160
+
161
+ var value = _objectSpread(_objectSpread({}, currentValue), formItemProps.copiedValue.value);
162
+
163
+ form === null || form === void 0 ? void 0 : form.setFields([{
164
+ name: namePath,
165
+ value: value,
166
+ errors: []
167
+ }]);
168
+ }
169
+
170
+ var transformChildren = function transformChildren(parentName) {
171
+ if (Array.isArray(children)) {
172
+ return children.map(function (c, index) {
173
+ var _c$type;
174
+
175
+ if (['Igloo_Free_Form_Item', 'Igloo_Free_Form_Section'].includes(c === null || c === void 0 ? void 0 : (_c$type = c.type) === null || _c$type === void 0 ? void 0 : _c$type.displayName)) {
176
+ return /*#__PURE__*/cloneElement(c, _objectSpread(_objectSpread({}, c.props), {}, {
177
+ parentName: parentName,
178
+ key: c.props.key || index,
179
+ setShowStepButton: setShowStepButton,
180
+ preview: preview,
181
+ disabledFromParent: elementProps.disabled || disabledFromParent
182
+ }));
183
+ }
184
+
185
+ return c;
186
+ });
187
+ }
188
+
189
+ return /*#__PURE__*/isValidElement(children) ? /*#__PURE__*/cloneElement(children, _objectSpread(_objectSpread({}, children.props), {}, {
190
+ parentName: parentName,
191
+ setShowStepButton: setShowStepButton,
192
+ preview: preview,
193
+ disabledFromParent: elementProps.disabled
194
+ })) : children;
195
+ };
196
+
197
+ if (!display) {
198
+ return null;
199
+ }
200
+
201
+ var groups = groupKeys.map(function (key, index) {
202
+ var parentName = calcNamePath(namePath, index);
203
+ return _jsxs(_Col, {
204
+ span: 24,
205
+ className: 'igloo-addable-section',
206
+ children: [label && _jsxs(_Row, {
207
+ justify: "space-between",
208
+ className: 'igloo-addable-section-label',
209
+ children: [_jsxs(Typography, _objectSpread(_objectSpread({}, labelProps), {}, {
210
+ level: "h4",
211
+ wrapElement: "div",
212
+ children: [label, " ", index + 1]
213
+ }), void 0), groupKeys.length > 1 && !preview && _jsx(Button, {
214
+ type: "link",
215
+ className: "igloo-addable-section-label-remove",
216
+ onClick: function onClick() {
217
+ return dispath({
218
+ type: 'remove',
219
+ key: key
220
+ });
221
+ },
222
+ children: formatMessage({
223
+ id: 'Remove'
224
+ })
225
+ }, void 0)]
226
+ }, void 0), _jsx("div", _objectSpread(_objectSpread({
227
+ className: 'igloo-addable-section-content'
228
+ }, contentProps), {}, {
229
+ children: _jsx(_Row, {
230
+ gutter: [32, preview ? 16 : 24],
231
+ children: transformChildren(parentName)
232
+ }, void 0)
233
+ }), void 0)]
234
+ }, key);
235
+ });
236
+ return _jsxs("div", {
237
+ className: "igloo-addable-section-container",
238
+ style: {
239
+ width: '100%'
240
+ },
241
+ children: [groups, groupKeys.length < max && !preview && _jsx(_Col, {
242
+ span: 24,
243
+ style: {
244
+ marginTop: 16
245
+ },
246
+ children: _jsxs(Button, {
247
+ onClick: function onClick() {
248
+ return dispath({
249
+ type: 'add',
250
+ key: Date.now()
251
+ });
252
+ },
253
+ className: "igloo-addable-section-button",
254
+ children: [formatMessage({
255
+ id: 'Add'
256
+ }), " ", label]
257
+ }, void 0)
258
+ }, void 0)]
259
+ }, void 0);
260
+ };
261
+
262
+ export default AddableSection;
263
+ AddableSection.displayName = 'Igloo_Free_Form_AddableSection';
@@ -0,0 +1 @@
1
+ import './index.less';
@@ -0,0 +1 @@
1
+ import './index.less';
@@ -0,0 +1,22 @@
1
+ .igloo-addable-section-container {
2
+ .igloo-addable-section {
3
+ .igloo-addable-section-label {
4
+ .igloo-addable-section-label-remove {
5
+ height: auto;
6
+ border: none;
7
+ }
8
+ }
9
+
10
+ .igloo-addable-section-content {
11
+ margin-top: 16px;
12
+ }
13
+
14
+ & + .igloo-addable-section {
15
+ margin-top: 24px;
16
+ }
17
+ }
18
+
19
+ .igloo-addable-section-button {
20
+ min-width: 221px;
21
+ }
22
+ }
@@ -182,7 +182,7 @@ var Section = function Section(props) {
182
182
  className: 'igloo-freeform-section-content'
183
183
  }, contentProps), {}, {
184
184
  children: _jsx(_Row, {
185
- gutter: [32, 24],
185
+ gutter: [32, preview ? 16 : 24],
186
186
  children: transformChildren()
187
187
  }, void 0)
188
188
  }), void 0)]
package/es/index.d.ts CHANGED
@@ -42,3 +42,4 @@ export { default as FormPage } from './free-form/page';
42
42
  export { default as FormSteps } from './free-form/steps';
43
43
  export { default as FormStep } from './free-form/step';
44
44
  export { default as FormSection } from './free-form/section';
45
+ export { default as FormAddableSection } from './free-form/addable-section';
package/es/index.js CHANGED
@@ -41,4 +41,5 @@ export { default as FormPages } from './free-form/pages';
41
41
  export { default as FormPage } from './free-form/page';
42
42
  export { default as FormSteps } from './free-form/steps';
43
43
  export { default as FormStep } from './free-form/step';
44
- export { default as FormSection } from './free-form/section';
44
+ export { default as FormSection } from './free-form/section';
45
+ export { default as FormAddableSection } from './free-form/addable-section';