Skip to content
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

Update ButtonGroup to use Beta::Button #2013

Merged
merged 21 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
5 changes: 5 additions & 0 deletions .changeset/forty-jokes-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

Update `ButtonGroup` to use `Beta::Button`
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions app/components/primer/beta/button_group.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.ButtonGroup {
display: inline-flex;

& button {
margin-inline-end: -1px;
position: relative;
border-radius: 0;

&:focus,
&:active,
&:hover {
z-index: 1;
}
}

& > :first-child,
& > :first-child.Button-withTooltip button {
border-top-left-radius: var(--borderRadius-medium, 6px);
border-bottom-left-radius: var(--borderRadius-medium, 6px);
}

& > :last-child,
& > :last-child.Button-withTooltip button {
border-top-right-radius: var(--borderRadius-medium, 6px);
border-bottom-right-radius: var(--borderRadius-medium, 6px);
}

}
38 changes: 19 additions & 19 deletions app/components/primer/beta/button_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,45 @@ class ButtonGroup < Primer::Component

# Required list of buttons to be rendered.
#
# @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::ButtonComponent) %> except for `size` and `group_item`.
# @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::Beta::Button) %>
renders_many :buttons, lambda { |**kwargs|
kwargs[:group_item] = true
kwargs[:size] = @size
kwargs[:scheme] = @scheme

# rubocop:disable Primer/ComponentNameMigration
Primer::ButtonComponent.new(**kwargs)
# rubocop:enable Primer/ComponentNameMigration
if kwargs[:icon]
Primer::Beta::IconButton.new(**kwargs)
else
Primer::Beta::Button.new(**kwargs)
end
}

# @example Default
#
# <%= render(Primer::Beta::ButtonGroup.new) do |component| %>
# <% component.with_button { "Default" } %>
# <% component.with_button(scheme: :primary) { "Primary" } %>
# <% component.with_button(scheme: :danger) { "Danger" } %>
# <% component.with_button(scheme: :outline) { "Outline" } %>
# <% component.with_button(classes: "custom-class") { "Custom class" } %>
# <% component.with_button { "Button 1" } %>
# <% component.with_button { "Button 2" } %>
# <% component.with_button { "Button 3" } %>
# <% end %>
#
# @example Sizes
#
# <%= render(Primer::Beta::ButtonGroup.new(size: :small)) do |component| %>
# <% component.with_button { "Default" } %>
# <% component.with_button(scheme: :primary) { "Primary" } %>
# <% component.with_button(scheme: :danger) { "Danger" } %>
# <% component.with_button(scheme: :outline) { "Outline" } %>
# <% component.with_button { "Button 1" } %>
# <% component.with_button { "Button 2" } %>
# <% component.with_button { "Button 3" } %>
# <% end %>
#
# @param variant [Symbol] DEPRECATED. <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
# @param size [Symbol] <%= one_of(Primer::ButtonComponent::SIZE_OPTIONS) %>
# @param scheme [Symbol] DEPRECATED. <%= one_of(Primer::Beta::Button::SCHEME_OPTIONS) %>
# @param size [Symbol] <%= one_of(Primer::Beta::Button::SIZE_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(variant: nil, size: Primer::ButtonComponent::DEFAULT_SIZE, **system_arguments)
@size = variant || size
def initialize(scheme: Primer::Beta::Button::DEFAULT_SCHEME, size: Primer::Beta::Button::DEFAULT_SIZE, **system_arguments)
@size = size
@scheme = scheme
Comment on lines +43 to +44
Copy link
Member

@jonrohan jonrohan May 15, 2023

Choose a reason for hiding this comment

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

You might want to use fetch or fallback here and the Button scheme and size options

Just thinking out loud maybe not since the button will take care of that anyway. Never mind

@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div

@system_arguments[:classes] = class_names(
"BtnGroup",
"ButtonGroup",
system_arguments[:classes]
)
end
Expand Down
1 change: 1 addition & 0 deletions app/components/primer/primer.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@import "./alpha/overlay.pcss";
@import "./beta/breadcrumbs.pcss";
@import "./beta/button.pcss";
@import "./beta/button_group.pcss";
@import "./beta/counter.pcss";
@import "./beta/flash.pcss";
@import "./beta/label.pcss";
Expand Down
42 changes: 31 additions & 11 deletions previews/primer/beta/button_group_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ module Beta
class ButtonGroupPreview < ViewComponent::Preview
# @label Playground
#
# @param size [Symbol] select [medium, small]
def playground(size: :medium)
render(Primer::Beta::ButtonGroup.new(size: size)) do |component|
component.with_button { "Button" }
component.with_button(scheme: :primary) { "Primary" }
component.with_button(scheme: :danger) { "Danger" }
component.with_button(scheme: :outline) { "Outline" }
# @param size [Symbol] select [small, medium, large]
# @param scheme [Symbol] select [default, primary, secondary, danger, invisible]
def playground(size: :medium, scheme: :default)
render(Primer::Beta::ButtonGroup.new(size: size, scheme: scheme)) do |component|
component.with_button { "Button 1" }
component.with_button { "Button 2" }
component.with_button { "Button 3" }
end
end

Expand All @@ -21,10 +21,30 @@ def playground(size: :medium)
# @param size [Symbol] select [medium, small]
def default(size: :medium)
render(Primer::Beta::ButtonGroup.new(size: size)) do |component|
component.with_button { "Button" }
component.with_button(scheme: :primary) { "Primary" }
component.with_button(scheme: :danger) { "Danger" }
component.with_button(scheme: :outline) { "Outline" }
component.with_button { "Button 1" }
component.with_button { "Button 2" }
component.with_button { "Button 3" }
end
end

# @label Split button
#
# @param size [Symbol] select [medium, small]
def split_button(size: :medium)
render(Primer::Beta::ButtonGroup.new(size: size)) do |component|
component.with_button { "Button 1" }
component.with_button(icon: "triangle-down", "aria-label": "menu")
end
end

# @label Icon buttons
#
# @param size [Symbol] select [medium, small]
def icon_buttons(size: :medium)
render(Primer::Beta::ButtonGroup.new(size: size)) do |component|
component.with_button(icon: :note, "aria-label": "button 1")
component.with_button(icon: :rows, "aria-label": "button 2")
component.with_button(icon: "sort-desc", "aria-label": "button 3")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= render(Primer::Beta::ButtonGroup.new) do |component| %>
<% component.with_button() { "Main menu" } %>
<% component.with_button(icon: "triangle-down", "aria-label": "secondary menu", data: { "menu-id": "my-id" }) %>
<% end %>

<%= render(Primer::Alpha::ActionMenu.new(anchor_align: :end, menu_id: "my-id")) do |component| %>
<% component.with_item(label: "Item", tag: :button, value: "") %>
<% end %>
12 changes: 8 additions & 4 deletions static/classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"Box--danger": [
"Primer::Beta::BorderBox"
],
"ButtonGroup": [
"Primer::Beta::ButtonGroup",
"Primer::Beta::Button-group"
],
"Label--info": [
"Primer::Beta::Label"
],
Expand Down Expand Up @@ -375,10 +379,10 @@
"ActionListWrap--inset": [
"Primer::Alpha::ActionList"
],
"ActionListItem-action": [
"ActionListItem-visual": [
"Primer::Alpha::ActionList"
],
"ActionListItem-visual": [
"ActionListItem-action": [
"Primer::Alpha::ActionList"
],
"SegmentedControl-item": [
Expand Down Expand Up @@ -513,10 +517,10 @@
"FormControl-inlineValidation": [
"Primer::Alpha::TextField"
],
"FormControl-check-group-wrap": [
"FormControl-radio-group-wrap": [
"Primer::Alpha::TextField"
],
"FormControl-radio-group-wrap": [
"FormControl-check-group-wrap": [
"Primer::Alpha::TextField"
],
"Popover-message--bottom-left": [
Expand Down
36 changes: 19 additions & 17 deletions test/components/beta/button_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class PrimerBetaButtonGroupTest < Minitest::Test
def test_does_not_render_without_buttons
render_inline(Primer::Beta::ButtonGroup.new)

refute_selector("div.BtnGroup")
refute_selector("div.ButtonGroup")
end

def test_renders_button_items
render_inline(Primer::Beta::ButtonGroup.new) { |component| component.with_button { "Button" } }

assert_selector("div.BtnGroup") do
assert_selector("button.btn.BtnGroup-item", text: "Button")
assert_selector("div.ButtonGroup") do
assert_selector("button.Button--secondary.Button", text: "Button")
end
end

Expand All @@ -24,16 +24,14 @@ def test_renders_button_with_props
component.with_button { "Button" }
component.with_button(scheme: :primary) { "Primary" }
component.with_button(scheme: :danger) { "Danger" }
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to pass the scheme to ButtonGroup now

component.with_button(scheme: :outline) { "Outline" }
component.with_button(classes: "custom-class") { "Custom class" }
end

assert_selector("div.BtnGroup") do
assert_selector("button.btn.BtnGroup-item", text: "Button")
assert_selector("button.btn.BtnGroup-item.btn-primary", text: "Primary")
assert_selector("button.btn.BtnGroup-item.btn-danger", text: "Danger")
assert_selector("button.btn.BtnGroup-item.btn-outline", text: "Outline")
assert_selector("button.btn.BtnGroup-item.custom-class", text: "Custom class")
assert_selector("div.ButtonGroup") do
assert_selector("button.Button--secondary.Button", text: "Button")
assert_selector("button.Button--primary.Button", text: "Primary")
assert_selector("button.Button--danger.Button", text: "Danger")
assert_selector("button.custom-class", text: "Custom class")
end
end

Expand All @@ -46,20 +44,24 @@ def test_does_not_render_content
def test_all_buttons_with_same_size
render_inline(Primer::Beta::ButtonGroup.new(size: :small)) do |component|
component.with_button(size: :medium) { "Medium" }
component.with_button(size: :large) { "Large" }
end

assert_selector("div.BtnGroup") do
assert_selector("button.btn.BtnGroup-item.btn-sm", text: "Medium")
assert_selector("div.ButtonGroup") do
assert_selector("button.Button-small.Button", text: "Medium")
assert_selector("button.Button-small.Button", text: "Large")
end
end

def test_all_buttons_with_same_variant
render_inline(Primer::Beta::ButtonGroup.new(variant: :small)) do |component|
component.with_button(size: :medium) { "Medium" }
def test_all_buttons_with_same_scheme
render_inline(Primer::Beta::ButtonGroup.new(scheme: :primary)) do |component|
component.with_button(scheme: :primary) { "Primary" }
component.with_button(scheme: :danger) { "Danger" }
end

assert_selector("div.BtnGroup") do
assert_selector("button.btn.BtnGroup-item.btn-sm", text: "Medium")
assert_selector("div.ButtonGroup") do
assert_selector("button.Button--primary.Button", text: "Primary")
assert_selector("button.Button--primary.Button", text: "Danger")
end
end
end
2 changes: 1 addition & 1 deletion test/css/component_selector_use_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Primer::Alpha::ActionMenu => ["ActionListItem-multiSelectIcon", "copy-link", "quote-reply"],
Primer::Alpha::AutoComplete => ["form-control", "ActionList"],
Primer::Alpha::HiddenTextExpander => ["ellipsis-expander", "hidden-text-expander"],
Primer::Beta::ButtonGroup => ["BtnGroup", "BtnGroup-item"],
Primer::Beta::ButtonGroup => ["ButtonGroup"],
Primer::Beta::CloseButton => ["close-button"],
Primer::Beta::Details => ["details-overlay"],
Primer::Beta::Markdown => ["markdown-body"],
Expand Down
3 changes: 1 addition & 2 deletions test/css/component_specific_selectors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class ComponentSpecificSelectorsTest < Minitest::Test
".Button--iconOnly.Button--large"
],
Primer::Beta::ButtonGroup => [
".BtnGroup-item.btn.selected",
".BtnGroup-parent"
".ButtonGroup"
],
Primer::Beta::Avatar => [
".avatar-link",
Expand Down