Skip to content

Commit 1c73539

Browse files
authored
Add :primary and :secondary scheme to IconButton and Match scheme for ButtonGroup menu (#2707)
1 parent 6ca210d commit 1c73539

File tree

12 files changed

+54
-6
lines changed

12 files changed

+54
-6
lines changed

.changeset/angry-files-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/view-components": patch
3+
---
4+
5+
Add `:primary` and `:secondary` scheme to IconButton and Match scheme for ButtonGroup menu
Loading
Loading

app/components/primer/beta/button.pcss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ summary.Button {
170170
border-color: var(--button-primary-borderColor-rest);
171171
box-shadow: var(--shadow-resting-small, var(--color-btn-primary-shadow));
172172

173+
&.Button--iconOnly {
174+
color: var(--button-primary-iconColor-rest);
175+
}
176+
173177
&:hover:not(:disabled, .Button--inactive) {
174178
background-color: var(--button-primary-bgColor-hover);
175179
border-color: var(--button-primary-borderColor-hover);
@@ -316,6 +320,10 @@ summary.Button {
316320
border-color: var(--button-danger-borderColor-rest);
317321
box-shadow: var(--button-default-shadow-resting), var(--button-default-shadow-inset);
318322

323+
&.Button--iconOnly {
324+
color: var(--button-danger-iconColor-rest);
325+
}
326+
319327
&:hover:not(:disabled, .Button--inactive) {
320328
color: var(--button-danger-fgColor-hover);
321329
fill: var(--button-danger-fgColor-hover);

app/components/primer/beta/button_group.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ class ButtonGroup < Primer::Component
4646
},
4747

4848
menu_button: {
49-
renders: lambda { |**system_arguments|
50-
MenuButton.new(**system_arguments)
49+
renders: lambda { |menu_arguments: {}, button_arguments: {}|
50+
button_arguments[:size] = @size
51+
button_arguments[:scheme] = @scheme
52+
MenuButton.new(menu_arguments: menu_arguments, button_arguments: button_arguments)
5153
},
5254

5355
as: :menu_button

app/components/primer/beta/icon_button.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class IconButton < Primer::Component
2020
DEFAULT_SCHEME = :default
2121
SCHEME_MAPPINGS = {
2222
DEFAULT_SCHEME => "Button--secondary",
23+
:primary => "Button--primary",
24+
:secondary => "Button--secondary",
2325
:danger => "Button--danger",
2426
:invisible => "Button--invisible"
2527
}.freeze

previews/primer/beta/button_group_preview.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ def split_button(size: :medium)
4141

4242
# @label With menu button
4343
#
44+
# @param scheme [Symbol] select [default, primary, secondary, danger, invisible]
45+
# @param size [Symbol] select [medium, small]
4446
# @snapshot
45-
def with_menu_button
47+
def with_menu_button(scheme: :default, size: :medium)
48+
render_with_template(locals: {
49+
scheme: scheme,
50+
size: size
51+
})
4652
end
4753

4854
# @label Icon buttons

previews/primer/beta/button_group_preview/with_menu_button.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= render(Primer::Beta::ButtonGroup.new) do |component| %>
1+
<%= render(Primer::Beta::ButtonGroup.new(scheme: scheme, size: size)) do |component| %>
22
<% component.with_button { "Main menu" } %>
33
<% component.with_menu_button(button_arguments: { "aria-label": "secondary menu" }, menu_arguments: { anchor_align: :end }) do |menu, button| %>
44
<% menu.with_item(label: "Item 1", item_id: :item1) %>

previews/primer/beta/icon_button_preview.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ def invisible(
8787
))
8888
end
8989

90+
# @label Primary
91+
# @param size select [small, medium, large]
92+
# @param aria_label text
93+
# @param disabled toggle
94+
# @param tag select [a, summary, button]
95+
# @snapshot
96+
def primary(
97+
size: :medium,
98+
id: "button-preview",
99+
tag: :button,
100+
disabled: false,
101+
icon: :x,
102+
aria_label: "Button"
103+
)
104+
render(Primer::Beta::IconButton.new(
105+
scheme: :primary,
106+
size: size,
107+
id: id,
108+
tag: tag,
109+
disabled: disabled,
110+
icon: icon,
111+
"aria-label": aria_label
112+
))
113+
end
114+
90115
# @label Danger
91116
# @param size select [small, medium, large]
92117
# @param aria_label text

test/performance/bench_octicons.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def setup
1717
def bench_allocations_without_cache
1818
Primer::Beta::Octicon.new(**@options)
1919
Primer::Octicon::Cache.clear!
20-
assert_allocations "3.2" => 28, "3.1" => 29, "3.0" => 29, "2.7" => 30 do
20+
assert_allocations "3.2" => 26, "3.1" => 27, "3.0" => 27 do
2121
Primer::Beta::Octicon.new(**@options)
2222
end
2323
ensure
@@ -26,7 +26,7 @@ def bench_allocations_without_cache
2626

2727
def bench_allocations_with_cache
2828
Primer::Octicon::Cache.preload!
29-
assert_allocations "3.2" => 10, "3.1" => 10, "3.0" => 10, "2.7" => 12 do
29+
assert_allocations "3.2" => 10, "3.1" => 10, "3.0" => 10 do
3030
Primer::Beta::Octicon.new(**@options)
3131
end
3232
end

0 commit comments

Comments
 (0)