Extract a StimulusJS modal_controller

+ make `help_modal_link_controller` inherit from it
This commit is contained in:
Jean-Baptiste Bellet
2022-10-17 14:49:08 +02:00
parent c3805b8187
commit 2fde3abe37
2 changed files with 22 additions and 12 deletions

View File

@@ -1,15 +1,7 @@
import { Controller } from "stimulus";
import ModalLinkController from "./modal_link_controller";
export default class extends Controller {
static values = { target: String };
open() {
let helpModal = document.getElementById(this.targetValue);
let helpModalController =
this.application.getControllerForElementAndIdentifier(
helpModal,
"help-modal"
);
helpModalController.open();
export default class extends ModalLinkController {
getIdentifier() {
return "help-modal";
}
}

View File

@@ -0,0 +1,18 @@
import { Controller } from "stimulus";
export default class extends Controller {
static values = { target: String };
open() {
let modal = document.getElementById(this.targetValue);
let modalController = this.application.getControllerForElementAndIdentifier(
modal,
this.getIdentifier()
);
modalController.open();
}
getIdentifier() {
return "modal";
}
}