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.
@@ -44,6 +44,30 @@ export declare const confirm: (title: string, text: string, opts?: {
44
44
  cancelButtonText?: string;
45
45
  cancelButtonVariant?: Variant;
46
46
  }) => Promise<boolean>;
47
+ /**
48
+ * Show a prompt modal asking the user for input
49
+ * @author Yuen Ler Chow
50
+ * @param title the title text to display at the top of the prompt
51
+ * @param text the text to display in the prompt
52
+ * @param [opts={}] additional options for the prompt dialog
53
+ * @param [opts.placeholder] the placeholder text for the input field
54
+ * @param [opts.defaultText] the default text for the input field
55
+ * @param [opts.confirmButtonText=Okay] the text of the confirm button
56
+ * @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
57
+ * @param [opts.cancelButtonText=Cancel] the text of the cancel button
58
+ * @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
59
+ * @returns Promise that resolves with the input string or null if canceled
60
+ */
61
+ export declare const prompt: (title: string, text: string, currentInputFieldText: string, opts?: {
62
+ placeholder?: string | undefined;
63
+ defaultText?: string | undefined;
64
+ confirmButtonText?: string | undefined;
65
+ confirmButtonVariant?: Variant | undefined;
66
+ cancelButtonText?: string | undefined;
67
+ cancelButtonVariant?: Variant | undefined;
68
+ minNumChars?: number | undefined;
69
+ findValidationError?: ((text: string) => string | undefined) | undefined;
70
+ } | undefined) => Promise<string | null>;
47
71
  /**
48
72
  * Show a fatal error message
49
73
  * @author Gabe Abrams
@@ -4,6 +4,7 @@
4
4
  */
5
5
  declare enum ModalType {
6
6
  Okay = "okay",
7
+ Cancel = "cancel",
7
8
  OkayCancel = "okay-cancel",
8
9
  YesNo = "yes-no",
9
10
  YesNoCancel = "yes-no-cancel",
package/dist/esm/index.js CHANGED
@@ -158,6 +158,7 @@ var ModalButtonType$1 = ModalButtonType;
158
158
  var ModalType;
159
159
  (function (ModalType) {
160
160
  ModalType["Okay"] = "okay";
161
+ ModalType["Cancel"] = "cancel";
161
162
  ModalType["OkayCancel"] = "okay-cancel";
162
163
  ModalType["YesNo"] = "yes-no";
163
164
  ModalType["YesNoCancel"] = "yes-no-cancel";
@@ -312,6 +313,9 @@ const modalTypeToModalButtonTypes = {
312
313
  [ModalType$1.Okay]: [
313
314
  ModalButtonType$1.Okay,
314
315
  ],
316
+ [ModalType$1.Cancel]: [
317
+ ModalButtonType$1.Cancel,
318
+ ],
315
319
  [ModalType$1.OkayCancel]: [
316
320
  ModalButtonType$1.Okay,
317
321
  ModalButtonType$1.Cancel,
@@ -1052,6 +1056,11 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
1052
1056
  });
1053
1057
  });
1054
1058
  /*----------------------------------------*/
1059
+ /* --------------- Prompt -------------- */
1060
+ /*----------------------------------------*/
1061
+ // Stored copies of setters
1062
+ let setPromptInfo;
1063
+ /*----------------------------------------*/
1055
1064
  /* ------------- Fatal Error ------------ */
1056
1065
  /*----------------------------------------*/
1057
1066
  // Stored copies of setters
@@ -1067,14 +1076,14 @@ const fatalErrorHandlers = [];
1067
1076
  * @param [errorTitle] title of the error box
1068
1077
  */
1069
1078
  const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
1070
- var _a, _b;
1079
+ var _b, _c;
1071
1080
  // Determine message and code
1072
1081
  const message = (typeof error === 'string'
1073
1082
  ? error.trim()
1074
- : String((_a = error.message) !== null && _a !== void 0 ? _a : 'An unknown error occurred.'));
1083
+ : String((_b = error.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred.'));
1075
1084
  const code = (typeof error === 'string'
1076
1085
  ? ReactKitErrorCode$1.NoCode
1077
- : String((_b = error.code) !== null && _b !== void 0 ? _b : ReactKitErrorCode$1.NoCode));
1086
+ : String((_c = error.code) !== null && _c !== void 0 ? _c : ReactKitErrorCode$1.NoCode));
1078
1087
  // Call all fatal error listeners
1079
1088
  try {
1080
1089
  fatalErrorHandlers.forEach((handler) => {
@@ -1201,6 +1210,9 @@ const AppWrapper = (props) => {
1201
1210
  // Confirm
1202
1211
  const [confirmInfo, setConfirmInfoInner,] = useState(undefined);
1203
1212
  setConfirmInfo = setConfirmInfoInner;
1213
+ // Prompt
1214
+ const [promptInfo, setPromptInfoInner] = useState(undefined);
1215
+ setPromptInfo = setPromptInfoInner;
1204
1216
  // Session expired
1205
1217
  const [sessionHasExpired, setSessionHasExpiredInner,] = useState(false);
1206
1218
  setSessionHasExpired = setSessionHasExpiredInner;
@@ -1231,6 +1243,34 @@ const AppWrapper = (props) => {
1231
1243
  }
1232
1244
  }, onTopOfOtherModals: true, dontAllowBackdropExit: true }, confirmInfo.text));
1233
1245
  }
1246
+ /* ------------- Prompt ------------ */
1247
+ if (promptInfo) {
1248
+ // Run min char validation
1249
+ const minNumCharsValidationError = ((promptInfo.opts.minNumChars
1250
+ && promptInfo.currentInputFieldText.length < promptInfo.opts.minNumChars)
1251
+ ? `Please enter at least ${promptInfo.opts.minNumChars} characters.`
1252
+ : undefined);
1253
+ // Run custom validation
1254
+ const customValidationError = (promptInfo.opts.findValidationError
1255
+ && promptInfo.opts.findValidationError(promptInfo.currentInputFieldText));
1256
+ modal = (React__default.createElement(Modal, { key: `prompt-${promptInfo.title}-${promptInfo.text}`, title: promptInfo.title,
1257
+ // only show the cancel button if there is a validation error
1258
+ type: ((customValidationError || minNumCharsValidationError)
1259
+ ? ModalType$1.Cancel
1260
+ : ModalType$1.OkayCancel), okayLabel: promptInfo.opts.confirmButtonText, okayVariant: promptInfo.opts.confirmButtonVariant, cancelLabel: promptInfo.opts.cancelButtonText, cancelVariant: promptInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
1261
+ (buttonType === ModalButtonType$1.Okay
1262
+ ? promptInfo.currentInputFieldText
1263
+ : null);
1264
+ setPromptInfo(undefined);
1265
+ }, onTopOfOtherModals: true, dontAllowBackdropExit: true },
1266
+ React__default.createElement("div", { className: "d-flex flex-column align-items-center" },
1267
+ React__default.createElement("p", null, promptInfo.text),
1268
+ React__default.createElement("input", { type: "text", placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
1269
+ return setPromptInfo(Object.assign(Object.assign({}, promptInfo), { currentInputFieldText: e.target.value }));
1270
+ } }),
1271
+ minNumCharsValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, minNumCharsValidationError)),
1272
+ customValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, customValidationError)))));
1273
+ }
1234
1274
  /* ------ Custom Modal Portals ------ */
1235
1275
  // Custom modal portals
1236
1276
  const customModalPortals = [];