Skip to content

Commit 15c1eb7

Browse files
refactor(Avatar): remove support for sx prop (#6611)
Co-authored-by: Marie Lucca <francinelucca@github.com>
1 parent 913739d commit 15c1eb7

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

.changeset/seven-cameras-act.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@primer/react': major
3+
'@primer/styled-react': minor
4+
---
5+
6+
Update Avatar component to no longer support sx, add sx wrapper to @primer/styled-react

packages/react/src/Avatar/Avatar.stories.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,4 @@ Playground.argTypes = {
6262
disable: true,
6363
},
6464
},
65-
sx: {
66-
controls: false,
67-
table: {
68-
disable: true,
69-
},
70-
},
7165
}

packages/react/src/Avatar/Avatar.test.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {describe, expect, it} from 'vitest'
22
import {render, screen} from '@testing-library/react'
3-
import {Avatar} from '..'
4-
import {ThemeProvider} from '../ThemeProvider'
5-
import theme from '../theme'
3+
import Avatar from '../Avatar'
64

75
describe('Avatar', () => {
86
it('should support `className` on the outermost element', () => {
@@ -31,16 +29,6 @@ describe('Avatar', () => {
3129
expect(avatar).toHaveAttribute('src', 'primer.png')
3230
})
3331

34-
it('respects margin props', () => {
35-
render(
36-
<ThemeProvider theme={theme}>
37-
<Avatar src="primer.png" alt="" sx={{m: 2}} data-testid="avatar" />
38-
</ThemeProvider>,
39-
)
40-
const avatar = screen.getByTestId('avatar')
41-
expect(avatar).toHaveStyle(`margin: 8px`)
42-
})
43-
4432
it('should support the `style` prop without overriding internal styles', () => {
4533
render(
4634
<Avatar

packages/react/src/Avatar/Avatar.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {clsx} from 'clsx'
22
import React from 'react'
3-
import type {SxProp} from '../sx'
43
import type {ResponsiveValue} from '../hooks/useResponsiveValue'
54
import {isResponsiveValue} from '../hooks/useResponsiveValue'
6-
import {BoxWithFallback} from '../internal/components/BoxWithFallback'
75
import classes from './Avatar.module.css'
86

97
export const DEFAULT_AVATAR_SIZE = 20
@@ -19,11 +17,10 @@ export type AvatarProps = {
1917
alt?: string
2018
/** Additional class name. */
2119
className?: string
22-
} & SxProp &
23-
React.ComponentPropsWithoutRef<'img'>
20+
} & React.ComponentPropsWithoutRef<'img'>
2421

2522
const Avatar = React.forwardRef<HTMLImageElement, AvatarProps>(function Avatar(
26-
{alt = '', size = DEFAULT_AVATAR_SIZE, square = false, sx: sxProp, className, style, ...rest},
23+
{alt = '', size = DEFAULT_AVATAR_SIZE, square = false, className, style, ...rest},
2724
ref,
2825
) {
2926
const isResponsive = isResponsiveValue(size)
@@ -38,8 +35,7 @@ const Avatar = React.forwardRef<HTMLImageElement, AvatarProps>(function Avatar(
3835
}
3936

4037
return (
41-
<BoxWithFallback
42-
as="img"
38+
<img
4339
data-component="Avatar"
4440
className={clsx(className, classes.Avatar)}
4541
ref={ref}
@@ -56,7 +52,6 @@ const Avatar = React.forwardRef<HTMLImageElement, AvatarProps>(function Avatar(
5652
}
5753
: (cssSizeVars as React.CSSProperties)
5854
}
59-
sx={sxProp}
6055
{...rest}
6156
/>
6257
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {type AvatarProps as PrimerAvatarProps, Avatar as PrimerAvatar} from '@primer/react'
2+
import {forwardRef} from 'react'
3+
import type {StyledProps} from '../styled-props'
4+
import {Box} from './Box'
5+
6+
type AvatarProps = PrimerAvatarProps & StyledProps
7+
const Avatar = forwardRef<HTMLImageElement, AvatarProps>(function Avatar(props, ref) {
8+
return <Box as={PrimerAvatar} ref={ref} {...props} />
9+
})
10+
11+
export {Avatar}
12+
export type {AvatarProps}

packages/styled-react/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export {ActionList} from '@primer/react'
2-
export {Avatar} from '@primer/react'
32
export {Box, type BoxProps} from './components/Box'
43
export {Button} from '@primer/react'
54
export {Details} from '@primer/react'
@@ -21,6 +20,7 @@ export {useTheme} from '@primer/react'
2120

2221
export {ActionMenu} from './components/ActionMenu'
2322
export {Autocomplete, type AutocompleteOverlayProps} from './components/Autocomplete'
23+
export {Avatar, type AvatarProps} from './components/Avatar'
2424
export {Breadcrumbs, Breadcrumb, type BreadcrumbsProps, type BreadcrumbsItemProps} from './components/Breadcrumbs'
2525
export {Checkbox, type CheckboxProps} from './components/Checkbox'
2626
export {CheckboxGroup, type CheckboxGroupProps} from './components/CheckboxGroup'

0 commit comments

Comments
 (0)