Skip to content

Commit 2e5c601

Browse files
jonrohanjoshblack
andauthored
bugfix(Spinner): Spinner component size get's large when passing sx and size props (#5236)
* Bug fix styled spinner * Also pass along className * Create forty-rats-jog.md * Update .changeset/forty-rats-jog.md Co-authored-by: Josh Black <[email protected]> * Update packages/react/src/Spinner/Spinner.dev.stories.tsx Co-authored-by: Josh Black <[email protected]> --------- Co-authored-by: Josh Black <[email protected]>
1 parent e1993f1 commit 2e5c601

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.changeset/forty-rats-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Update Spinner component to correctly use the `size` prop when both `sx` and `size` are provided

packages/react/src/Spinner/Spinner.dev.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export default {
77
component: Spinner,
88
} as Meta<typeof Spinner>
99

10-
export const Default = () => <Spinner sx={{border: '1px solid red'}} />
10+
export const Default = () => <Spinner sx={{border: '1px solid red'}} size="small" />

packages/react/src/Spinner/Spinner.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {HTMLDataAttributes} from '../internal/internal-types'
66
import {useId} from '../hooks'
77
import {useFeatureFlag} from '../FeatureFlags'
88
import classes from './Spinner.module.css'
9-
import Box from '../Box'
9+
import {clsx} from 'clsx'
1010

1111
const sizeMap = {
1212
small: '16px',
@@ -87,17 +87,21 @@ const StyledComponentSpinner = styled(Spinner)`
8787
${sx}
8888
`
8989

90-
function StyledSpinner({sx, ...props}: SpinnerProps) {
90+
const StyledBaseSpinner = styled.div`
91+
${sx}
92+
`
93+
94+
function StyledSpinner({sx, className, ...props}: SpinnerProps) {
9195
const enabled = useFeatureFlag('primer_react_css_modules_team')
9296
if (enabled) {
9397
if (sx) {
94-
return <Box sx={sx} as={Spinner} className={classes.SpinnerAnimation} {...props} />
98+
return <StyledBaseSpinner sx={sx} as={Spinner} className={clsx(className, classes.SpinnerAnimation)} {...props} />
9599
}
96100

97-
return <Spinner className={classes.SpinnerAnimation} {...props} />
101+
return <Spinner className={clsx(className, classes.SpinnerAnimation)} {...props} />
98102
}
99103

100-
return <StyledComponentSpinner sx={sx} {...props} />
104+
return <StyledComponentSpinner sx={sx} className={className} {...props} />
101105
}
102106

103107
StyledSpinner.displayName = 'Spinner'

0 commit comments

Comments
 (0)