Skip to content

Commit 19befd6

Browse files
Remove support for sx from CircleBadge component (#6673)
Co-authored-by: Marie Lucca <francinelucca@github.com> Co-authored-by: Marie Lucca <40550942+francinelucca@users.noreply.github.com>
1 parent 94be2cd commit 19befd6

File tree

9 files changed

+82
-40
lines changed

9 files changed

+82
-40
lines changed

.changeset/cool-apricots-sneeze.md

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

.changeset/lazy-elephants-shave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@primer/react": patch
3+
"@primer/styled-react": patch
4+
---
5+
6+
Remove support for `sx` from `CircleBadge` component

packages/react/src/CircleBadge/CircleBadge.docs.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
"name": "as",
3333
"type": "React.ElementType",
3434
"defaultValue": "\"div\""
35-
},
36-
{
37-
"name": "sx",
38-
"type": "SystemStyleObject",
39-
"deprecated": true
4035
}
4136
],
4237
"subcomponents": [
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.CircleBadge {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
background-color: var(--bgColor-default);
6+
border-radius: 50%;
7+
box-shadow: var(--shadow-resting-medium);
8+
9+
&:where([data-inline]) {
10+
display: inline-flex;
11+
}
12+
}
13+
14+
.CircleBadgeIcon {
15+
height: auto;
16+
max-height: 55%;
17+
max-width: 60%;
18+
}

packages/react/src/CircleBadge/CircleBadge.stories.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ export const Default = () => (
1414
</CircleBadge>
1515
)
1616

17-
export const Playground: StoryFn<typeof CircleBadge> = ({'CircleBadge.Icon aria-label': iconAriaLabel, args}) => (
17+
export const Playground: StoryFn<typeof CircleBadge> = args => (
1818
<CircleBadge {...args}>
19-
<CircleBadge.Icon icon={ZapIcon} aria-label={iconAriaLabel} />
19+
<CircleBadge.Icon icon={ZapIcon} aria-label="Zap" />
2020
</CircleBadge>
2121
)
2222

2323
Playground.args = {
2424
variant: 'medium',
25-
size: null,
25+
size: undefined,
2626
inline: false,
2727
as: 'div',
28-
'CircleBadge.Icon aria-label': undefined,
2928
}
3029

3130
Playground.argTypes = {
@@ -45,7 +44,4 @@ Playground.argTypes = {
4544
type: 'boolean',
4645
},
4746
},
48-
'CircleBadge.Icon aria-label': {
49-
type: 'string',
50-
},
5147
}

packages/react/src/CircleBadge/CircleBadge.tsx

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
1-
import styled from 'styled-components'
2-
import {get} from '../constants'
31
import Octicon from '../Octicon'
4-
import type {SxProp} from '../sx'
5-
import sx from '../sx'
62
import isNumeric from '../utils/isNumeric'
73
import type {ComponentProps} from '../utils/types'
84

5+
import styles from './CircleBadge.module.css'
6+
import type {OcticonProps} from '../Octicon'
7+
import {clsx} from 'clsx'
8+
99
const variantSizes = {
1010
small: 56,
1111
medium: 96,
1212
large: 128,
1313
}
1414

15-
type StyledCircleBadgeProps = {
15+
export type CircleBadgeProps<As extends React.ElementType> = {
1616
inline?: boolean
1717
variant?: keyof typeof variantSizes
1818
size?: number
19-
} & SxProp
19+
as?: As
20+
className?: string
21+
} & React.ComponentPropsWithRef<React.ElementType extends As ? 'a' : As>
2022

21-
const sizeStyles = ({size, variant = 'medium'}: StyledCircleBadgeProps) => {
23+
const sizeStyles = ({size, variant = 'medium'}: CircleBadgeProps<React.ElementType>) => {
2224
const calc = isNumeric(size) ? size : variantSizes[variant]
2325
return {
2426
width: calc,
2527
height: calc,
2628
}
2729
}
2830

29-
const CircleBadge = styled.div<StyledCircleBadgeProps>`
30-
display: ${({inline = false}) => (inline ? 'inline-flex' : 'flex')};
31-
align-items: center;
32-
justify-content: center;
33-
background-color: ${get('colors.canvas.default')};
34-
border-radius: 50%;
35-
box-shadow: ${get('shadows.shadow.medium')};
36-
${sizeStyles};
37-
${sx};
38-
`
39-
const CircleBadgeIcon = styled(Octicon)`
40-
height: auto;
41-
max-width: 60%;
42-
max-height: 55%;
43-
`
31+
const CircleBadge = <As extends React.ElementType>({as: Component = 'div', ...props}: CircleBadgeProps<As>) => (
32+
<Component
33+
{...props}
34+
className={clsx(styles.CircleBadge, props.className)}
35+
data-inline={props.inline ? '' : undefined}
36+
style={sizeStyles(props)}
37+
/>
38+
)
4439

45-
CircleBadgeIcon.displayName = 'CircleBadge.Icon'
40+
const CircleBadgeIcon = (props: OcticonProps) => <Octicon className={styles.CircleBadgeIcon} {...props} />
4641

47-
export type CircleBadgeProps = ComponentProps<typeof CircleBadge>
42+
CircleBadgeIcon.displayName = 'CircleBadge.Icon'
4843

4944
export type CircleBadgeIconProps = ComponentProps<typeof CircleBadgeIcon>
5045

packages/react/src/CircleBadge/__snapshots__/CircleBadge.test.tsx.snap

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22

33
exports[`CircleBadge > respects the inline prop 1`] = `
44
<div
5-
class="sc-gEvEer lNPvJ"
5+
class="prc-CircleBadge-CircleBadge-LZ7wp"
6+
data-inline=""
7+
style="width: 96px; height: 96px;"
68
/>
79
`;
810

911
exports[`CircleBadge > respects the variant prop 1`] = `
1012
<div
11-
class="sc-gEvEer irZoQl"
13+
class="prc-CircleBadge-CircleBadge-LZ7wp"
14+
style="width: 128px; height: 128px;"
15+
variant="large"
1216
/>
1317
`;
1418

1519
exports[`CircleBadge > uses the size prop to override the variant prop 1`] = `
1620
<div
17-
class="sc-gEvEer ceBMXF"
21+
class="prc-CircleBadge-CircleBadge-LZ7wp"
1822
size="20"
23+
style="width: 20px; height: 20px;"
24+
variant="large"
1925
/>
2026
`;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
CircleBadge as PrimerCircleBadge,
3+
type CircleBadgeProps as PrimerCircleBadgeProps,
4+
sx,
5+
type SxProp,
6+
} from '@primer/react'
7+
import styled from 'styled-components'
8+
import {type ForwardRefComponent} from '../polymorphic'
9+
10+
type CircleBadgeProps<As extends React.ElementType> = PrimerCircleBadgeProps<As> & SxProp
11+
12+
const CircleBadge: ForwardRefComponent<React.ElementType, CircleBadgeProps<React.ElementType>> = styled(
13+
PrimerCircleBadge,
14+
).withConfig({
15+
shouldForwardProp: prop => (prop as keyof CircleBadgeProps<React.ElementType>) !== 'sx',
16+
})<CircleBadgeProps<React.ElementType>>`
17+
${sx}
18+
`
19+
20+
export {CircleBadge}
21+
export type {CircleBadgeProps}

packages/styled-react/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export {Breadcrumbs} from '@primer/react'
66
export {Box, type BoxProps} from './components/Box'
77
export {Button} from '@primer/react'
88
export {CheckboxGroup} from '@primer/react'
9-
export {CircleBadge} from '@primer/react'
109
export {Details} from '@primer/react'
1110
export {FormControl} from '@primer/react'
1211
export {Heading} from '@primer/react'
@@ -32,6 +31,7 @@ export {useColorSchemeVar} from '@primer/react'
3231
export {useTheme} from '@primer/react'
3332

3433
export {Checkbox, type CheckboxProps} from './components/Checkbox'
34+
export {CircleBadge} from './components/CircleBadge'
3535
export {CounterLabel, type CounterLabelProps} from './components/CounterLabel'
3636
export {Dialog, type DialogProps} from './components/Dialog'
3737
export {Flash} from './components/Flash'

0 commit comments

Comments
 (0)