Skip to content

Commit

Permalink
Merge branch 'main' into kh-set-min-width-for-button
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 authored Apr 30, 2024
2 parents 8cd0454 + 811fac4 commit c546607
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 167 deletions.
5 changes: 0 additions & 5 deletions .changeset/wild-knives-notice.md

This file was deleted.

15 changes: 1 addition & 14 deletions app/components/primer/alpha/overlay.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,7 @@
<% if content.present? %>
<%= content %>
<% else %>
<% if bodies.size > 1 %>
<%= render(Primer::Alpha::TabPanels.new(label: "label", wrapper_arguments: { classes: "Overlay-tabPanels" })) do |component| %>
<% bodies.each do |body| %>
<% component.with_tab(**body.tab_arguments) do |tab| %>
<% tab.with_panel(classes: "Overlay-tabPanel") do %>
<%= body %>
<% end %>
<% tab.with_text { body.tab_label } %>
<% end %>
<% end %>
<% end %>
<% else %>
<%= bodies.first %>
<% end %>
<%= body %>
<%= footer %>
<% end %>
<% end %>
Expand Down
16 changes: 0 additions & 16 deletions app/components/primer/alpha/overlay.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,3 @@ anchored-position.not-anchored::backdrop, dialog::backdrop {
outline: solid 1px transparent;
}
}

.Overlay-tabPanels {
display: flex;
flex-direction: column;
overflow-y: hidden;

&::part(tablist-wrapper) {
margin: var(--base-size-8) 0;
padding: 0 var(--base-size-8);
}
}

.Overlay-tabPanel {
overflow: hidden;
display: flex;
}
14 changes: 2 additions & 12 deletions app/components/primer/alpha/overlay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ class Overlay < Primer::Component
}

# Required body content.
# when multiple bodies are passed, they will be rendered in a TabPanels component.
#
# @param padding [Symbol] The padding. <%= one_of(Primer::Alpha::Overlay::PADDING_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_many :bodies, lambda { |padding: @padding, **system_arguments|
renders_one :body, lambda { |padding: @padding, **system_arguments|
Primer::Alpha::Overlay::Body.new(
padding: padding,
**system_arguments
Expand Down Expand Up @@ -186,16 +185,7 @@ def before_render
@system_arguments[:aria][:label] = @title
end
end
if bodies?
if bodies.size > 1
# confirm all bodies have tab_label
bodies.each do |body|
raise ArgumentError, "Multiple with_body slots require `tab_label` to be passed." unless body.tab_label.present?
end
end
else
with_body
end
with_body unless body?
end

private
Expand Down
8 changes: 1 addition & 7 deletions app/components/primer/alpha/overlay/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@ class Overlay
# A `Overlay::Body` is a compositional component, used to render the
# Body of an overlay. See <%= link_to_component(Primer::Alpha::Overlay) %>.
class Body < Primer::Component

attr_reader :tab_arguments, :tab_label

# @param tab_arguments [Hash] Arguments passed to TabPanels component
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(padding: DEFAULT_PADDING, tab_label: nil, tab_arguments: {}, **system_arguments)
def initialize(padding: DEFAULT_PADDING, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"Overlay-body",
PADDING_MAPPINGS[fetch_or_fallback(PADDING_OPTIONS, padding, DEFAULT_PADDING)],
system_arguments[:classes]
)
@tab_arguments = tab_arguments
@tab_label = tab_label
end

def call
Expand Down
2 changes: 1 addition & 1 deletion app/components/primer/alpha/tab_panels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TabPanels < Primer::Component
# @param id [String] Unique ID of tab.
# @param selected [Boolean] Whether the tab is selected.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_many :tabs, lambda { |id: self.class.generate_id, selected: false, **system_arguments|
renders_many :tabs, lambda { |id:, selected: false, **system_arguments|
system_arguments[:id] = id
system_arguments[:classes] = tab_nav_tab_classes(system_arguments[:classes])

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions previews/primer/alpha/overlay_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ def overlay_with_header_subtitle
end
end

def overlay_with_three_bodies
render_with_template(locals: {})
end

def in_a_sticky_container
render_with_template(locals: {})
end
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions static/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -1866,12 +1866,6 @@
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/alpha/overlay/body.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/alpha/overlay/body/default/",
"parameters": [
{
"name": "tab_arguments",
"type": "Hash",
"default": "`{}`",
"description": "Arguments passed to TabPanels component"
},
{
"name": "system_arguments",
"type": "Hash",
Expand Down
6 changes: 0 additions & 6 deletions static/classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,6 @@
"Overlay-headerFilter": [
"Primer::Alpha::Dialog"
],
"Overlay-tabPanel": [
"Primer::Alpha::Overlay"
],
"Overlay-tabPanels": [
"Primer::Alpha::Overlay"
],
"Popover": [
"Primer::Beta::Popover"
],
Expand Down
36 changes: 2 additions & 34 deletions static/info_arch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6000,8 +6000,8 @@
]
},
{
"name": "bodies",
"description": "Required body content.\nwhen multiple bodies are passed, they will be rendered in a TabPanels component.",
"name": "body",
"description": "Required body content.",
"parameters": [
{
"name": "padding",
Expand Down Expand Up @@ -6157,19 +6157,6 @@
]
}
},
{
"preview_path": "primer/alpha/overlay/overlay_with_three_bodies",
"name": "overlay_with_three_bodies",
"snapshot": "false",
"skip_rules": {
"wont_fix": [
"region"
],
"will_fix": [
"color-contrast"
]
}
},
{
"preview_path": "primer/alpha/overlay/in_a_sticky_container",
"name": "in_a_sticky_container",
Expand Down Expand Up @@ -6338,12 +6325,6 @@
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/alpha/overlay/body.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/alpha/overlay/body/default/",
"parameters": [
{
"name": "tab_arguments",
"type": "Hash",
"default": "`{}`",
"description": "Arguments passed to TabPanels component"
},
{
"name": "system_arguments",
"type": "Hash",
Expand All @@ -6355,20 +6336,7 @@

],
"methods": [
{
"name": "tab_arguments",
"description": "Returns the value of attribute tab_arguments.",
"parameters": [

]
},
{
"name": "tab_label",
"description": "Returns the value of attribute tab_label.",
"parameters": [

]
}
],
"previews": [

Expand Down
13 changes: 0 additions & 13 deletions static/previews.json
Original file line number Diff line number Diff line change
Expand Up @@ -4979,19 +4979,6 @@
]
}
},
{
"preview_path": "primer/alpha/overlay/overlay_with_three_bodies",
"name": "overlay_with_three_bodies",
"snapshot": "false",
"skip_rules": {
"wont_fix": [
"region"
],
"will_fix": [
"color-contrast"
]
}
},
{
"preview_path": "primer/alpha/overlay/in_a_sticky_container",
"name": "in_a_sticky_container",
Expand Down
25 changes: 0 additions & 25 deletions test/components/primer/alpha/overlay_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,4 @@ def test_renders_header_subtitle

assert_selector(".Overlay-header .Overlay-description")
end

def test_renders_multiple_bodies_as_tabpanels
render_inline(Primer::Alpha::Overlay.new(title: "Title", role: :dialog)) do |component|
component.with_header
component.with_body(tab_label: "Tab 1") { "Hello" }
component.with_body(tab_label: "Tab 2") { "Hello" }
end

assert_selector("tab-container.Overlay-tabPanels") do
assert_selector(".tabnav-tab", count: 2)
assert_selector(".Overlay-tabPanel", count: 2, visible: :all)
end
end

def test_raises_argument_error_when_tab_label_is_missing
error = assert_raises(ArgumentError) do
render_inline(Primer::Alpha::Overlay.new(title: "Title", role: :dialog)) do |component|
component.with_header
component.with_body { "Hello" }
component.with_body { "Hello" }
end
end

assert_includes(error.message, "Multiple with_body slots require `tab_label` to be passed.")
end
end

0 comments on commit c546607

Please sign in to comment.