dce-reactkit 3.9.3 → 3.9.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -186,6 +186,7 @@ var ModalButtonType$1 = ModalButtonType;
186
186
  var ModalType;
187
187
  (function (ModalType) {
188
188
  ModalType["Okay"] = "okay";
189
+ ModalType["Cancel"] = "cancel";
189
190
  ModalType["OkayCancel"] = "okay-cancel";
190
191
  ModalType["YesNo"] = "yes-no";
191
192
  ModalType["YesNoCancel"] = "yes-no-cancel";
@@ -340,6 +341,9 @@ const modalTypeToModalButtonTypes = {
340
341
  [ModalType$1.Okay]: [
341
342
  ModalButtonType$1.Okay,
342
343
  ],
344
+ [ModalType$1.Cancel]: [
345
+ ModalButtonType$1.Cancel,
346
+ ],
343
347
  [ModalType$1.OkayCancel]: [
344
348
  ModalButtonType$1.Okay,
345
349
  ModalButtonType$1.Cancel,
@@ -1080,6 +1084,11 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
1080
1084
  });
1081
1085
  });
1082
1086
  /*----------------------------------------*/
1087
+ /* --------------- Prompt -------------- */
1088
+ /*----------------------------------------*/
1089
+ // Stored copies of setters
1090
+ let setPromptInfo;
1091
+ /*----------------------------------------*/
1083
1092
  /* ------------- Fatal Error ------------ */
1084
1093
  /*----------------------------------------*/
1085
1094
  // Stored copies of setters
@@ -1095,14 +1104,14 @@ const fatalErrorHandlers = [];
1095
1104
  * @param [errorTitle] title of the error box
1096
1105
  */
1097
1106
  const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
1098
- var _a, _b;
1107
+ var _b, _c;
1099
1108
  // Determine message and code
1100
1109
  const message = (typeof error === 'string'
1101
1110
  ? error.trim()
1102
- : String((_a = error.message) !== null && _a !== void 0 ? _a : 'An unknown error occurred.'));
1111
+ : String((_b = error.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred.'));
1103
1112
  const code = (typeof error === 'string'
1104
1113
  ? ReactKitErrorCode$1.NoCode
1105
- : String((_b = error.code) !== null && _b !== void 0 ? _b : ReactKitErrorCode$1.NoCode));
1114
+ : String((_c = error.code) !== null && _c !== void 0 ? _c : ReactKitErrorCode$1.NoCode));
1106
1115
  // Call all fatal error listeners
1107
1116
  try {
1108
1117
  fatalErrorHandlers.forEach((handler) => {
@@ -1229,6 +1238,9 @@ const AppWrapper = (props) => {
1229
1238
  // Confirm
1230
1239
  const [confirmInfo, setConfirmInfoInner,] = React.useState(undefined);
1231
1240
  setConfirmInfo = setConfirmInfoInner;
1241
+ // Prompt
1242
+ const [promptInfo, setPromptInfoInner] = React.useState(undefined);
1243
+ setPromptInfo = setPromptInfoInner;
1232
1244
  // Session expired
1233
1245
  const [sessionHasExpired, setSessionHasExpiredInner,] = React.useState(false);
1234
1246
  setSessionHasExpired = setSessionHasExpiredInner;
@@ -1259,6 +1271,34 @@ const AppWrapper = (props) => {
1259
1271
  }
1260
1272
  }, onTopOfOtherModals: true, dontAllowBackdropExit: true }, confirmInfo.text));
1261
1273
  }
1274
+ /* ------------- Prompt ------------ */
1275
+ if (promptInfo) {
1276
+ // Run min char validation
1277
+ const minNumCharsValidationError = ((promptInfo.opts.minNumChars
1278
+ && promptInfo.currentInputFieldText.length < promptInfo.opts.minNumChars)
1279
+ ? `Please enter at least ${promptInfo.opts.minNumChars} characters.`
1280
+ : undefined);
1281
+ // Run custom validation
1282
+ const customValidationError = (promptInfo.opts.findValidationError
1283
+ && promptInfo.opts.findValidationError(promptInfo.currentInputFieldText));
1284
+ modal = (React__default["default"].createElement(Modal, { key: `prompt-${promptInfo.title}-${promptInfo.text}`, title: promptInfo.title,
1285
+ // only show the cancel button if there is a validation error
1286
+ type: ((customValidationError || minNumCharsValidationError)
1287
+ ? ModalType$1.Cancel
1288
+ : ModalType$1.OkayCancel), okayLabel: promptInfo.opts.confirmButtonText, okayVariant: promptInfo.opts.confirmButtonVariant, cancelLabel: promptInfo.opts.cancelButtonText, cancelVariant: promptInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
1289
+ (buttonType === ModalButtonType$1.Okay
1290
+ ? promptInfo.currentInputFieldText
1291
+ : null);
1292
+ setPromptInfo(undefined);
1293
+ }, onTopOfOtherModals: true, dontAllowBackdropExit: true },
1294
+ React__default["default"].createElement("div", { className: "d-flex flex-column align-items-center" },
1295
+ React__default["default"].createElement("p", null, promptInfo.text),
1296
+ React__default["default"].createElement("input", { type: "text", placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
1297
+ return setPromptInfo(Object.assign(Object.assign({}, promptInfo), { currentInputFieldText: e.target.value }));
1298
+ } }),
1299
+ minNumCharsValidationError && (React__default["default"].createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, minNumCharsValidationError)),
1300
+ customValidationError && (React__default["default"].createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, customValidationError)))));
1301
+ }
1262
1302
  /* ------ Custom Modal Portals ------ */
1263
1303
  // Custom modal portals
1264
1304
  const customModalPortals = [];