Skip to content

Commit 3cf8fe4

Browse files
authored
Allow custom texts for Cancel and Confirm buttons in DangerConfirmationDialog (#232)
1 parent 0592b35 commit 3cf8fe4

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

.changeset/itchy-lions-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openproject/primer-view-components': patch
3+
---
4+
5+
Allow custom texts for cancel and confirm button in DangerConfirmationDialog

app/components/primer/open_project/danger_confirmation_dialog.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<% end %>
1212
</scrollable-region>
1313
<%= render(Primer::Alpha::Dialog::Footer.new(show_divider: false)) do %>
14-
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": dialog_id })) { I18n.t("button_cancel") } %>
15-
<%= render(Primer::Beta::Button.new(type: (@form_wrapper.shows_form? ? :submit : :button), scheme: :danger, data: { "submit-dialog-id": dialog_id })) { I18n.t("button_delete_permanently") } %>
14+
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": dialog_id })) { @cancel_button_text } %>
15+
<%= render(Primer::Beta::Button.new(type: (@form_wrapper.shows_form? ? :submit : :button), scheme: :danger, data: { "submit-dialog-id": dialog_id })) { @confirm_button_text } %>
1616
<% end %>
1717
<% end %>
1818
</danger-confirmation-dialog-form-helper>

app/components/primer/open_project/danger_confirmation_dialog.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,17 @@ class DangerConfirmationDialog < Primer::Component
6767
def initialize(
6868
form_arguments: {},
6969
id: self.class.generate_id,
70+
confirm_button_text: I18n.t("button_delete_permanently"),
71+
cancel_button_text: I18n.t("button_cancel"),
7072
**system_arguments
7173
)
7274
@check_box_name = form_arguments.delete(:name) || "confirm_dangerous_action"
7375
@form_wrapper = FormWrapper.new(**form_arguments)
7476
@dialog_id = id.to_s
7577

78+
@confirm_button_text = confirm_button_text
79+
@cancel_button_text = cancel_button_text
80+
7681
@system_arguments = system_arguments
7782
@system_arguments[:id] = @dialog_id
7883
@system_arguments[:classes] = class_names(

previews/primer/open_project/danger_confirmation_dialog_preview.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,24 @@ def default
2525
# @param icon_color [Symbol] select [default, muted, subtle, accent, success, attention, severe, danger, open, closed, done, sponsors, on_emphasis, inherit]
2626
# @param show_description toggle
2727
# @param show_additional_details toggle
28+
# @param confirm_button_text [String]
29+
# @param cancel_button_text [String]
2830
# @param check_box_text [String]
2931
def playground(
3032
icon: :"alert",
3133
icon_color: :danger,
3234
show_description: true,
3335
show_additional_details: false,
36+
confirm_button_text: "Understood",
37+
cancel_button_text: "NO!",
3438
check_box_text: "I understand that this deletion cannot be reversed"
3539
)
3640
render_with_template(locals: { icon: icon,
3741
icon_color: icon_color,
3842
show_description: show_description,
3943
show_additional_details: show_additional_details,
44+
confirm_button_text: confirm_button_text,
45+
cancel_button_text: cancel_button_text,
4046
check_box_text: check_box_text })
4147
end
4248

previews/primer/open_project/danger_confirmation_dialog_preview/playground.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<%= render(Primer::OpenProject::DangerConfirmationDialog.new(id: "my-dialog")) do |dialog| %>
1+
<%= render(Primer::OpenProject::DangerConfirmationDialog.new(id: "my-dialog",
2+
confirm_button_text: confirm_button_text,
3+
cancel_button_text: cancel_button_text)) do |dialog| %>
24
<% dialog.with_show_button { "Click me" } %>
35
<% dialog.with_confirmation_message(icon_arguments: { icon: icon, color: icon_color }) do |message| %>
46
<% message.with_heading(tag: :h2).with_content("Proceed with danger?") %>

0 commit comments

Comments
 (0)