Add onClose for modals

This commit is contained in:
Zerebos 2024-02-21 19:49:24 -05:00
parent c6c54bf620
commit 7a7912ef6d
2 changed files with 6 additions and 2 deletions

View File

@ -50,6 +50,7 @@ const UI = {
* @param {string} [options.cancelText=Cancel] Text for the cancel button * @param {string} [options.cancelText=Cancel] Text for the cancel button
* @param {callable} [options.onConfirm=NOOP] Callback to occur when clicking the submit button * @param {callable} [options.onConfirm=NOOP] Callback to occur when clicking the submit button
* @param {callable} [options.onCancel=NOOP] Callback to occur when clicking the cancel button * @param {callable} [options.onCancel=NOOP] Callback to occur when clicking the cancel button
* @param {callable} [options.onClose=NOOP] Callback to occur when exiting the modal
* @returns {string} The key used for this modal. * @returns {string} The key used for this modal.
*/ */
showConfirmationModal(title, content, options = {}) { showConfirmationModal(title, content, options = {}) {

View File

@ -157,6 +157,7 @@ export default class Modals {
* @param {string} [options.cancelText=Cancel] - text for the cancel button * @param {string} [options.cancelText=Cancel] - text for the cancel button
* @param {callable} [options.onConfirm=NOOP] - callback to occur when clicking the submit button * @param {callable} [options.onConfirm=NOOP] - callback to occur when clicking the submit button
* @param {callable} [options.onCancel=NOOP] - callback to occur when clicking the cancel button * @param {callable} [options.onCancel=NOOP] - callback to occur when clicking the cancel button
* @param {callable} [options.onClose=NOOP] - callback to occur when exiting the modal
* @param {string} [options.key] - key used to identify the modal. If not provided, one is generated and returned * @param {string} [options.key] - key used to identify the modal. If not provided, one is generated and returned
* @returns {string} - the key used for this modal * @returns {string} - the key used for this modal
*/ */
@ -168,7 +169,7 @@ export default class Modals {
if (content instanceof FormattableString) content = content.toString(); if (content instanceof FormattableString) content = content.toString();
const emptyFunction = () => {}; const emptyFunction = () => {};
const {onConfirm = emptyFunction, onCancel = emptyFunction, confirmText = Strings.Modals.okay, cancelText = Strings.Modals.cancel, danger = false, key = undefined} = options; const {onClose = emptyFunction, onConfirm = emptyFunction, onCancel = emptyFunction, confirmText = Strings.Modals.okay, cancelText = Strings.Modals.cancel, danger = false, key = undefined} = options;
if (!this.ModalActions || !this.ConfirmationModal || !this.Markdown) { if (!this.ModalActions || !this.ConfirmationModal || !this.Markdown) {
return this.default(title, content, [ return this.default(title, content, [
@ -181,6 +182,7 @@ export default class Modals {
content = content.map(c => typeof(c) === "string" ? React.createElement(Markdown, null, c) : c); content = content.map(c => typeof(c) === "string" ? React.createElement(Markdown, null, c) : c);
const modalKey = ModalActions.openModal(props => { const modalKey = ModalActions.openModal(props => {
console.log(props);
return React.createElement(ErrorBoundary, { return React.createElement(ErrorBoundary, {
onError: () => { onError: () => {
setTimeout(() => { setTimeout(() => {
@ -197,7 +199,8 @@ export default class Modals {
confirmText: confirmText, confirmText: confirmText,
cancelText: cancelText, cancelText: cancelText,
onConfirm: onConfirm, onConfirm: onConfirm,
onCancel: onCancel onCancel: onCancel,
onCloseCallback: () => {if (props?.transitionState === 1) onClose?.()}
}, props), React.createElement(ErrorBoundary, {}, content))); }, props), React.createElement(ErrorBoundary, {}, content)));
}, {modalKey: key}); }, {modalKey: key});
return modalKey; return modalKey;