Skip to content

Commit

Permalink
bugfix(Spinner): Spinner component size get's large when passing sx a…
Browse files Browse the repository at this point in the history
…nd 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 <joshblack@github.com>

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

Co-authored-by: Josh Black <joshblack@github.com>

---------

Co-authored-by: Josh Black <joshblack@github.com>
  • Loading branch information
jonrohan and joshblack authored Nov 6, 2024
1 parent e1993f1 commit 2e5c601
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-rats-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Update Spinner component to correctly use the `size` prop when both `sx` and `size` are provided
2 changes: 1 addition & 1 deletion packages/react/src/Spinner/Spinner.dev.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default {
component: Spinner,
} as Meta<typeof Spinner>

export const Default = () => <Spinner sx={{border: '1px solid red'}} />
export const Default = () => <Spinner sx={{border: '1px solid red'}} size="small" />
14 changes: 9 additions & 5 deletions packages/react/src/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {HTMLDataAttributes} from '../internal/internal-types'
import {useId} from '../hooks'
import {useFeatureFlag} from '../FeatureFlags'
import classes from './Spinner.module.css'
import Box from '../Box'
import {clsx} from 'clsx'

const sizeMap = {
small: '16px',
Expand Down Expand Up @@ -87,17 +87,21 @@ const StyledComponentSpinner = styled(Spinner)`
${sx}
`

function StyledSpinner({sx, ...props}: SpinnerProps) {
const StyledBaseSpinner = styled.div`
${sx}
`

function StyledSpinner({sx, className, ...props}: SpinnerProps) {
const enabled = useFeatureFlag('primer_react_css_modules_team')
if (enabled) {
if (sx) {
return <Box sx={sx} as={Spinner} className={classes.SpinnerAnimation} {...props} />
return <StyledBaseSpinner sx={sx} as={Spinner} className={clsx(className, classes.SpinnerAnimation)} {...props} />
}

return <Spinner className={classes.SpinnerAnimation} {...props} />
return <Spinner className={clsx(className, classes.SpinnerAnimation)} {...props} />
}

return <StyledComponentSpinner sx={sx} {...props} />
return <StyledComponentSpinner sx={sx} className={className} {...props} />
}

StyledSpinner.displayName = 'Spinner'
Expand Down

0 comments on commit 2e5c601

Please sign in to comment.