Skip to content

Add Dialog::Header close_scheme, close_label params #3373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/components/primer/alpha/dialog/header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
<%= subtitle %>
<% end %>
</div>
<div class="Overlay-actionWrap">
<%= render Primer::Beta::CloseButton.new(classes: "Overlay-closeButton", "data-close-dialog-id": @id) %>
</div>
<% if @close_scheme != :none %>
<div class="Overlay-actionWrap">
<%= render(
Primer::Beta::CloseButton.new(
classes: "Overlay-closeButton",
aria: { label: @close_label },
data: { close_dialog_id: @id }
)
) %>
</div>
<% end %>
</div>
<%= filter %>
<% end %>
14 changes: 14 additions & 0 deletions app/components/primer/alpha/dialog/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class Header < Primer::Component
}.freeze
VARIANT_OPTIONS = VARIANT_MAPPINGS.keys

DEFAULT_CLOSE_SCHEME = :close
CLOSE_SCHEMES = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schemes are usually something like :danger, :primary and so on.. Since you want to achieve a boolean flag to hide and show the close button, it maybe makes sense to make that a boolean like show_close_button.

DEFAULT_CLOSE_SCHEME,
:none
].freeze

DEFAULT_CLOSE_LABEL = "Close"

# Optional filter slot for adding a filter input to the header.
#
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
Expand Down Expand Up @@ -48,6 +56,8 @@ class Header < Primer::Component
# @param show_divider [Boolean] Show a divider between the header and body.
# @param visually_hide_title [Boolean] Visually hide the `title` while maintaining a label for assistive technologies.
# @param variant [Symbol] <%= one_of(Primer::Alpha::Dialog::Header::VARIANT_OPTIONS) %>
# @param close_scheme [Symbol] Whether the component can be closed with an "x" button. <%= one_of(Primer::Alpha::Banner::CLOSE_SCHEMES) %>
# @param close_label [String] The aria-label text of the close "x" button.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(
id:,
Expand All @@ -56,12 +66,16 @@ def initialize(
show_divider: false,
visually_hide_title: false,
variant: DEFAULT_VARIANT,
close_scheme: DEFAULT_CLOSE_SCHEME,
close_label: DEFAULT_CLOSE_LABEL,
**system_arguments
)
@id = id
@title = title
@subtitle = subtitle
@visually_hide_title = visually_hide_title
@close_scheme = close_scheme
@close_label = close_label
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div

Expand Down
1 change: 1 addition & 0 deletions demo/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ GEM
PLATFORMS
arm64-darwin-21
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-19
x86_64-darwin-20
x86_64-darwin-21
Expand Down
32 changes: 32 additions & 0 deletions previews/primer/alpha/dialog_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,38 @@ def initally_open(title: "Test Dialog", subtitle: nil, size: :medium, button_tex
def with_header_filter
render_with_template(locals: {})
end

# @label With Header Close Button label
#
# @param title [String] text
# @param subtitle [String] text
# @param button_text [String] text
# @param show_divider [Boolean] toggle
# @param close_label [String] text
def with_header_close_button_label(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog", show_divider: true, close_label: "Close me!")
render_with_template(locals: {
title: title,
subtitle: subtitle,
button_text: button_text,
show_divider: show_divider,
close_label: close_label
})
end

# @label Without Header Close Button
#
# @param title [String] text
# @param subtitle [String] text
# @param button_text [String] text
# @param show_divider [Boolean] toggle
def without_header_close_button(title: "Test Dialog", subtitle: nil, button_text: "Show Dialog", show_divider: true)
render_with_template(locals: {
title: title,
subtitle: subtitle,
button_text: button_text,
show_divider: show_divider
})
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render(Primer::Alpha::Dialog.new(id: "my-dialog", title: title, subtitle: subtitle, visually_hide_title: false)) do |dialog| %>
<% dialog.with_header(show_divider: show_divider, close_label: close_label) %>
<% dialog.with_show_button_content(button_text) %>
<% dialog.with_body_content("Hello World") %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= render(Primer::Alpha::Dialog.new(id: "my-dialog", title: title, subtitle: subtitle, visually_hide_title: false)) do |dialog| %>
<% dialog.with_header(show_divider: show_divider, close_scheme: :none) %>
<% dialog.with_show_button_content(button_text) %>
<% dialog.with_body_content("Hello World") %>
<% dialog.with_footer do %>
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": "my-dialog" })) { "Close" } %>
<% end %>
<% end %>
28 changes: 28 additions & 0 deletions test/components/primer/alpha/dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@ def test_renders_header_subtitle
assert_selector(".Overlay-header .Overlay-description")
end

def test_renders_header_with_close_label
render_inline(Primer::Alpha::Dialog.new(title: "Title", id: "my-dialog")) do |component|
component.with_body { "content" }
component.with_header(close_label: "Close me!") { "header" }
end

assert_selector("dialog") do
assert_selector(".Overlay-header") do
assert_selector(".Overlay-actionWrap")
assert_selector("button[data-close-dialog-id][aria-label='Close me!']")
end
end
end

def test_renders_header_with_close_scheme_none
render_inline(Primer::Alpha::Dialog.new(title: "Title", id: "my-dialog")) do |component|
component.with_body { "content" }
component.with_header(close_scheme: :none) { "header" }
end

assert_selector("dialog") do
assert_selector(".Overlay-header") do
refute_selector(".Overlay-actionWrap")
refute_selector("button[data-close-dialog-id]")
end
end
end

def test_renders_header_with_filter
render_preview(:with_header_filter)

Expand Down
Loading