@maif/react-forms 1.0.25 → 1.0.26

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/lib/form.js CHANGED
@@ -171,16 +171,16 @@ var defaultVal = function defaultVal(t, array, defaultValue) {
171
171
 
172
172
  var getDefaultValues = function getDefaultValues(flow, schema) {
173
173
  return flow.reduce(function (acc, key) {
174
+ if (_typeof(key) === 'object') {
175
+ return _objectSpread(_objectSpread({}, acc), getDefaultValues(key.flow, schema));
176
+ }
177
+
174
178
  var entry = schema[key];
175
179
 
176
180
  if (!entry) {
177
181
  return acc;
178
182
  }
179
183
 
180
- if (_typeof(key) === 'object') {
181
- return _objectSpread(_objectSpread({}, acc), getDefaultValues(key.flow, schema));
182
- }
183
-
184
184
  return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, defaultVal(entry.type, entry.array || entry.isMulti, entry.defaultValue)));
185
185
  }, {});
186
186
  };
@@ -347,6 +347,18 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
347
347
  }
348
348
  };
349
349
  });
350
+
351
+ var functionalProperty = function functionalProperty(entry, prop) {
352
+ if (typeof prop === 'function') {
353
+ return prop({
354
+ rawValues: getValues(),
355
+ value: getValues(entry)
356
+ });
357
+ } else {
358
+ return prop;
359
+ }
360
+ };
361
+
350
362
  return /*#__PURE__*/_react["default"].createElement(_reactHookForm.FormProvider, methods, /*#__PURE__*/_react["default"].createElement("form", {
351
363
  className: className || "".concat(classes.pr_15, " ").concat(classes.full_width),
352
364
  onSubmit: _handleSubmit(function (data) {
@@ -391,7 +403,7 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
391
403
  key: "".concat(entry, "-").concat(idx),
392
404
  entry: entry,
393
405
  error: error,
394
- label: (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry,
406
+ label: functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry),
395
407
  help: step === null || step === void 0 ? void 0 : step.help,
396
408
  render: inputWrapper
397
409
  }, /*#__PURE__*/_react["default"].createElement(Step, {
@@ -408,7 +420,8 @@ var Form = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, ref) {
408
420
  setValue: setValue,
409
421
  watch: watch,
410
422
  inputWrapper: inputWrapper,
411
- httpClient: maybeCustomHttpClient
423
+ httpClient: maybeCustomHttpClient,
424
+ functionalProperty: functionalProperty
412
425
  }));
413
426
  }), /*#__PURE__*/_react["default"].createElement(Footer, {
414
427
  render: footer,
@@ -473,7 +486,8 @@ var Step = function Step(_ref4) {
473
486
  inputWrapper = _ref4.inputWrapper,
474
487
  httpClient = _ref4.httpClient,
475
488
  defaultValue = _ref4.defaultValue,
476
- index = _ref4.index;
489
+ index = _ref4.index,
490
+ functionalProperty = _ref4.functionalProperty;
477
491
  var classes = (0, _styleContext.useCustomStyle)();
478
492
 
479
493
  if (entry && _typeof(entry) === 'object') {
@@ -519,7 +533,7 @@ var Step = function Step(_ref4) {
519
533
  key: "collapse-".concat(en, "-").concat(entryIdx),
520
534
  entry: en,
521
535
  error: err,
522
- label: (stp === null || stp === void 0 ? void 0 : stp.label) === null ? null : (stp === null || stp === void 0 ? void 0 : stp.label) || en,
536
+ label: functionalProperty(en, (stp === null || stp === void 0 ? void 0 : stp.label) === null ? null : (stp === null || stp === void 0 ? void 0 : stp.label) || en),
523
537
  help: stp === null || stp === void 0 ? void 0 : stp.help,
524
538
  render: inputWrapper
525
539
  }, /*#__PURE__*/_react["default"].createElement(Step, {
@@ -536,22 +550,12 @@ var Step = function Step(_ref4) {
536
550
  watch: watch,
537
551
  inputWrapper: inputWrapper,
538
552
  httpClient: httpClient,
539
- defaultValue: stp === null || stp === void 0 ? void 0 : stp.defaultValue
553
+ defaultValue: stp === null || stp === void 0 ? void 0 : stp.defaultValue,
554
+ functionalProperty: functionalProperty
540
555
  }));
541
556
  }));
542
557
  }
543
558
 
544
- var disabled = function disabled() {
545
- if (typeof step.disabled === 'function') {
546
- return step.disabled({
547
- rawValues: getValues(),
548
- value: getValues(entry)
549
- });
550
- } else {
551
- return step.disabled;
552
- }
553
- };
554
-
555
559
  if (step.array) {
556
560
  return /*#__PURE__*/_react["default"].createElement(ArrayStep, {
557
561
  entry: entry,
@@ -564,7 +568,7 @@ var Step = function Step(_ref4) {
564
568
  values: getValues(entry),
565
569
  defaultValue: step.defaultValue || defaultVal(step.type),
566
570
  getValues: getValues,
567
- disabled: disabled(),
571
+ disabled: functionalProperty(entry, step.disabled),
568
572
  component: function component(props, idx) {
569
573
  var _error$idx;
570
574
 
@@ -586,7 +590,8 @@ var Step = function Step(_ref4) {
586
590
  httpClient: httpClient,
587
591
  defaultValue: props.defaultValue,
588
592
  value: props.value,
589
- index: idx
593
+ index: idx,
594
+ functionalProperty: functionalProperty
590
595
  });
591
596
  }
592
597
  });
@@ -628,7 +633,7 @@ var Step = function Step(_ref4) {
628
633
  type: "text",
629
634
  id: entry,
630
635
  className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
631
- readOnly: disabled() ? 'readOnly' : null
636
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null
632
637
  }, step.props, {
633
638
  defaultValue: defaultValue,
634
639
  placeholder: step.placeholder
@@ -651,7 +656,7 @@ var Step = function Step(_ref4) {
651
656
  error: error
652
657
  }, /*#__PURE__*/_react["default"].createElement(_index.CodeInput, _extends({
653
658
  className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
654
- readOnly: disabled() ? true : false,
659
+ readOnly: functionalProperty(entry, step.disabled) ? true : false,
655
660
  onChange: function onChange(e) {
656
661
  field.onChange(e);
657
662
  (0, _Option.option)(step.onChange).map(function (onChange) {
@@ -685,7 +690,7 @@ var Step = function Step(_ref4) {
685
690
  error: error
686
691
  }, /*#__PURE__*/_react["default"].createElement(_index.MarkdownInput, _extends({}, step.props, {
687
692
  className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
688
- readOnly: disabled() ? 'readOnly' : null,
693
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
689
694
  onChange: function onChange(e) {
690
695
  field.onChange(e);
691
696
  (0, _Option.option)(step.onChange).map(function (onChange) {
@@ -720,7 +725,7 @@ var Step = function Step(_ref4) {
720
725
  error: error
721
726
  }, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, step, {
722
727
  className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
723
- disabled: disabled(),
728
+ disabled: functionalProperty(entry, step.disabled),
724
729
  value: field.value,
725
730
  possibleValues: step.options,
726
731
  defaultValue: defaultValue,
@@ -759,7 +764,7 @@ var Step = function Step(_ref4) {
759
764
  type: step.format || 'text',
760
765
  id: entry,
761
766
  className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
762
- readOnly: disabled() ? 'readOnly' : null,
767
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
763
768
  defaultValue: defaultValue,
764
769
  placeholder: step.placeholder
765
770
  }, inputProps)));
@@ -785,7 +790,7 @@ var Step = function Step(_ref4) {
785
790
  error: error
786
791
  }, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, step, {
787
792
  className: (0, _classnames["default"])(classes.content, _defineProperty({}, classes.input__invalid, error)),
788
- readOnly: disabled() ? 'readOnly' : null,
793
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
789
794
  onChange: function onChange(e) {
790
795
  field.onChange(e);
791
796
  (0, _Option.option)(step.onChange).map(function (onChange) {
@@ -822,7 +827,7 @@ var Step = function Step(_ref4) {
822
827
  type: step.format || 'number',
823
828
  id: entry,
824
829
  className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
825
- readOnly: disabled() ? 'readOnly' : null,
830
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
826
831
  name: entry,
827
832
  placeholder: step.placeholder,
828
833
  defaultValue: defaultValue
@@ -846,7 +851,7 @@ var Step = function Step(_ref4) {
846
851
  error: error
847
852
  }, /*#__PURE__*/_react["default"].createElement(_index.BooleanInput, _extends({}, step.props, {
848
853
  className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
849
- readOnly: disabled() ? 'readOnly' : null,
854
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
850
855
  onChange: function onChange(e) {
851
856
  field.onChange(e);
852
857
  (0, _Option.option)(step.onChange).map(function (onChange) {
@@ -883,7 +888,7 @@ var Step = function Step(_ref4) {
883
888
  error: error
884
889
  }, /*#__PURE__*/_react["default"].createElement(_index.SelectInput, _extends({}, step.props, step, {
885
890
  className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
886
- readOnly: disabled() ? 'readOnly' : null,
891
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
887
892
  onChange: function onChange(e) {
888
893
  field.onChange(e);
889
894
  (0, _Option.option)(step.onChange).map(function (onChange) {
@@ -930,7 +935,8 @@ var Step = function Step(_ref4) {
930
935
  maybeCustomHttpClient: httpClient,
931
936
  value: getValues(entry) || defaultValue,
932
937
  error: error,
933
- index: index
938
+ index: index,
939
+ functionalProperty: functionalProperty
934
940
  }));
935
941
 
936
942
  default:
@@ -951,7 +957,7 @@ var Step = function Step(_ref4) {
951
957
  error: error
952
958
  }, /*#__PURE__*/_react["default"].createElement(_index.ObjectInput, _extends({}, step.props, step, {
953
959
  className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
954
- readOnly: disabled() ? 'readOnly' : null,
960
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
955
961
  onChange: function onChange(e) {
956
962
  field.onChange(e);
957
963
  (0, _Option.option)(step.onChange).map(function (onChange) {
@@ -988,7 +994,7 @@ var Step = function Step(_ref4) {
988
994
  }, /*#__PURE__*/_react["default"].createElement(_reactRainbowComponents.DatePicker, _extends({}, step.props, {
989
995
  id: "datePicker-1",
990
996
  className: (0, _classnames["default"])(_defineProperty({}, classes.input__invalid, error)),
991
- readOnly: disabled() ? 'readOnly' : null,
997
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
992
998
  value: field.value,
993
999
  onChange: function onChange(e) {
994
1000
  field.onChange(e);
@@ -1050,7 +1056,7 @@ var Step = function Step(_ref4) {
1050
1056
  }), /*#__PURE__*/_react["default"].createElement("button", {
1051
1057
  type: "button",
1052
1058
  className: "".concat(classes.btn, " ").concat(classes.flex, " ").concat(classes.ai_center),
1053
- disabled: uploading || disabled(),
1059
+ disabled: uploading || functionalProperty(entry, step.disabled),
1054
1060
  onClick: trigger
1055
1061
  }, uploading && /*#__PURE__*/_react["default"].createElement(_reactFeather.Loader, null), !uploading && /*#__PURE__*/_react["default"].createElement(_reactFeather.Upload, null), /*#__PURE__*/_react["default"].createElement("span", {
1056
1062
  className: "".concat(classes.ml_5)
@@ -1102,7 +1108,7 @@ var Step = function Step(_ref4) {
1102
1108
  type: "file",
1103
1109
  id: entry,
1104
1110
  className: (0, _classnames["default"])(classes.input, _defineProperty({}, classes.input__invalid, error)),
1105
- readOnly: disabled() ? 'readOnly' : null,
1111
+ readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
1106
1112
  name: entry,
1107
1113
  placeholder: step.placeholder
1108
1114
  }, inputProps)));
@@ -1190,7 +1196,8 @@ var NestedForm = function NestedForm(_ref16) {
1190
1196
  index = _ref16.index,
1191
1197
  error = _ref16.error,
1192
1198
  value = _ref16.value,
1193
- step = _ref16.step;
1199
+ step = _ref16.step,
1200
+ functionalProperty = _ref16.functionalProperty;
1194
1201
 
1195
1202
  var _useFormContext = (0, _reactHookForm.useFormContext)(),
1196
1203
  register = _useFormContext.register,
@@ -1266,7 +1273,7 @@ var NestedForm = function NestedForm(_ref16) {
1266
1273
  }, []);
1267
1274
  var bordered = computedSandF.filter(function (x) {
1268
1275
  return x.visibleStep;
1269
- }).length > 1 && step.label === null;
1276
+ }).length > 1 && step.label !== null;
1270
1277
  return /*#__PURE__*/_react["default"].createElement("div", {
1271
1278
  className: (0, _classnames["default"])(_defineProperty({}, classes.nestedform__border, bordered))
1272
1279
  }, !!step.collapsable && schemaAndFlow.flow.length > 1 && collapsed && /*#__PURE__*/_react["default"].createElement(_reactFeather.ArrowDown, {
@@ -1313,7 +1320,7 @@ var NestedForm = function NestedForm(_ref16) {
1313
1320
  className: (0, _classnames["default"])(_defineProperty({}, classes.display__none, isCollapsed || !visibleStep)),
1314
1321
  entry: "".concat(parent, ".").concat(entry),
1315
1322
  error: realError,
1316
- label: (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry,
1323
+ label: functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry),
1317
1324
  help: step.help,
1318
1325
  render: inputWrapper
1319
1326
  }, /*#__PURE__*/_react["default"].createElement(Step, {
@@ -1331,7 +1338,8 @@ var NestedForm = function NestedForm(_ref16) {
1331
1338
  watch: watch,
1332
1339
  inputWrapper: inputWrapper,
1333
1340
  httpClient: maybeCustomHttpClient,
1334
- defaultValue: value && value[entry]
1341
+ defaultValue: value && value[entry],
1342
+ functionalProperty: functionalProperty
1335
1343
  }));
1336
1344
  }));
1337
1345
  };
package/lib/style.d.ts CHANGED
@@ -12,22 +12,23 @@ export namespace style {
12
12
  opacity: number;
13
13
  };
14
14
  };
15
- namespace btn {
16
- const borderRadius: number;
17
- const padding: number;
18
- const fontSize: string;
19
- const cursor: string;
20
- const borderWidth: string;
21
- const backgroundColor: string;
22
- }
15
+ const btn: {
16
+ borderRadius: number;
17
+ padding: number;
18
+ fontSize: string;
19
+ cursor: string;
20
+ borderWidth: string;
21
+ backgroundColor: string;
22
+ '&:disabled': {
23
+ opacity: number;
24
+ cursor: string;
25
+ };
26
+ };
23
27
  namespace btn_sm {
24
- const fontSize_1: string;
25
- export { fontSize_1 as fontSize };
26
- const padding_1: string;
27
- export { padding_1 as padding };
28
- export const lineHeight: string;
29
- const borderRadius_1: string;
30
- export { borderRadius_1 as borderRadius };
28
+ const fontSize: string;
29
+ const padding: string;
30
+ const lineHeight: string;
31
+ const borderRadius: string;
31
32
  }
32
33
  const btn_group: {
33
34
  "& > button:not(:last-child)": {
@@ -127,8 +128,8 @@ export namespace style {
127
128
  const marginBottom: number;
128
129
  }
129
130
  namespace p_15 {
130
- const padding_2: number;
131
- export { padding_2 as padding };
131
+ const padding_1: number;
132
+ export { padding_1 as padding };
132
133
  }
133
134
  namespace pr_15 {
134
135
  const paddingRight: number;
@@ -160,16 +161,15 @@ export namespace style {
160
161
  const alignItems: string;
161
162
  }
162
163
  namespace cursor_pointer {
163
- const cursor_1: string;
164
- export { cursor_1 as cursor };
164
+ const cursor: string;
165
165
  }
166
166
  namespace collapse {
167
167
  const display_2: string;
168
168
  export { display_2 as display };
169
169
  const justifyContent_2: string;
170
170
  export { justifyContent_2 as justifyContent };
171
- const cursor_2: string;
172
- export { cursor_2 as cursor };
171
+ const cursor_1: string;
172
+ export { cursor_1 as cursor };
173
173
  }
174
174
  namespace collapse_label {
175
175
  export const fontWeight: string;
@@ -202,8 +202,8 @@ export namespace style {
202
202
  export { width_1 as width };
203
203
  const marginTop_4: string;
204
204
  export { marginTop_4 as marginTop };
205
- const fontSize_2: string;
206
- export { fontSize_2 as fontSize };
205
+ const fontSize_1: string;
206
+ export { fontSize_1 as fontSize };
207
207
  const color_4: string;
208
208
  export { color_4 as color };
209
209
  }
package/lib/style.js CHANGED
@@ -46,7 +46,11 @@ var style = (_style = {
46
46
  fontSize: "1rem",
47
47
  cursor: "pointer",
48
48
  borderWidth: '1px',
49
- backgroundColor: '#fff'
49
+ backgroundColor: '#fff',
50
+ '&:disabled': {
51
+ opacity: .6,
52
+ cursor: 'not-allowed'
53
+ }
50
54
  },
51
55
  btn_sm: {
52
56
  fontSize: "0.875rem",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maif/react-forms",
3
3
  "description": "Build react safe forms as fast as possible",
4
- "version": "1.0.25",
4
+ "version": "1.0.26",
5
5
  "main": "lib/index.js",
6
6
  "author": "MAIF team",
7
7
  "keywords": [