@insticc/genericform 2.0.1 → 2.0.3
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/build/Demo.js +95 -83
- package/build/Demo2.js +230 -192
- package/build/FormFields/CustomAccordion.js +44 -35
- package/build/FormFields/CustomCheckbox.js +15 -13
- package/build/FormFields/CustomCheckboxGroup.js +63 -22
- package/build/FormFields/CustomComponent.js +9 -7
- package/build/FormFields/CustomDatePicker.js +32 -26
- package/build/FormFields/CustomDropdown.js +25 -21
- package/build/FormFields/CustomInput.js +17 -15
- package/build/FormFields/CustomJson.js +43 -39
- package/build/FormFields/CustomLabel.js +7 -6
- package/build/FormFields/CustomMultiDropdown.js +21 -20
- package/build/FormFields/CustomNumberInput.js +20 -18
- package/build/FormFields/CustomRadioGroup.js +29 -25
- package/build/FormFields/CustomSearch.js +19 -18
- package/build/FormFields/CustomSeparator.js +3 -3
- package/build/FormFields/CustomTextArea.js +19 -17
- package/build/FormFields/CustomToggle.js +17 -14
- package/build/FormFields/defaults.js +21 -15
- package/build/index.css +3 -8
- package/build/index.js +148 -133
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -34,11 +34,12 @@ var _CustomSearch = _interopRequireDefault(require("./FormFields/CustomSearch"))
|
|
|
34
34
|
var _CustomSeparator = _interopRequireDefault(require("./FormFields/CustomSeparator"));
|
|
35
35
|
var _CustomTextArea = _interopRequireDefault(require("./FormFields/CustomTextArea"));
|
|
36
36
|
var _CustomToggle = _interopRequireDefault(require("./FormFields/CustomToggle"));
|
|
37
|
+
var _semanticUiReact = require("semantic-ui-react");
|
|
37
38
|
var _Demo = _interopRequireDefault(require("./Demo"));
|
|
38
39
|
var _Demo2 = _interopRequireDefault(require("./Demo2"));
|
|
39
40
|
require("./index.css");
|
|
41
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
40
42
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
41
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
42
43
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
43
44
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
44
45
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
@@ -103,15 +104,17 @@ var groupByInline = function groupByInline(fields) {
|
|
|
103
104
|
|
|
104
105
|
// #region GenericForm Props
|
|
105
106
|
var GenericForm = function GenericForm(_ref) {
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
_ref$fields = _ref.fields,
|
|
107
|
+
var _submitButton$icon, _cancelButton$icon;
|
|
108
|
+
var _ref$fields = _ref.fields,
|
|
109
109
|
fields = _ref$fields === void 0 ? [] : _ref$fields,
|
|
110
110
|
title = _ref.title,
|
|
111
111
|
titleIcon = _ref.titleIcon,
|
|
112
|
+
titleStyle = _ref.titleStyle,
|
|
112
113
|
_ref$containerStyle = _ref.containerStyle,
|
|
113
114
|
containerStyle = _ref$containerStyle === void 0 ? {} : _ref$containerStyle,
|
|
114
115
|
formStyle = _ref.formStyle,
|
|
116
|
+
actionsDivStyle = _ref.actionsDivStyle,
|
|
117
|
+
actionsStyle = _ref.actionsStyle,
|
|
115
118
|
_ref$splitForm = _ref.splitForm,
|
|
116
119
|
splitForm = _ref$splitForm === void 0 ? false : _ref$splitForm,
|
|
117
120
|
splitField = _ref.splitField,
|
|
@@ -128,9 +131,13 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
128
131
|
_ref$showCancel = _ref.showCancel,
|
|
129
132
|
showCancel = _ref$showCancel === void 0 ? true : _ref$showCancel,
|
|
130
133
|
_ref$submitText = _ref.submitText,
|
|
131
|
-
submitText = _ref$submitText === void 0 ? '
|
|
134
|
+
submitText = _ref$submitText === void 0 ? 'Submit' : _ref$submitText,
|
|
132
135
|
_ref$cancelText = _ref.cancelText,
|
|
133
136
|
cancelText = _ref$cancelText === void 0 ? 'Cancel' : _ref$cancelText,
|
|
137
|
+
_ref$submitButton = _ref.submitButton,
|
|
138
|
+
submitButton = _ref$submitButton === void 0 ? {} : _ref$submitButton,
|
|
139
|
+
_ref$cancelButton = _ref.cancelButton,
|
|
140
|
+
cancelButton = _ref$cancelButton === void 0 ? {} : _ref$cancelButton,
|
|
134
141
|
_ref$validateOnChange = _ref.validateOnChange,
|
|
135
142
|
validateOnChange = _ref$validateOnChange === void 0 ? true : _ref$validateOnChange,
|
|
136
143
|
_ref$validateOnSubmit = _ref.validateOnSubmit,
|
|
@@ -231,7 +238,7 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
231
238
|
|
|
232
239
|
// #region Validation
|
|
233
240
|
var validateField = (0, _react.useCallback)(function (field, value, currentFormData) {
|
|
234
|
-
if (['hr', 'label', '
|
|
241
|
+
if (['hr', 'label', 'accordion'].includes(field.type)) return null;
|
|
235
242
|
var errs = [];
|
|
236
243
|
if (field.required) {
|
|
237
244
|
var empty = value === undefined || value === null || value === '' || Array.isArray(value) && value.length === 0;
|
|
@@ -466,76 +473,63 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
466
473
|
switch (field.type) {
|
|
467
474
|
// Abstract
|
|
468
475
|
case 'hr':
|
|
469
|
-
return /*#__PURE__*/
|
|
470
|
-
key: field.name || "sep-".concat(Math.random()),
|
|
476
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomSeparator["default"], {
|
|
471
477
|
mainDivStyle: field.style
|
|
472
|
-
});
|
|
478
|
+
}, field.name || "sep-".concat(Math.random()));
|
|
473
479
|
case 'label':
|
|
474
|
-
return /*#__PURE__*/
|
|
475
|
-
key: field.name
|
|
476
|
-
}, cp, {
|
|
480
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomLabel["default"], _objectSpread(_objectSpread({}, cp), {}, {
|
|
477
481
|
mainDivStyle: field.style,
|
|
478
482
|
labelStyle: field.labelStyle
|
|
479
|
-
}));
|
|
483
|
+
}), field.name);
|
|
480
484
|
|
|
481
485
|
// Simple
|
|
482
486
|
case 'string':
|
|
483
487
|
case 'text':
|
|
484
488
|
case 'email':
|
|
485
489
|
case 'password':
|
|
486
|
-
return /*#__PURE__*/
|
|
487
|
-
key: field.name
|
|
488
|
-
}, cp, sp, fp, {
|
|
490
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomInput["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
489
491
|
value: value,
|
|
490
492
|
type: field.type === 'email' ? 'email' : field.type === 'password' ? 'password' : 'text',
|
|
491
493
|
placeholder: field.placeholder,
|
|
492
494
|
onChange: fieldHandler(field),
|
|
493
495
|
inputStyle: field.inputStyle,
|
|
494
496
|
className: field.className
|
|
495
|
-
}));
|
|
497
|
+
}), field.name);
|
|
496
498
|
case 'int':
|
|
497
499
|
case 'number':
|
|
498
|
-
return /*#__PURE__*/
|
|
499
|
-
key: field.name
|
|
500
|
-
}, cp, sp, fp, {
|
|
500
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomNumberInput["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
501
501
|
value: value,
|
|
502
502
|
placeholder: field.placeholder,
|
|
503
503
|
min: field.min,
|
|
504
504
|
max: field.max,
|
|
505
505
|
step: field.step,
|
|
506
506
|
onChange: fieldHandler(field)
|
|
507
|
-
}));
|
|
507
|
+
}), field.name);
|
|
508
508
|
case 'textArea':
|
|
509
|
-
return /*#__PURE__*/
|
|
510
|
-
key: field.name
|
|
511
|
-
}, cp, sp, fp, {
|
|
509
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomTextArea["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
512
510
|
value: value,
|
|
513
511
|
placeholder: field.placeholder,
|
|
514
512
|
rows: field.rows,
|
|
515
513
|
height: field.height,
|
|
516
514
|
onChange: fieldHandler(field)
|
|
517
|
-
}));
|
|
515
|
+
}), field.name);
|
|
518
516
|
|
|
519
517
|
// Date
|
|
520
518
|
case 'date':
|
|
521
519
|
case 'datetime':
|
|
522
520
|
case 'time':
|
|
523
521
|
case 'year':
|
|
524
|
-
return /*#__PURE__*/
|
|
525
|
-
key: field.name
|
|
526
|
-
}, cp, sp, fp, {
|
|
522
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomDatePicker["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
527
523
|
value: value,
|
|
528
524
|
placeholder: field.placeholder,
|
|
529
525
|
onChange: dateFieldHandler(field),
|
|
530
526
|
dateFormat: field.type === 'time' ? false : field.type === 'year' ? 'YYYY' : 'DD/MM/YYYY',
|
|
531
527
|
timeFormat: field.type === 'datetime' || field.type === 'time' ? 'HH:mm' : false
|
|
532
|
-
}));
|
|
528
|
+
}), field.name);
|
|
533
529
|
|
|
534
530
|
// Option
|
|
535
531
|
case 'select':
|
|
536
|
-
return /*#__PURE__*/
|
|
537
|
-
key: field.name
|
|
538
|
-
}, cp, sp, fp, {
|
|
532
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomDropdown["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
539
533
|
value: value,
|
|
540
534
|
options: field.options,
|
|
541
535
|
placeholder: field.placeholder,
|
|
@@ -548,20 +542,16 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
548
542
|
option: fullOption
|
|
549
543
|
});
|
|
550
544
|
}
|
|
551
|
-
}));
|
|
545
|
+
}), field.name);
|
|
552
546
|
case 'multipleDropdown':
|
|
553
|
-
return /*#__PURE__*/
|
|
554
|
-
key: field.name
|
|
555
|
-
}, cp, sp, fp, {
|
|
547
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomMultiDropdown["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
556
548
|
value: value,
|
|
557
549
|
options: field.options,
|
|
558
550
|
placeholder: field.placeholder,
|
|
559
551
|
onChange: fieldHandler(field)
|
|
560
|
-
}));
|
|
552
|
+
}), field.name);
|
|
561
553
|
case 'search':
|
|
562
|
-
return /*#__PURE__*/
|
|
563
|
-
key: field.name
|
|
564
|
-
}, cp, sp, fp, {
|
|
554
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomSearch["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
565
555
|
value: value,
|
|
566
556
|
options: field.options,
|
|
567
557
|
placeholder: field.placeholder,
|
|
@@ -569,65 +559,53 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
569
559
|
onChange: handleSearchChange,
|
|
570
560
|
handleResultSelect: handleResultSelect,
|
|
571
561
|
resultRenderer: resultRenderer
|
|
572
|
-
}));
|
|
562
|
+
}), field.name);
|
|
573
563
|
case 'accordion':
|
|
574
|
-
return /*#__PURE__*/
|
|
575
|
-
key: field.name,
|
|
564
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomAccordion["default"], {
|
|
576
565
|
name: field.name,
|
|
577
566
|
sections: field.sections,
|
|
578
567
|
defaultOpen: field.defaultOpen,
|
|
579
568
|
activeAllIndex: field.activeAllIndex,
|
|
580
569
|
mainDivStyle: field.style,
|
|
581
570
|
inputStyle: field.inputStyle
|
|
582
|
-
});
|
|
571
|
+
}, field.name);
|
|
583
572
|
case 'toggle':
|
|
584
|
-
return /*#__PURE__*/
|
|
585
|
-
key: field.name
|
|
586
|
-
}, cp, sp, fp, {
|
|
573
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomToggle["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
587
574
|
value: !!value,
|
|
588
575
|
onChange: fieldHandler(field)
|
|
589
|
-
}));
|
|
576
|
+
}), field.name);
|
|
590
577
|
case 'checkbox':
|
|
591
|
-
return /*#__PURE__*/
|
|
592
|
-
key: field.name
|
|
593
|
-
}, cp, sp, fp, {
|
|
578
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomCheckbox["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
594
579
|
checked: !!value,
|
|
595
580
|
onChange: fieldHandler(field),
|
|
596
581
|
onOptionChange: field.onOptionChange
|
|
597
|
-
}));
|
|
582
|
+
}), field.name);
|
|
598
583
|
case 'checkboxGroup':
|
|
599
|
-
return /*#__PURE__*/
|
|
600
|
-
key: field.name
|
|
601
|
-
}, cp, sp, fp, {
|
|
584
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomCheckboxGroup["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
602
585
|
checked: value !== null && value !== void 0 ? value : [],
|
|
603
586
|
options: field.options,
|
|
587
|
+
grouped: field.grouped,
|
|
604
588
|
onChange: fieldHandler(field),
|
|
605
589
|
onOptionChange: field.onOptionChange
|
|
606
|
-
}));
|
|
590
|
+
}), field.name);
|
|
607
591
|
case 'radioGroup':
|
|
608
592
|
case 'radioGroupInline':
|
|
609
|
-
return /*#__PURE__*/
|
|
610
|
-
key: field.name
|
|
611
|
-
}, cp, sp, fp, {
|
|
593
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomRadioGroup["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
612
594
|
value: value,
|
|
613
595
|
options: field.options,
|
|
614
596
|
inline: field.type === 'radioGroupInline',
|
|
615
597
|
onChange: fieldHandler(field),
|
|
616
598
|
onOptionChange: field.onOptionChange,
|
|
617
599
|
formData: internalFormData
|
|
618
|
-
}));
|
|
600
|
+
}), field.name);
|
|
619
601
|
|
|
620
602
|
// Other
|
|
621
603
|
case 'component':
|
|
622
|
-
return /*#__PURE__*/
|
|
623
|
-
key: field.name || "cmp-".concat(Math.random())
|
|
624
|
-
}, cp, sp, {
|
|
604
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomComponent["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
625
605
|
component: field.component
|
|
626
|
-
}));
|
|
606
|
+
}), field.name || "cmp-".concat(Math.random()));
|
|
627
607
|
case 'json':
|
|
628
|
-
return /*#__PURE__*/
|
|
629
|
-
key: field.name
|
|
630
|
-
}, cp, sp, fp, {
|
|
608
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomJson["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
631
609
|
value: value,
|
|
632
610
|
datatype: field.datatype,
|
|
633
611
|
allowModeSwitch: field.allowModeSwitch,
|
|
@@ -645,18 +623,15 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
645
623
|
onValidate: function onValidate(name, raw, isMulti) {
|
|
646
624
|
return validateJsonField(name, raw, isMulti, false, field);
|
|
647
625
|
}
|
|
648
|
-
}));
|
|
626
|
+
}), field.name);
|
|
649
627
|
default:
|
|
650
|
-
return /*#__PURE__*/
|
|
651
|
-
key: field.name
|
|
652
|
-
}, cp, sp, fp, {
|
|
628
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomInput["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
|
|
653
629
|
value: value,
|
|
654
630
|
type: "text",
|
|
655
631
|
placeholder: field.placeholder,
|
|
656
632
|
onChange: fieldHandler(field),
|
|
657
|
-
inputStyle: field.inputStyle,
|
|
658
633
|
className: field.className
|
|
659
|
-
}));
|
|
634
|
+
}), field.name);
|
|
660
635
|
}
|
|
661
636
|
}, [
|
|
662
637
|
// eslint-disable-line react-hooks/exhaustive-deps
|
|
@@ -674,21 +649,23 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
674
649
|
}, [sortedFields]);
|
|
675
650
|
var renderFields = function renderFields(fieldList) {
|
|
676
651
|
return groupByInline(fieldList).map(function (group, idx) {
|
|
677
|
-
return group.type === 'inline' ? /*#__PURE__*/
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
})
|
|
652
|
+
return group.type === 'inline' ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
653
|
+
className: "ufg-field-row",
|
|
654
|
+
children: group.fields.map(function (_ref9) {
|
|
655
|
+
var field = _ref9.field;
|
|
656
|
+
return renderField(field);
|
|
657
|
+
})
|
|
658
|
+
}, idx) : renderField(group.field);
|
|
684
659
|
});
|
|
685
660
|
};
|
|
686
661
|
var renderGroupSection = function renderGroupSection(g, fieldList) {
|
|
687
|
-
return /*#__PURE__*/
|
|
688
|
-
key: g,
|
|
662
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
689
663
|
className: "ufg-form",
|
|
690
|
-
style: formStyle
|
|
691
|
-
|
|
664
|
+
style: formStyle,
|
|
665
|
+
children: [g !== 'ungrouped' && /*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
666
|
+
children: g
|
|
667
|
+
}), renderFields(fieldList)]
|
|
668
|
+
}, g);
|
|
692
669
|
};
|
|
693
670
|
var splitByField = function splitByField(fieldList) {
|
|
694
671
|
var idx = fieldList.findIndex(function (f) {
|
|
@@ -714,24 +691,34 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
714
691
|
if (splitIdx === -1) return groups.map(function (g) {
|
|
715
692
|
return renderGroupSection(g, groupedFields[g]);
|
|
716
693
|
});
|
|
717
|
-
return /*#__PURE__*/
|
|
718
|
-
className: "ufg-form-columns"
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
694
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
695
|
+
className: "ufg-form-columns",
|
|
696
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
697
|
+
children: groups.slice(0, splitIdx + 1).map(function (g) {
|
|
698
|
+
return renderGroupSection(g, groupedFields[g]);
|
|
699
|
+
})
|
|
700
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
701
|
+
children: groups.slice(splitIdx + 1).map(function (g) {
|
|
702
|
+
return renderGroupSection(g, groupedFields[g]);
|
|
703
|
+
})
|
|
704
|
+
})]
|
|
705
|
+
});
|
|
724
706
|
}
|
|
725
707
|
if (splitForm && splitField) {
|
|
726
|
-
return /*#__PURE__*/
|
|
727
|
-
className: "ufg-form-columns"
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
708
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
709
|
+
className: "ufg-form-columns",
|
|
710
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
711
|
+
children: groups.map(function (g) {
|
|
712
|
+
return renderGroupSection(g, splitByField(groupedFields[g]).left);
|
|
713
|
+
})
|
|
714
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
715
|
+
children: groups.map(function (g) {
|
|
716
|
+
var _splitByField = splitByField(groupedFields[g]),
|
|
717
|
+
right = _splitByField.right;
|
|
718
|
+
return right.length ? renderGroupSection(g, right) : null;
|
|
719
|
+
})
|
|
720
|
+
})]
|
|
721
|
+
});
|
|
735
722
|
}
|
|
736
723
|
return groups.map(function (g) {
|
|
737
724
|
return renderGroupSection(g, groupedFields[g]);
|
|
@@ -741,51 +728,79 @@ var GenericForm = function GenericForm(_ref) {
|
|
|
741
728
|
// #endregion
|
|
742
729
|
// #region Actions bar
|
|
743
730
|
var hasErrors = Object.values(errors).some(Boolean);
|
|
744
|
-
var actionsBar = /*#__PURE__*/
|
|
745
|
-
className: "ufg-actions"
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
731
|
+
var actionsBar = /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
732
|
+
className: "ufg-actions",
|
|
733
|
+
style: actionsDivStyle,
|
|
734
|
+
children: [customActions.map(function (action, idx) {
|
|
735
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
|
|
736
|
+
type: "button",
|
|
737
|
+
className: "ufg-button ".concat(action.className || 'ufg-button-secondary'),
|
|
738
|
+
onClick: action.onClick,
|
|
739
|
+
disabled: !!action.disabled,
|
|
740
|
+
style: _objectSpread(_objectSpread({}, actionsStyle), action.style),
|
|
741
|
+
children: [action.icon, action.label]
|
|
742
|
+
}, idx);
|
|
743
|
+
}), showSubmit && haveSaveButton && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
744
|
+
type: "submit",
|
|
745
|
+
className: "ufg-button ".concat(submitButton.className || 'ufg-button-primary'),
|
|
746
|
+
disabled: isSubmitting || hasErrors,
|
|
747
|
+
style: _objectSpread(_objectSpread({}, actionsStyle), submitButton.style),
|
|
748
|
+
children: isSubmitting ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
749
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_semanticUiReact.Icon, {
|
|
750
|
+
name: "spinner",
|
|
751
|
+
loading: true
|
|
752
|
+
}), " ", submitText]
|
|
753
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
754
|
+
children: [(_submitButton$icon = submitButton.icon) !== null && _submitButton$icon !== void 0 ? _submitButton$icon : '', submitText]
|
|
755
|
+
})
|
|
756
|
+
}), onCancel && showCancel && /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
|
|
749
757
|
type: "button",
|
|
750
|
-
className: "ufg-button ".concat(
|
|
751
|
-
onClick:
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
}
|
|
755
|
-
})
|
|
756
|
-
type: "submit",
|
|
757
|
-
className: "ufg-button ufg-button-primary",
|
|
758
|
-
disabled: isSubmitting || hasErrors
|
|
759
|
-
}, isSubmitting ? 'Saving…' : submitText), onCancel && showCancel && /*#__PURE__*/React.createElement("button", {
|
|
760
|
-
type: "button",
|
|
761
|
-
className: "ufg-button ufg-button-secondary",
|
|
762
|
-
onClick: onCancel
|
|
763
|
-
}, cancelText));
|
|
758
|
+
className: "ufg-button ".concat(cancelButton.className || 'ufg-button-secondary'),
|
|
759
|
+
onClick: onCancel,
|
|
760
|
+
style: _objectSpread(_objectSpread({}, actionsStyle), cancelButton.style),
|
|
761
|
+
children: [(_cancelButton$icon = cancelButton.icon) !== null && _cancelButton$icon !== void 0 ? _cancelButton$icon : '', cancelText]
|
|
762
|
+
})]
|
|
763
|
+
});
|
|
764
764
|
|
|
765
765
|
// #endregion
|
|
766
766
|
// #region Form JSX
|
|
767
|
-
var formJSX = /*#__PURE__*/
|
|
767
|
+
var formJSX = /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
|
|
768
768
|
className: "ufg-form",
|
|
769
|
-
style:
|
|
769
|
+
style: {
|
|
770
770
|
margin: 'auto'
|
|
771
771
|
},
|
|
772
|
-
onSubmit: onFormSubmit
|
|
773
|
-
|
|
772
|
+
onSubmit: onFormSubmit,
|
|
773
|
+
children: [buildContent(), actionsBar]
|
|
774
|
+
});
|
|
774
775
|
if (enableModal) {
|
|
775
|
-
return /*#__PURE__*/
|
|
776
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Modal, {
|
|
776
777
|
show: modalShow,
|
|
777
778
|
onHide: onCancel,
|
|
778
779
|
size: modalSize,
|
|
779
|
-
style: containerStyle
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
780
|
+
style: containerStyle,
|
|
781
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Header, {
|
|
782
|
+
closeButton: true,
|
|
783
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Modal.Title, {
|
|
784
|
+
style: titleStyle,
|
|
785
|
+
children: [titleIcon, " ", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
786
|
+
children: title
|
|
787
|
+
})]
|
|
788
|
+
})
|
|
789
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Body, {
|
|
790
|
+
children: formJSX
|
|
791
|
+
})]
|
|
792
|
+
});
|
|
783
793
|
}
|
|
784
|
-
return /*#__PURE__*/
|
|
794
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
785
795
|
className: disableDefaultContainer ? '' : 'ufg-container',
|
|
786
|
-
style: containerStyle
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
796
|
+
style: containerStyle,
|
|
797
|
+
children: [title && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
798
|
+
className: "ufg-title",
|
|
799
|
+
style: titleStyle,
|
|
800
|
+
children: [titleIcon, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
801
|
+
children: title
|
|
802
|
+
})]
|
|
803
|
+
}), formJSX]
|
|
804
|
+
});
|
|
790
805
|
};
|
|
791
806
|
var _default = exports["default"] = GenericForm;
|
package/package.json
CHANGED