Skip to content

Commit ccf3d94

Browse files
authored
add disable_expand to AvatarStack (#3740)
1 parent c9e7079 commit ccf3d94

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

.changeset/rotten-banks-speak.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/view-components': minor
3+
---
4+
5+
Add `disable_expand` param to AvatarStack for React component parity

app/components/primer/beta/avatar_stack.pcss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* stylelint-disable selector-max-specificity */
2+
/* The selector-max-specificity rule is disabled here because the nested selectors
3+
in AvatarStack require high specificity to properly override default styles and
4+
achieve the intended visual stacking. */
5+
16
/* AvatarStack */
27

38
/* Stacked avatars can be used to show who is participating in thread when
@@ -60,7 +65,7 @@
6065
}
6166
}
6267

63-
&:hover {
68+
&:hover:not([data-disable-expand]) {
6469
& .avatar {
6570
margin-right: var(--base-size-4);
6671
}
@@ -74,6 +79,10 @@
7479
display: none !important;
7580
}
7681
}
82+
83+
&[data-disable-expand] {
84+
position: relative;
85+
}
7786
}
7887

7988
.avatar.avatar-more {
@@ -110,7 +119,7 @@
110119
right: 0;
111120
flex-direction: row-reverse;
112121

113-
&:hover .avatar {
122+
&:hover:not([data-disable-expand]) .avatar {
114123
margin-right: 0;
115124
margin-left: var(--base-size-4);
116125
}

app/components/primer/beta/avatar_stack.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ class AvatarStack < Primer::Component
2222
# @param tag [Symbol] <%= one_of(Primer::Beta::AvatarStack::TAG_OPTIONS) %>
2323
# @param align [Symbol] <%= one_of(Primer::Beta::AvatarStack::ALIGN_OPTIONS) %>
2424
# @param tooltipped [Boolean] Whether to add a tooltip to the stack or not.
25+
# @param disable_expand [Boolean] Whether to disable the expand behavior on hover. If true, avatars will not expand.
2526
# @param body_arguments [Hash] Parameters to add to the Body. If `tooltipped` is set, has the same arguments as <%= link_to_component(Primer::Tooltip) %>.
2627
# The default tag is <%= pretty_value(Primer::Beta::AvatarStack::DEFAULT_BODY_TAG) %> but can be changed using `tag:`
2728
# to <%= one_of(Primer::Beta::AvatarStack::BODY_TAG_OPTIONS, lower: true) %>
2829
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
29-
def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_arguments: {}, **system_arguments)
30+
def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, disable_expand: false, body_arguments: {}, **system_arguments)
3031
@align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)
3132
@system_arguments = system_arguments
3233
@tooltipped = tooltipped
34+
@disable_expand = disable_expand
3335
@body_arguments = body_arguments
3436
@direction = @body_arguments[:direction]
3537

@@ -39,6 +41,7 @@ def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_a
3941
"AvatarStack-body",
4042
@body_arguments[:classes]
4143
)
44+
@body_arguments[:"data-disable-expand"] = true if @disable_expand
4245

4346
@system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
4447
@system_arguments[:classes] = class_names(

previews/primer/beta/avatar_stack_preview.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class AvatarStackPreview < ViewComponent::Preview
1111
# @param align select [["Left", left], ["Right", right]]
1212
# @param tooltipped toggle
1313
# @param tooltip_label text
14-
def playground(number_of_avatars: 1, tag: :div, align: :left, tooltipped: false, tooltip_label: "This is a tooltip!")
15-
render(Primer::Beta::AvatarStack.new(tag: tag, align: align, tooltipped: tooltipped, body_arguments: { label: tooltip_label })) do |component|
14+
# @param disable_expand toggle
15+
def playground(number_of_avatars: 1, tag: :div, align: :left, tooltipped: false, tooltip_label: "This is a tooltip!", disable_expand: false)
16+
render(Primer::Beta::AvatarStack.new(tag: tag, align: align, tooltipped: tooltipped, disable_expand: disable_expand, body_arguments: { label: tooltip_label })) do |component|
1617
Array.new(number_of_avatars&.to_i || 1) do
1718
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
1819
end
@@ -97,6 +98,17 @@ def with_tooltip
9798
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser", href: "primer.style")
9899
end
99100
end
101+
102+
# @label With disabled expand
103+
def with_disabled_expand
104+
render(Primer::Beta::AvatarStack.new(disable_expand: true)) do |component|
105+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
106+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
107+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
108+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
109+
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "@kittenuser")
110+
end
111+
end
100112
#
101113
# @!endgroup
102114
end

test/components/beta/avatar_stack_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,18 @@ def test_renders_three_plus_avatar_stack
109109
end
110110
end
111111
end
112+
113+
def test_renders_with_disable_expand
114+
render_inline(Primer::Beta::AvatarStack.new(disable_expand: true)) do |component|
115+
component.with_avatar(src: "Foo", alt: "Bar")
116+
component.with_avatar(src: "Foo", alt: "Bar")
117+
component.with_avatar(src: "Foo", alt: "Bar")
118+
end
119+
120+
assert_selector(".AvatarStack") do
121+
assert_selector(".AvatarStack-body[data-disable-expand]") do
122+
assert_selector("img.avatar", count: 3)
123+
end
124+
end
125+
end
112126
end

0 commit comments

Comments
 (0)