@insticc/genericform 2.1.2 → 2.1.4

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.
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
 
3
- 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); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports["default"] = void 0;
8
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _defaults = require("./defaults");
10
8
  var _react = require("react");
9
+ var _defaults = require("./defaults");
11
10
  var _jsxRuntime = require("react/jsx-runtime");
12
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13
12
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
@@ -25,6 +24,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
25
24
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
26
25
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
27
26
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
27
+ 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); }
28
28
  var IndeterminateCheckbox = function IndeterminateCheckbox(_ref) {
29
29
  var id = _ref.id,
30
30
  checked = _ref.checked,
@@ -82,6 +82,15 @@ var CustomCheckboxGroup = function CustomCheckboxGroup(_ref2) {
82
82
  inputStyle = _ref2$inputStyle === void 0 ? {} : _ref2$inputStyle,
83
83
  _ref2$tooltipStyle = _ref2.tooltipStyle,
84
84
  tooltipStyle = _ref2$tooltipStyle === void 0 ? {} : _ref2$tooltipStyle;
85
+ var isObject = (0, _react.useMemo)(function () {
86
+ return !!options && _typeof(options[0]) === "object";
87
+ }, [options]);
88
+ var getValue = (0, _react.useCallback)(function (opt) {
89
+ return isObject ? opt.id || opt.value || opt.name : opt;
90
+ }, [isObject]);
91
+ var getLabel = (0, _react.useCallback)(function (opt) {
92
+ return isObject ? opt.label || opt.text || opt.name : opt;
93
+ }, [isObject]);
85
94
  var _useState = (0, _react.useState)({}),
86
95
  _useState2 = _slicedToArray(_useState, 2),
87
96
  collapsed = _useState2[0],
@@ -95,16 +104,16 @@ var CustomCheckboxGroup = function CustomCheckboxGroup(_ref2) {
95
104
  var getChildValues = (0, _react.useCallback)(function (opt) {
96
105
  var _opt$options$map, _opt$options;
97
106
  return (_opt$options$map = (_opt$options = opt.options) === null || _opt$options === void 0 ? void 0 : _opt$options.map(function (s) {
98
- return s.name || s.value;
107
+ return getValue(s);
99
108
  })) !== null && _opt$options$map !== void 0 ? _opt$options$map : [];
100
109
  }, []);
101
110
  var isAllChecked = (0, _react.useCallback)(function (opt) {
102
- var parentVal = opt.name || opt.value;
111
+ var parentVal = getValue(opt);
103
112
  var children = getChildValues(opt);
104
113
  return children.length > 0 && checked.includes(parentVal) && children.every(function (v) {
105
114
  return checked.includes(v);
106
115
  });
107
- }, [checked, getChildValues]);
116
+ }, [checked, getValue, getChildValues]);
108
117
  var isSomeChecked = (0, _react.useCallback)(function (opt) {
109
118
  var children = getChildValues(opt);
110
119
  return children.some(function (v) {
@@ -119,14 +128,14 @@ var CustomCheckboxGroup = function CustomCheckboxGroup(_ref2) {
119
128
  onOptionChange === null || onOptionChange === void 0 || onOptionChange(data);
120
129
  }, [onChange, onOptionChange, name, checked]);
121
130
  var handleParentChange = (0, _react.useCallback)(function (opt, state) {
122
- var parentVal = opt.name || opt.value;
131
+ var parentVal = getValue(opt);
123
132
  var children = getChildValues(opt);
124
- var data = state ? _toConsumableArray(new Set(parentCheckAll ? [].concat(_toConsumableArray(checked), [parentVal, children]) : [].concat(_toConsumableArray(checked), [parentVal]))) : checked.filter(function (v) {
133
+ var data = state ? _toConsumableArray(new Set(parentCheckAll ? [].concat(_toConsumableArray(checked), [parentVal], _toConsumableArray(children)) : [].concat(_toConsumableArray(checked), [parentVal]))) : checked.filter(function (v) {
125
134
  return v !== parentVal && !children.includes(v);
126
135
  });
127
136
  onChange === null || onChange === void 0 || onChange(name, data);
128
137
  onOptionChange === null || onOptionChange === void 0 || onOptionChange(data);
129
- }, [onChange, onOptionChange, name, checked, getChildValues]);
138
+ }, [onChange, onOptionChange, name, checked, parentCheckAll, getValue, getChildValues]);
130
139
  var toggleCollapse = (0, _react.useCallback)(function (idx) {
131
140
  setCollapsed(function (prev) {
132
141
  return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, idx, !prev[idx]));
@@ -150,7 +159,7 @@ var CustomCheckboxGroup = function CustomCheckboxGroup(_ref2) {
150
159
  var _opt$options2;
151
160
  var hasChildren = !!((_opt$options2 = opt.options) !== null && _opt$options2 !== void 0 && _opt$options2.length);
152
161
  var isCollapsed = collapsible && !!collapsed[idx];
153
- var parentVal = opt.name || opt.value;
162
+ var parentVal = getValue(opt);
154
163
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
155
164
  children: [idx > 0 && grouped && /*#__PURE__*/(0, _jsxRuntime.jsx)("hr", {
156
165
  style: {
@@ -201,7 +210,7 @@ var CustomCheckboxGroup = function CustomCheckboxGroup(_ref2) {
201
210
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
202
211
  htmlFor: "".concat(name, "-").concat(idx),
203
212
  style: opt.labelStyle,
204
- children: opt.label || opt.text
213
+ children: getLabel(opt)
205
214
  })]
206
215
  })]
207
216
  }), hasChildren && !isCollapsed && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
@@ -210,24 +219,25 @@ var CustomCheckboxGroup = function CustomCheckboxGroup(_ref2) {
210
219
  paddingLeft: collapsible ? '2rem' : '1.25rem'
211
220
  },
212
221
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {}), opt.options.map(function (subopt, subidx) {
222
+ var suboptVal = getValue(subopt);
213
223
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
214
224
  className: "ufg-checkbox-item",
215
225
  style: inputStyle,
216
226
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
217
227
  id: "".concat(name, "-").concat(idx, "-").concat(subidx),
218
228
  type: "checkbox",
219
- checked: checked.includes(subopt.name || subopt.value),
229
+ checked: checked.includes(suboptVal),
220
230
  disabled: !!subopt.disabled,
221
231
  style: subopt.inputStyle,
222
232
  onChange: function onChange(e) {
223
- return handleChange(subopt.name || subopt.value, e.target.checked);
233
+ return handleChange(suboptVal, e.target.checked);
224
234
  }
225
235
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
226
236
  htmlFor: "".concat(name, "-").concat(idx, "-").concat(subidx),
227
237
  style: subopt.labelStyle,
228
- children: subopt.label || subopt.text
238
+ children: getLabel(subopt)
229
239
  })]
230
- }, subopt.name || subopt.value);
240
+ }, suboptVal);
231
241
  })]
232
242
  })]
233
243
  }, "".concat(name, "-").concat(idx));
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
7
8
  var _react = require("react");
8
9
  var _defaults = require("./defaults");
9
10
  var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
12
  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); }
11
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -28,6 +30,8 @@ var CustomFileInput = function CustomFileInput(_ref) {
28
30
  error = _ref.error,
29
31
  _ref$tooltip = _ref.tooltip,
30
32
  tooltip = _ref$tooltip === void 0 ? "" : _ref$tooltip,
33
+ _ref$tooltipInline = _ref.tooltipInline,
34
+ tooltipInline = _ref$tooltipInline === void 0 ? false : _ref$tooltipInline,
31
35
  _ref$showHelp = _ref.showHelp,
32
36
  showHelp = _ref$showHelp === void 0 ? false : _ref$showHelp,
33
37
  _ref$helpText = _ref.helpText,
@@ -68,7 +72,7 @@ var CustomFileInput = function CustomFileInput(_ref) {
68
72
  style: {
69
73
  display: 'flex',
70
74
  alignItems: 'center',
71
- gap: 8
75
+ gap: 10
72
76
  },
73
77
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
74
78
  type: "button",
@@ -85,7 +89,7 @@ var CustomFileInput = function CustomFileInput(_ref) {
85
89
  return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.click();
86
90
  },
87
91
  children: placeholder || "Select"
88
- }), value ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
92
+ }), value && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
89
93
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
90
94
  style: {
91
95
  fontSize: '0.85rem',
@@ -108,13 +112,7 @@ var CustomFileInput = function CustomFileInput(_ref) {
108
112
  title: "Remove file",
109
113
  children: "\u2715"
110
114
  })]
111
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
112
- style: {
113
- fontSize: '0.82rem',
114
- color: '#aaa'
115
- },
116
- children: "No file selected"
117
- })]
115
+ }), tooltipInline && (0, _defaults.tooltipJsx)(tooltip, tooltipStyle)]
118
116
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
119
117
  id: "form-input-".concat(name),
120
118
  ref: ref,
@@ -125,7 +123,27 @@ var CustomFileInput = function CustomFileInput(_ref) {
125
123
  },
126
124
  disabled: disabled,
127
125
  onChange: handleChange
128
- }), (0, _defaults.errorJsx)(error), (0, _defaults.tooltipJsx)(tooltip, tooltipStyle)]
126
+ }), (0, _defaults.errorJsx)(error), !tooltipInline && (0, _defaults.tooltipJsx)(tooltip, tooltipStyle)]
129
127
  });
130
128
  };
129
+ CustomFileInput.propType = {
130
+ onChange: _propTypes["default"].func.isRequired,
131
+ name: _propTypes["default"].string.isRequired,
132
+ label: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),
133
+ value: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number, _propTypes["default"].array, _propTypes["default"].object]),
134
+ accept: _propTypes["default"].string,
135
+ placeholder: _propTypes["default"].string,
136
+ disabled: _propTypes["default"].bool,
137
+ required: _propTypes["default"].bool,
138
+ error: _propTypes["default"].string,
139
+ tooltip: _propTypes["default"].string,
140
+ tooltipInline: _propTypes["default"].bool,
141
+ showHelp: _propTypes["default"].bool,
142
+ helpText: _propTypes["default"].string,
143
+ mainDivStyle: _propTypes["default"].object,
144
+ labelStyle: _propTypes["default"].object,
145
+ spanStyle: _propTypes["default"].object,
146
+ inputStyle: _propTypes["default"].object,
147
+ tooltipStyle: _propTypes["default"].object
148
+ };
131
149
  var _default = exports["default"] = CustomFileInput;
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _react = require("react");
9
+ var _defaults = require("./defaults");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
13
+ 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."); }
14
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
17
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
18
+ var EyeIcon = function EyeIcon(_ref) {
19
+ var visible = _ref.visible;
20
+ return visible ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", {
21
+ viewBox: "0 0 20 20",
22
+ fill: "none",
23
+ xmlns: "http://www.w3.org/2000/svg",
24
+ width: "18",
25
+ height: "18",
26
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
27
+ d: "M2 10s3-6 8-6 8 6 8 6-3 6-8 6-8-6-8-6z",
28
+ stroke: "#9CA3AF",
29
+ strokeWidth: "1.5"
30
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", {
31
+ cx: "10",
32
+ cy: "10",
33
+ r: "2.5",
34
+ stroke: "#9CA3AF",
35
+ strokeWidth: "1.5"
36
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
37
+ d: "M3 3l14 14",
38
+ stroke: "#9CA3AF",
39
+ strokeWidth: "1.5",
40
+ strokeLinecap: "round"
41
+ })]
42
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", {
43
+ viewBox: "0 0 20 20",
44
+ fill: "none",
45
+ xmlns: "http://www.w3.org/2000/svg",
46
+ width: "18",
47
+ height: "18",
48
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
49
+ d: "M2 10s3-6 8-6 8 6 8 6-3 6-8 6-8-6-8-6z",
50
+ stroke: "#9CA3AF",
51
+ strokeWidth: "1.5"
52
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", {
53
+ cx: "10",
54
+ cy: "10",
55
+ r: "2.5",
56
+ stroke: "#9CA3AF",
57
+ strokeWidth: "1.5"
58
+ })]
59
+ });
60
+ };
61
+ var getStrength = function getStrength(password) {
62
+ if (!password) return null;
63
+ var score = 0;
64
+ if (password.length >= 8) score++;
65
+ if (password.length >= 12) score++;
66
+ if (/[A-Z]/.test(password)) score++;
67
+ if (/[0-9]/.test(password)) score++;
68
+ if (/[^A-Za-z0-9]/.test(password)) score++;
69
+ if (score <= 1) return {
70
+ level: 1,
71
+ label: "Weak",
72
+ color: "#ef4444"
73
+ };
74
+ if (score <= 3) return {
75
+ level: 2,
76
+ label: "Fair",
77
+ color: "#f59e0b"
78
+ };
79
+ if (score === 4) return {
80
+ level: 3,
81
+ label: "Good",
82
+ color: "#3b82f6"
83
+ };
84
+ return {
85
+ level: 4,
86
+ label: "Strong",
87
+ color: "#22c55e"
88
+ };
89
+ };
90
+ var CustomPasswordInput = function CustomPasswordInput(_ref2) {
91
+ var _ref3;
92
+ var onChange = _ref2.onChange,
93
+ name = _ref2.name,
94
+ label = _ref2.label,
95
+ _ref2$value = _ref2.value,
96
+ value = _ref2$value === void 0 ? "" : _ref2$value,
97
+ _ref2$disabled = _ref2.disabled,
98
+ disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
99
+ _ref2$required = _ref2.required,
100
+ required = _ref2$required === void 0 ? false : _ref2$required,
101
+ placeholder = _ref2.placeholder,
102
+ error = _ref2.error,
103
+ _ref2$tooltip = _ref2.tooltip,
104
+ tooltip = _ref2$tooltip === void 0 ? "" : _ref2$tooltip,
105
+ _ref2$showHelp = _ref2.showHelp,
106
+ showHelp = _ref2$showHelp === void 0 ? false : _ref2$showHelp,
107
+ _ref2$helpText = _ref2.helpText,
108
+ helpText = _ref2$helpText === void 0 ? "" : _ref2$helpText,
109
+ className = _ref2.className,
110
+ _ref2$showStrength = _ref2.showStrength,
111
+ showStrength = _ref2$showStrength === void 0 ? false : _ref2$showStrength,
112
+ matchValue = _ref2.matchValue,
113
+ _ref2$mainDivStyle = _ref2.mainDivStyle,
114
+ mainDivStyle = _ref2$mainDivStyle === void 0 ? {} : _ref2$mainDivStyle,
115
+ _ref2$labelStyle = _ref2.labelStyle,
116
+ labelStyle = _ref2$labelStyle === void 0 ? {} : _ref2$labelStyle,
117
+ _ref2$spanStyle = _ref2.spanStyle,
118
+ spanStyle = _ref2$spanStyle === void 0 ? {} : _ref2$spanStyle,
119
+ _ref2$inputStyle = _ref2.inputStyle,
120
+ inputStyle = _ref2$inputStyle === void 0 ? {} : _ref2$inputStyle,
121
+ _ref2$tooltipStyle = _ref2.tooltipStyle,
122
+ tooltipStyle = _ref2$tooltipStyle === void 0 ? {} : _ref2$tooltipStyle;
123
+ var _useState = (0, _react.useState)(false),
124
+ _useState2 = _slicedToArray(_useState, 2),
125
+ visible = _useState2[0],
126
+ setVisible = _useState2[1];
127
+ var handleChange = (0, _react.useCallback)(function (e) {
128
+ return onChange === null || onChange === void 0 ? void 0 : onChange(name, e.target.value);
129
+ }, [onChange, name]);
130
+ var strength = showStrength ? getStrength(value) : null;
131
+ var showMatch = matchValue !== undefined && value.length > 0 && matchValue.length > 0;
132
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
133
+ className: "ufg-field-group",
134
+ id: name,
135
+ style: mainDivStyle,
136
+ children: [(0, _defaults.labelJsx)({
137
+ name: name,
138
+ labelStyle: labelStyle,
139
+ label: label,
140
+ required: required,
141
+ spanStyle: spanStyle,
142
+ showHelp: showHelp,
143
+ helpText: helpText
144
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
145
+ className: "ufg-input-wrapper",
146
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
147
+ id: "form-input-".concat(name),
148
+ type: visible ? "text" : "password",
149
+ name: name,
150
+ value: value,
151
+ placeholder: (_ref3 = placeholder !== null && placeholder !== void 0 ? placeholder : label) !== null && _ref3 !== void 0 ? _ref3 : "••••••••••",
152
+ disabled: disabled,
153
+ required: required,
154
+ autoComplete: "current-password",
155
+ className: "ufg-input ufg-input--padded".concat(error ? " error" : "").concat(className ? " ".concat(className) : ""),
156
+ style: inputStyle,
157
+ onChange: handleChange
158
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
159
+ type: "button",
160
+ className: "ufg-eye-btn",
161
+ onClick: function onClick() {
162
+ return setVisible(function (v) {
163
+ return !v;
164
+ });
165
+ },
166
+ "aria-label": visible ? "Hide password" : "Show password",
167
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(EyeIcon, {
168
+ visible: visible
169
+ })
170
+ })]
171
+ }), showStrength && value.length > 0 && strength && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
172
+ className: "ufg-strength",
173
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
174
+ className: "ufg-strength-bar",
175
+ children: [1, 2, 3, 4].map(function (i) {
176
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
177
+ className: "ufg-strength-segment",
178
+ style: {
179
+ background: i <= strength.level ? strength.color : "#e5e7eb"
180
+ }
181
+ }, i);
182
+ })
183
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
184
+ className: "ufg-strength-label",
185
+ style: {
186
+ color: strength.color
187
+ },
188
+ children: strength.label
189
+ })]
190
+ }), showMatch && /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
191
+ className: "ufg-match ".concat(value === matchValue ? "ufg-match--ok" : "ufg-match--no"),
192
+ children: value === matchValue ? "✓ Passwords match" : "✗ Passwords do not match"
193
+ }), (0, _defaults.errorJsx)(error), (0, _defaults.tooltipJsx)(tooltip, tooltipStyle)]
194
+ });
195
+ };
196
+ CustomPasswordInput.propTypes = {
197
+ onChange: _propTypes["default"].func.isRequired,
198
+ name: _propTypes["default"].string.isRequired,
199
+ label: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object]),
200
+ value: _propTypes["default"].string,
201
+ disabled: _propTypes["default"].bool,
202
+ required: _propTypes["default"].bool,
203
+ placeholder: _propTypes["default"].string,
204
+ error: _propTypes["default"].string,
205
+ tooltip: _propTypes["default"].string,
206
+ showHelp: _propTypes["default"].bool,
207
+ helpText: _propTypes["default"].string,
208
+ className: _propTypes["default"].string,
209
+ showStrength: _propTypes["default"].bool,
210
+ matchValue: _propTypes["default"].string,
211
+ inputStyle: _propTypes["default"].object,
212
+ mainDivStyle: _propTypes["default"].object,
213
+ labelStyle: _propTypes["default"].object,
214
+ spanStyle: _propTypes["default"].object,
215
+ tooltipStyle: _propTypes["default"].object
216
+ };
217
+ var _default = exports["default"] = CustomPasswordInput;
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _propTypes = _interopRequireWildcard(require("prop-types"));
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _react = require("react");
8
9
  var _defaults = require("./defaults");
9
10
  var _jsxRuntime = require("react/jsx-runtime");
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
12
12
  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); }
13
13
  var CustomRadioGroup = function CustomRadioGroup(_ref) {
14
14
  var _onChange = _ref.onChange,
@@ -43,7 +43,9 @@ var CustomRadioGroup = function CustomRadioGroup(_ref) {
43
43
  inputStyle = _ref$inputStyle === void 0 ? {} : _ref$inputStyle,
44
44
  _ref$tooltipStyle = _ref.tooltipStyle,
45
45
  tooltipStyle = _ref$tooltipStyle === void 0 ? {} : _ref$tooltipStyle;
46
- var isObject = _typeof(options[0]) === "object";
46
+ var isObject = (0, _react.useMemo)(function () {
47
+ return !!options && _typeof(options[0]) === "object";
48
+ }, [options]);
47
49
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
48
50
  className: "ufg-field-group",
49
51
  id: name,
package/build/index.js CHANGED
@@ -51,12 +51,6 @@ Object.defineProperty(exports, "CustomInput", {
51
51
  return _CustomInput["default"];
52
52
  }
53
53
  });
54
- Object.defineProperty(exports, "CustomInputAdd", {
55
- enumerable: true,
56
- get: function get() {
57
- return _CustomInputAdd["default"];
58
- }
59
- });
60
54
  Object.defineProperty(exports, "CustomJson", {
61
55
  enumerable: true,
62
56
  get: function get() {
@@ -81,6 +75,12 @@ Object.defineProperty(exports, "CustomNumberInput", {
81
75
  return _CustomNumberInput["default"];
82
76
  }
83
77
  });
78
+ Object.defineProperty(exports, "CustomPasswordInput", {
79
+ enumerable: true,
80
+ get: function get() {
81
+ return _CustomPasswordInput["default"];
82
+ }
83
+ });
84
84
  Object.defineProperty(exports, "CustomRadioGroup", {
85
85
  enumerable: true,
86
86
  get: function get() {
@@ -129,6 +129,7 @@ var _CustomLabel = _interopRequireDefault(require("./FormFields/CustomLabel"));
129
129
  var _CustomMobilePhone = _interopRequireDefault(require("./FormFields/CustomMobilePhone"));
130
130
  var _CustomMultiDropdown = _interopRequireDefault(require("./FormFields/CustomMultiDropdown"));
131
131
  var _CustomNumberInput = _interopRequireDefault(require("./FormFields/CustomNumberInput"));
132
+ var _CustomPasswordInput = _interopRequireDefault(require("./FormFields/CustomPasswordInput"));
132
133
  var _CustomRadioGroup = _interopRequireDefault(require("./FormFields/CustomRadioGroup"));
133
134
  var _CustomSearch = _interopRequireDefault(require("./FormFields/CustomSearch"));
134
135
  var _CustomSeparator = _interopRequireDefault(require("./FormFields/CustomSeparator"));
@@ -261,7 +262,10 @@ var GenericForm = function GenericForm(_ref) {
261
262
  _ref$modalSize = _ref.modalSize,
262
263
  modalSize = _ref$modalSize === void 0 ? 'lg' : _ref$modalSize,
263
264
  _ref$disableFormTag = _ref.disableFormTag,
264
- disableFormTag = _ref$disableFormTag === void 0 ? false : _ref$disableFormTag;
265
+ disableFormTag = _ref$disableFormTag === void 0 ? false : _ref$disableFormTag,
266
+ _ref$isSubmitting = _ref.isSubmitting,
267
+ isSubmitting = _ref$isSubmitting === void 0 ? false : _ref$isSubmitting,
268
+ handleErrors = _ref.handleErrors;
265
269
  var _useState = (0, _react.useState)([]),
266
270
  _useState2 = _slicedToArray(_useState, 2),
267
271
  sortedFields = _useState2[0],
@@ -277,9 +281,15 @@ var GenericForm = function GenericForm(_ref) {
277
281
  setErrors = _useState6[1];
278
282
  var _useState7 = (0, _react.useState)(false),
279
283
  _useState8 = _slicedToArray(_useState7, 2),
280
- isSubmitting = _useState8[0],
284
+ isSubmittingInternal = _useState8[0],
281
285
  setIsSubmitting = _useState8[1];
282
286
  var prevFieldValuesRef = (0, _react.useRef)({});
287
+ (0, _react.useEffect)(function () {
288
+ setIsSubmitting(isSubmitting);
289
+ }, [isSubmitting]);
290
+ (0, _react.useEffect)(function () {
291
+ handleErrors && handleErrors(errors);
292
+ }, [errors]);
283
293
 
284
294
  // ── Sync fields ─────────────────────────────────────────────────────────────
285
295
  (0, _react.useEffect)(function () {
@@ -551,7 +561,7 @@ var GenericForm = function GenericForm(_ref) {
551
561
 
552
562
  // #region RenderField
553
563
  var renderField = (0, _react.useCallback)(function (field) {
554
- var _internalFormData$fie2;
564
+ var _internalFormData$fie2, _field$showStrength;
555
565
  var isHidden = typeof field.hide === 'function' ? field.hide(internalFormData, field) : field.hide;
556
566
  if (isHidden) return null;
557
567
  var error = errors[field.name];
@@ -594,15 +604,20 @@ var GenericForm = function GenericForm(_ref) {
594
604
  case 'string':
595
605
  case 'text':
596
606
  case 'email':
597
- case 'password':
598
607
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomInput["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
599
608
  value: value,
600
609
  type: field.type === 'email' ? 'email' : field.type === 'password' ? 'password' : 'text',
601
- placeholder: field.placeholder,
602
610
  onChange: fieldHandler(field),
603
- inputStyle: field.inputStyle,
604
611
  className: field.className
605
612
  }), field.name);
613
+ case 'password':
614
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomPasswordInput["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
615
+ value: value,
616
+ onChange: fieldHandler(field),
617
+ className: field.className,
618
+ showStrength: (_field$showStrength = field.showStrength) !== null && _field$showStrength !== void 0 ? _field$showStrength : false,
619
+ matchValue: field.matchField ? internalFormData[field.matchField] : undefined
620
+ }), field.name);
606
621
  case 'int':
607
622
  case 'number':
608
623
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomNumberInput["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
@@ -705,7 +720,8 @@ var GenericForm = function GenericForm(_ref) {
705
720
  grouped: field.grouped,
706
721
  collapsible: field.collapsible,
707
722
  defaultCollapsed: field.defaultCollapsed,
708
- enableParent: field.enableParent
723
+ enableParent: field.enableParent,
724
+ parentCheckAll: field.parentCheckAll
709
725
  }), field.name);
710
726
  case 'radioGroup':
711
727
  case 'radioGroupInline':
@@ -747,6 +763,7 @@ var GenericForm = function GenericForm(_ref) {
747
763
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomFileInput["default"], _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, cp), sp), fp), {}, {
748
764
  value: value,
749
765
  accept: field.accept,
766
+ tooltipInline: field.tooltipInline,
750
767
  onChange: fieldHandler(field)
751
768
  }), field.name);
752
769
  case 'inputAdd':
@@ -794,7 +811,9 @@ var GenericForm = function GenericForm(_ref) {
794
811
  var renderGroupSection = function renderGroupSection(g, fieldList) {
795
812
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
796
813
  className: "ufg-fields",
797
- style: fieldsStyle,
814
+ style: enableModal ? _objectSpread({
815
+ gap: "1em"
816
+ }, fieldsStyle) : fieldsStyle,
798
817
  children: [g !== 'ungrouped' && /*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
799
818
  children: g
800
819
  }), renderFields(fieldList)]
@@ -891,7 +910,9 @@ var GenericForm = function GenericForm(_ref) {
891
910
  var hasErrors = Object.values(errors).some(Boolean);
892
911
  var actionsBar = /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
893
912
  className: "ufg-actions",
894
- style: actionsDivStyle,
913
+ style: enableModal ? _objectSpread({
914
+ justifyContent: "center"
915
+ }, actionsDivStyle) : actionsDivStyle,
895
916
  children: [customActions.map(function (action, idx) {
896
917
  return (0, _CustomAction["default"])(_objectSpread(_objectSpread({}, action), {}, {
897
918
  name: "".concat(action.name, " ").concat(idx),
@@ -901,9 +922,9 @@ var GenericForm = function GenericForm(_ref) {
901
922
  }), showSubmit && haveSaveButton && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
902
923
  type: "submit",
903
924
  className: "ufg-button ".concat(submitButton.className || 'ufg-button-primary'),
904
- disabled: isSubmitting || hasErrors,
925
+ disabled: isSubmittingInternal || hasErrors,
905
926
  style: _objectSpread(_objectSpread({}, actionsStyle), submitButton.style),
906
- children: isSubmitting ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
927
+ children: isSubmittingInternal ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
907
928
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_semanticUiReact.Icon, {
908
929
  name: "spinner",
909
930
  loading: true
@@ -924,14 +945,20 @@ var GenericForm = function GenericForm(_ref) {
924
945
  // #region Form JSX
925
946
  var formJSX = disableFormTag ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
926
947
  className: "ufg-form",
927
- style: formStyle || {
948
+ style: enableModal ? _objectSpread({
949
+ padding: "2em",
950
+ gap: "3em"
951
+ }, formStyle) : formStyle || {
928
952
  margin: 'auto'
929
953
  },
930
954
  onSubmit: onFormSubmit,
931
955
  children: [buildContent(), actionsBar]
932
956
  }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
933
957
  className: "ufg-form",
934
- style: formStyle || {
958
+ style: enableModal ? _objectSpread({
959
+ padding: "2em",
960
+ gap: "3em"
961
+ }, formStyle) : formStyle || {
935
962
  margin: 'auto'
936
963
  },
937
964
  onSubmit: onFormSubmit,
@@ -944,7 +971,7 @@ var GenericForm = function GenericForm(_ref) {
944
971
  size: modalSize,
945
972
  style: containerStyle,
946
973
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Modal.Header, {
947
- closeButton: true,
974
+ closeButton: !!onCancel,
948
975
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Modal.Title, {
949
976
  style: titleStyle,
950
977
  children: [titleIcon, " ", title, " "]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insticc/genericform",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "A generic form with a comprehensive set of field types, validation, and external state management",
5
5
  "main": "build/index.js",
6
6
  "scripts": {