Skip to content

Commit

Permalink
Make confirmations work in tailwind theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed May 27, 2024
1 parent 545675b commit f9ea4eb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/components/tailwind/button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class ButtonComponent < ViewComponent::Base
# href is untyped to support passing objects or paths or arrays to construct urls from
sig do
params(tag: Symbol, size: String, type: Symbol, href: T.untyped, icon: T.nilable(Symbol),
open_in_new_tab: T::Boolean, name: T.nilable(String), disabled: T::Boolean).void
open_in_new_tab: T::Boolean, name: T.nilable(String), disabled: T::Boolean,
confirm: T.nilable(String)).void
end
def initialize(tag:, size:, type:, href: nil, icon: nil, open_in_new_tab: false, name: nil, disabled: false)
def initialize(tag:, size:, type:, href: nil, icon: nil, open_in_new_tab: false, name: nil, disabled: false,
confirm: nil)
super

classes = %w[font-semibold]
Expand Down Expand Up @@ -71,6 +73,8 @@ def initialize(tag:, size:, type:, href: nil, icon: nil, open_in_new_tab: false,

options[:disabled] = true if disabled

options["x-on:click"] = "if (!confirm('#{confirm}')) { $event.preventDefault(); }" if confirm

@options = T.let(options, T.nilable(T::Hash[Symbol, T.nilable(String)]))
@tag = tag
@href = href
Expand Down
2 changes: 1 addition & 1 deletion app/views/_tailwind/alerts_new/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
<%# TODO: #1768 Show an error of some sort if the last delivery was not successful %>
<%= pa_button_to "Delete this alert", [:profile, @alert],
method: :delete, type: :secondary, icon: :trash, form_class: "mt-8",
data: { confirm: "Are you sure you want to unsubscribe for email alerts for #{@alert.address}?" } %>
confirm: "Are you sure you want to unsubscribe for email alerts for #{@alert.address}?" %>
2 changes: 1 addition & 1 deletion app/views/_tailwind/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@

<%= pa_button_to "Close your account", registration_path(resource_name),
method: :delete, type: :secondary, icon: :trash, form_class: "mt-12",
data: { confirm: "This will permanently remove your account and can not be undone. Are you sure?" } %>
confirm: "This will permanently remove your account and can not be undone. Are you sure?" %>

0 comments on commit f9ea4eb

Please sign in to comment.