-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into 30-proxy-static-pages
- Loading branch information
Showing
7 changed files
with
239 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static targets = ["modal"]; | ||
static values = { | ||
modalId: String, | ||
}; | ||
|
||
open(event) { | ||
const modalId = event.currentTarget.dataset.modalTargetId; | ||
const modal = this.modalTargets.find((modal) => modal.id === modalId); | ||
|
||
this.openEvent = event; | ||
|
||
event.preventDefault(); | ||
|
||
if (modal) { | ||
modal.showModal(); | ||
} else { | ||
console.warn(`Modal with ID '${modalId}' not found.`); | ||
} | ||
} | ||
|
||
confirm(event) { | ||
const modal = this._getModal(event); | ||
|
||
if (modal) { | ||
const confirmRedirect = modal.dataset.modalConfirmRedirect; | ||
const confirmAction = modal.dataset.modalConfirmAction; | ||
|
||
if (confirmRedirect) { | ||
window.location.href = confirmRedirect; | ||
} else if (confirmAction) { | ||
this.invokeAction(confirmAction); | ||
modal.close(); | ||
} else { | ||
modal.close(); | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
cancel(event) { | ||
const modal = this._getModal(event); | ||
|
||
if (modal) { | ||
const cancelRedirect = modal.dataset.modalCancelRedirect; | ||
const cancelAction = modal.dataset.modalCancelAction; | ||
|
||
if (cancelRedirect) { | ||
window.location.href = cancelRedirect; | ||
} else if (cancelAction) { | ||
this.invokeAction(cancelAction); | ||
modal.close(); | ||
} else { | ||
modal.close(); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
_getModal(event) { | ||
return event.currentTarget.closest("dialog"); | ||
} | ||
|
||
invokeAction(actionName) { | ||
const [controllerName, action] = actionName.split("#"); | ||
const controllerElement = document.querySelector( | ||
`[data-controller~="${controllerName}"]` | ||
); | ||
|
||
if (!controllerElement) { | ||
console.warn(`Controller element for ${controllerName} not found.`); | ||
} | ||
|
||
const controller = this.application.getControllerForElementAndIdentifier( | ||
controllerElement, | ||
controllerName | ||
); | ||
|
||
if (controller && typeof controller[action] === "function") { | ||
controller[action](this.openEvent); | ||
} else { | ||
console.warn(`Action ${actionName} not found on ${controllerName}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<dialog | ||
id="<%= id %>" | ||
class="border-width-0 radius-lg" | ||
aria-labelledby=<%= "#{id}-heading" %> | ||
aria-describedby=<%= "#{id}-description" %> | ||
data-modal-target="modal" | ||
data-modal-confirm-redirect="<%= defined?(confirm_redirect) ? confirm_redirect : '' %>" | ||
data-modal-cancel-redirect="<%= defined?(cancel_redirect) ? cancel_redirect : '' %>" | ||
data-modal-confirm-action="<%= defined?(confirm_action) ? confirm_action : '' %>" | ||
data-modal-cancel-action="<%= defined?(cancel_action) ? cancel_action : '' %>" | ||
> | ||
<div class="usa-modal__content"> | ||
<div class="usa-modal__main"> | ||
<h2 class="usa-modal__heading" id=<%= "#{id}-heading" %>> | ||
<%= heading %> | ||
</h2> | ||
<div class="usa-prose"> | ||
<p id=<%= "#{id}-description" %>> | ||
<%= description %> | ||
</p> | ||
</div> | ||
<div class="usa-modal__footer"> | ||
<button id="modal-btn-confirm" class="usa-button" type="button" data-action="modal#confirm"><%= confirm_text %></button> | ||
<button id="modal-btn-cancel" class="usa-button--unstyled" type="button" data-action="modal#cancel"><%= cancel_text %></button> | ||
</div> | ||
</div> | ||
</div> | ||
</dialog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters