Skip to content

Commit 3a41430

Browse files
hussam-i-amjonrohan
andauthoredJan 28, 2025··
feat(AvatarStack): add style prop (#5608)
* feat(AvatarStack): add style prop * add test --------- Co-authored-by: Jon Rohan <yes@jonrohan.codes>
1 parent 1614755 commit 3a41430

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎.changeset/nervous-planets-kneel.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
feat(AvatarStack): add style prop

‎packages/react/src/AvatarStack/AvatarStack.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export type AvatarStackProps = {
208208
size?: number | ResponsiveValue<number>
209209
className?: string
210210
children: React.ReactNode
211+
style?: React.CSSProperties
211212
} & SxProp
212213

213214
const AvatarStackBody = ({
@@ -254,6 +255,7 @@ const AvatarStack = ({
254255
disableExpand,
255256
size,
256257
className,
258+
style,
257259
sx: sxProp = defaultSxProp,
258260
}: AvatarStackProps) => {
259261
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
@@ -382,7 +384,7 @@ const AvatarStack = ({
382384
data-align-right={enabled && alignRight ? '' : undefined}
383385
data-responsive={enabled && (!size || isResponsiveValue(size)) ? '' : undefined}
384386
className={clsx(wrapperClassNames, {[classes.AvatarStack]: enabled})}
385-
style={enabled ? getResponsiveAvatarSizeStyles() : undefined}
387+
style={enabled ? {...getResponsiveAvatarSizeStyles(), style} : style}
386388
sx={avatarStackSx}
387389
>
388390
<AvatarStackBody

‎packages/react/src/__tests__/AvatarStack.test.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,15 @@ describe('Avatar', () => {
9393
)
9494
expect(container.querySelector('[tabindex="0"]')).not.toBeInTheDocument()
9595
})
96+
97+
it('should support `style` prop on the outermost element', () => {
98+
const style = {backgroundColor: 'red'}
99+
const {container} = HTMLRender(
100+
<AvatarStack style={style}>
101+
<img src="https://avatars.githubusercontent.com/primer" alt="" />
102+
<img src="https://avatars.githubusercontent.com/github" alt="" />
103+
</AvatarStack>,
104+
)
105+
expect(container.firstChild).toHaveStyle('background-color: red')
106+
})
96107
})

0 commit comments

Comments
 (0)
Please sign in to comment.