Skip to content

Commit

Permalink
Add a filter slot to the dialog header (#2804)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Apr 24, 2024
1 parent 797b904 commit 757635a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-pears-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": minor
---

Add a filter slot to the dialog header
1 change: 1 addition & 0 deletions app/components/primer/alpha/dialog/header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
<%= render Primer::Beta::CloseButton.new(classes: "Overlay-closeButton", "data-close-dialog-id": @id) %>
</div>
</div>
<%= filter %>
<% end %>
12 changes: 12 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,18 @@ class Header < Primer::Component
}.freeze
VARIANT_OPTIONS = VARIANT_MAPPINGS.keys

# Optional filter slot for adding a filter input to the header.
#
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :filter, lambda { |**system_arguments|
system_arguments[:tag] = :div
system_arguments[:classes] = class_names(
"Overlay-headerFilter",
system_arguments[:classes]
)
Primer::BaseComponent.new(**system_arguments)
}

# @param id [String] The HTML element's ID value.
# @param title [String] Describes the content of the dialog.
# @param subtitle [String] Provides additional context for the dialog, also setting the `aria-describedby` attribute.
Expand Down
4 changes: 4 additions & 0 deletions previews/primer/alpha/dialog_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ def initally_open(title: "Test Dialog", subtitle: nil, size: :medium, button_tex
d.with_body { body_text }
end
end

def with_header_filter
render_with_template(locals: {})
end
end
end
end
19 changes: 19 additions & 0 deletions previews/primer/alpha/dialog_preview/with_header_filter.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%= render(Primer::Alpha::Dialog.new(open: true, title: "Dialog")) do |dialog| %>
<% dialog.with_show_button { "Open" } %>
<% dialog.with_header do |header| %>
<% header.with_filter(pr: 3, pl: 3) do %>
<%= render Primer::Alpha::TextField.new(
autofocus: true,
visually_hide_label: true,
name: "filter",
label: "Filter dialog",
) %>
<% end %>
<% end %>
<% dialog.with_body do %>
Body
<% end %>
<% dialog.with_footer do %>
Footer
<% end %>
<% end %>
10 changes: 10 additions & 0 deletions test/components/primer/alpha/dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def test_renders_large_header
end
end

def test_renders_header_with_filter
render_preview(:with_header_filter)

assert_selector("dialog") do |dialog|
dialog.assert_selector(".Overlay-header") do |header|
header.assert_selector("input[type=text]")
end
end
end

def test_renders_footer_without_divider_by_default
render_inline(Primer::Alpha::Dialog.new(title: "Title", id: "my-dialog", subtitle: "Subtitle")) do |component|
component.with_body { "content" }
Expand Down

0 comments on commit 757635a

Please sign in to comment.