Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
82 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// app/javascript/controllers/dialog_controller.js | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="dialog" | ||
export default class extends Controller { | ||
static targets = ["modal", "frame"] | ||
|
||
connect() { | ||
this.modalTarget.addEventListener("close", this.enableBodyScroll.bind(this)) | ||
} | ||
|
||
disconnect() { | ||
this.modalTarget.removeEventListener("close", this.enableBodyScroll.bind(this)) | ||
} | ||
|
||
// hide modal on successful form submission | ||
// data-action="turbo:submit-end->turbo-modal#submitEnd" | ||
submitEnd(e) { | ||
if (e.detail.success) { | ||
// console.log(e.detail.success) | ||
this.close() | ||
} | ||
} | ||
|
||
open() { | ||
// this.modalTarget.show() | ||
this.modalTarget.showModal() | ||
document.body.classList.add('overflow-hidden') | ||
} | ||
|
||
close() { | ||
this.modalTarget.close() | ||
// document.body.classList.remove('overflow-hidden') | ||
this.frameTarget.removeAttribute("src") | ||
this.frameTarget.innerHTML = "" | ||
} | ||
|
||
enableBodyScroll() { | ||
document.body.classList.remove('overflow-hidden') | ||
} | ||
|
||
clickOutside(event) { | ||
if (event.target === this.modalTarget) { | ||
this.close() | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
<div class="mx-auto md:w-2/3 w-full"> | ||
<%= turbo_frame_tag :modal do %> | ||
<h1 class="font-bold text-4xl">Editing comment</h1> | ||
|
||
<%= render "form", comment: @comment %> | ||
<%= link_to "Show this comment", @comment, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
<%= link_to "Back to comments", comments_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> | ||
<% end %> |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<div class="mx-auto md:w-2/3 w-full"> | ||
<h1 class="font-bold text-4xl">New comment</h1> | ||
|
||
<%= render "form", comment: @comment %> | ||
<%= link_to "Back to comments", comments_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> | ||
</div> | ||
<%= turbo_frame_tag :modal do %> | ||
<div data-action="turbo:submit-end->dialog#submitEnd"> | ||
<h1 class="font-bold text-4xl">New comment</h1> | ||
<%= render "form", comment: @comment %> | ||
</div> | ||
<% end %> |
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