diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index db5c27b2..3e01dea3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,6 +11,13 @@ module ApplicationHelper name.underscore end + def notification(text, **options, &block) + content = tag.p(text) + content = capture &block if block_given? + + render partial: "shared/notification", locals: { type: options[:type], content: content } + end + # Wrap view with <%= modal do %> ... <% end %> to have it open in a modal # Make sure to add data-turbo-frame="modal" to the link/button that opens the modal def modal(&block) diff --git a/app/javascript/controllers/element_removal_controller.js b/app/javascript/controllers/element_removal_controller.js new file mode 100644 index 00000000..b14906a9 --- /dev/null +++ b/app/javascript/controllers/element_removal_controller.js @@ -0,0 +1,9 @@ +import { Controller } from '@hotwired/stimulus' + +// Connects to data-controller="element-removal" +export default class extends Controller { + remove() { + this.element.remove() + } +} + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 503af69a..780e9bf8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -24,6 +24,9 @@
+ + <%= safe_join(flash.map { |type, message| notification(message, type: type) }) %> +