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

Add :primary and :secondary scheme to IconButton and Match scheme for ButtonGroup menu #2707

Merged
merged 9 commits into from
Mar 20, 2024
5 changes: 5 additions & 0 deletions .changeset/angry-files-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

Add `:primary` and `:secondary` scheme to IconButton and Match scheme for ButtonGroup menu
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.
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.
8 changes: 8 additions & 0 deletions app/components/primer/beta/button.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ summary.Button {
border-color: var(--button-primary-borderColor-rest);
box-shadow: var(--shadow-resting-small, var(--color-btn-primary-shadow));

&.Button--iconOnly {
color: var(--button-primary-iconColor-rest);
}

&:hover:not(:disabled, .Button--inactive) {
background-color: var(--button-primary-bgColor-hover);
border-color: var(--button-primary-borderColor-hover);
Expand Down Expand Up @@ -316,6 +320,10 @@ summary.Button {
border-color: var(--button-danger-borderColor-rest);
box-shadow: var(--button-default-shadow-resting), var(--button-default-shadow-inset);

&.Button--iconOnly {
color: var(--button-danger-iconColor-rest);
}

&:hover:not(:disabled, .Button--inactive) {
color: var(--button-danger-fgColor-hover);
fill: var(--button-danger-fgColor-hover);
Expand Down
6 changes: 4 additions & 2 deletions app/components/primer/beta/button_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ class ButtonGroup < Primer::Component
},

menu_button: {
renders: lambda { |**system_arguments|
MenuButton.new(**system_arguments)
renders: lambda { |menu_arguments: {}, button_arguments: {}|
button_arguments[:size] = @size
button_arguments[:scheme] = @scheme
MenuButton.new(menu_arguments: menu_arguments, button_arguments: button_arguments)
},

as: :menu_button
Expand Down
2 changes: 2 additions & 0 deletions app/components/primer/beta/icon_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class IconButton < Primer::Component
DEFAULT_SCHEME = :default
SCHEME_MAPPINGS = {
DEFAULT_SCHEME => "Button--secondary",
:primary => "Button--primary",
:secondary => "Button--secondary",
:danger => "Button--danger",
:invisible => "Button--invisible"
}.freeze
Expand Down
8 changes: 7 additions & 1 deletion previews/primer/beta/button_group_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ def split_button(size: :medium)

# @label With menu button
#
# @param scheme [Symbol] select [default, primary, secondary, danger, invisible]
# @param size [Symbol] select [medium, small]
# @snapshot
def with_menu_button
def with_menu_button(scheme: :default, size: :medium)
render_with_template(locals: {
scheme: scheme,
size: size
})
end

# @label Icon buttons
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render(Primer::Beta::ButtonGroup.new) do |component| %>
<%= render(Primer::Beta::ButtonGroup.new(scheme: scheme, size: size)) do |component| %>
<% component.with_button { "Main menu" } %>
<% component.with_menu_button(button_arguments: { "aria-label": "secondary menu" }, menu_arguments: { anchor_align: :end }) do |menu, button| %>
<% menu.with_item(label: "Item 1", item_id: :item1) %>
Expand Down
25 changes: 25 additions & 0 deletions previews/primer/beta/icon_button_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,31 @@ def invisible(
))
end

# @label Primary
# @param size select [small, medium, large]
# @param aria_label text
# @param disabled toggle
# @param tag select [a, summary, button]
# @snapshot
def primary(
size: :medium,
id: "button-preview",
tag: :button,
disabled: false,
icon: :x,
aria_label: "Button"
)
render(Primer::Beta::IconButton.new(
scheme: :primary,
size: size,
id: id,
tag: tag,
disabled: disabled,
icon: icon,
"aria-label": aria_label
))
end

# @label Danger
# @param size select [small, medium, large]
# @param aria_label text
Expand Down
4 changes: 2 additions & 2 deletions test/performance/bench_octicons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setup
def bench_allocations_without_cache
Primer::Beta::Octicon.new(**@options)
Primer::Octicon::Cache.clear!
assert_allocations "3.2" => 28, "3.1" => 29, "3.0" => 29, "2.7" => 30 do
assert_allocations "3.2" => 26, "3.1" => 27, "3.0" => 27 do
Primer::Beta::Octicon.new(**@options)
end
ensure
Expand All @@ -26,7 +26,7 @@ def bench_allocations_without_cache

def bench_allocations_with_cache
Primer::Octicon::Cache.preload!
assert_allocations "3.2" => 10, "3.1" => 10, "3.0" => 10, "2.7" => 12 do
assert_allocations "3.2" => 10, "3.1" => 10, "3.0" => 10 do
Primer::Beta::Octicon.new(**@options)
end
end
Expand Down
Loading