diff --git a/app/assets/javascripts/utilities/showLoginModal.js b/app/assets/javascripts/utilities/showLoginModal.js
index cb8d04816..a667c0b9c 100644
--- a/app/assets/javascripts/utilities/showLoginModal.js
+++ b/app/assets/javascripts/utilities/showLoginModal.js
@@ -1,5 +1,5 @@
function showLoginModal() {
- window.showModal({
+ window.Forem.showModal({
title: 'Log in to continue',
contentSelector: '#global-signup-modal',
overlay: true,
diff --git a/app/assets/javascripts/utilities/showUserAlertModal.js b/app/assets/javascripts/utilities/showUserAlertModal.js
index 355dc9b20..00ba187cd 100644
--- a/app/assets/javascripts/utilities/showUserAlertModal.js
+++ b/app/assets/javascripts/utilities/showUserAlertModal.js
@@ -1,3 +1,12 @@
+/**
+ * HTML ID for modal DOM node
+ *
+ * @private
+ * @constant modalId *
+ * @type {string}
+ */
+const modalId = 'user-alert-modal';
+
/**
* Displays a general purpose user alert modal with a title, body text, and confirmation button.
*
@@ -10,8 +19,12 @@
* showUserAlertModal('Warning', 'You must wait', 'OK', '/faq/why-must-i-wait', 'Why must I wait?');
*/
function showUserAlertModal(title, text, confirm_text) {
- let modalDiv = buildModalDiv(title, text, confirm_text);
- toggleUserAlertModal();
+ buildModalDiv(text, confirm_text);
+ window.Forem.showModal({
+ title,
+ contentSelector: `#${modalId}`,
+ overlay: true,
+ });
}
/**
* Displays a user rate limit alert modal letting the user know what they did that exceeded a rate limit,
@@ -36,60 +49,27 @@ function showRateLimitModal(action_text, next_action_text) {
);
}
-/**
- * HTML ID for modal DOM node
- *
- * @private
- * @constant modalId *
- * @type {string}
- */
-const modalId = 'user-alert-modal';
-
/**
* HTML template for modal
*
* @private
* @function getModalHtml
*
- * @param {string} title The title/heading text to be displayed
* @param {string} text The body text to be displayed
* @param {string} confirm_text Text of the confirmation button
*
* @returns {string} HTML for the modal
*/
-const getModalHtml = (
- title,
- text,
- confirm_text,
-) => `
-
-
-
-
-
-
-
- ${title}
-
-
- ${text}
-
-
-
-
+const getModalHtml = (text, confirm_text) => `
+
+
+
+ ${text}
+
+
-
`;
@@ -108,36 +88,21 @@ function buildRateLimitText(action_text, next_action_text) {
return `Since you recently ${action_text}, you’ll need to wait a moment before ${next_action_text}.`;
}
-/**
- * Shows or hides the user alert modal by toggling it's 'hidden' class
- *
- * @private
- * @function toggleUserAlertModal
- *
- */
-function toggleUserAlertModal() {
- let modalDiv = document.getElementById(modalId);
- if (modalDiv) {
- modalDiv.classList.toggle('hidden');
- }
-}
-
/**
* Checks for the alert modal, and if it's not present builds and inserts it in the DOM
*
* @private
* @function buildModalDiv
*
- * @param {string} title The title/heading text to be displayed
* @param {string} text The body text to be displayed
* @param {string} confirm_text Text of the confirmation button
*
* @returns {Element} DOM node of the inserted alert modal
*/
-function buildModalDiv(title, text, confirm_text) {
+function buildModalDiv(text, confirm_text) {
let modalDiv = document.getElementById(modalId);
if (!modalDiv) {
- modalDiv = getModal(title, text, confirm_text);
+ modalDiv = getModal(text, confirm_text);
document.body.appendChild(modalDiv);
}
return modalDiv;
@@ -149,14 +114,13 @@ function buildModalDiv(title, text, confirm_text) {
* @private
* @function getModal
*
- * @param {string} title The title/heading text to be displayed
* @param {string} text The body text to be displayed
* @param {string} confirm_text Text of the confirmation button
*
* @returns {Element} DOM node of alert modal with formatted text
*/
-function getModal(title, text, confirm_text) {
+function getModal(text, confirm_text) {
let wrapper = document.createElement('div');
- wrapper.innerHTML = getModalHtml(title, text, confirm_text);
- return wrapper.firstChild;
+ wrapper.innerHTML = getModalHtml(text, confirm_text);
+ return wrapper;
}
diff --git a/app/javascript/crayons/Modal/Modal.jsx b/app/javascript/crayons/Modal/Modal.jsx
index 24e48238a..040cf44b1 100644
--- a/app/javascript/crayons/Modal/Modal.jsx
+++ b/app/javascript/crayons/Modal/Modal.jsx
@@ -33,19 +33,50 @@ const CloseIcon = () => (
);
+/**
+ * A modal component which can be presented with or without an overlay.
+ * The modal is presented within a focus trap for accessibility purposes - please note that the selector used for the focusTrap must be unique on the given page, otherwise focus may be trapped on the wrong element.
+ *
+ * @param {Object} props
+ * @param {Array} props.children The content to be displayed inside the Modal. Can be provided by composition (see example).
+ * @param {string} props.size The desired modal size ('s', 'm' or 'default')
+ * @param {string} props.className Optional additional classnames to apply to the modal container
+ * @param {string} props.title The title to be displayed in the modal heading. If provided, a title bar with a close button will be displayed.
+ * @param {boolean} props.overlay Whether or not to show a semi-opaque overlay behind the modal
+ * @param {Function} props.onClose Callback for any function to be executed on close button click or Escape
+ * @param {boolean} props.closeOnClickOutside Whether the modal should close if the user clicks outside of it
+ * @param {string} props.focusTrapSelector The CSS selector for where to trap the user's focus. This should be unique to the page in which the modal is presented.
+ *
+ * @example
+ *
+