forked from primer/view_components
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow confirmation checkbox label customisation
Adds `confirmation_checkbox` slot to allow the caller to provide custom labels, including I18n strings.
- Loading branch information
Showing
7 changed files
with
79 additions
and
14 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
43 changes: 43 additions & 0 deletions
43
app/components/primer/open_project/danger_confirmation_dialog/confirmation_checkbox.rb
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,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
class DangerConfirmationDialog | ||
# This component is part of `Primer::OpenProject::DangerConfirmationDialog` | ||
# and should not be used as a standalone component. | ||
class ConfirmationCheckbox < Primer::Component | ||
|
||
# @param checkbox_id [String] The id of the checkbox input. | ||
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %> | ||
def initialize(checkbox_id: self.class.generate_id, **system_arguments) | ||
@system_arguments = deny_tag_argument(**system_arguments) | ||
@system_arguments[:tag] = :div | ||
@system_arguments[:classes] = class_names( | ||
system_arguments[:classes], | ||
"DangerConfirmationDialog-confirmationCheckbox" | ||
) | ||
|
||
@checkbox_arguments = {} | ||
@checkbox_arguments[:id] = checkbox_id | ||
@checkbox_arguments[:name] = "confirm_dangerous_action" | ||
@checkbox_arguments[:data] = { | ||
target: "danger-confirmation-dialog-form-helper.checkbox", | ||
action: "change:danger-confirmation-dialog-form-helper#toggle" | ||
} | ||
end | ||
|
||
def call | ||
render(Primer::BaseComponent.new(**@system_arguments)) do | ||
render(Primer::Alpha::CheckBox.new(**@checkbox_arguments.merge(label: trimmed_content))) | ||
end | ||
end | ||
|
||
private | ||
|
||
def before_render | ||
content | ||
end | ||
end | ||
end | ||
end | ||
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
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