Skip to content

Commit b1e5699

Browse files
authoredJan 8, 2025··
chore(ButtonGroup): Remove CSS modules feature flag from ButtonGroup (#5457)
* Remove CSS modules feature flag from ButtonGroup * test(vrt): update snapshots * Revert Avatar snapshot change * Create lemon-files-complain.md --------- Co-authored-by: jonrohan <jonrohan@users.noreply.github.com>
1 parent 8b8ec3c commit b1e5699

13 files changed

+63
-105
lines changed
 

‎.changeset/lemon-files-complain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Remove CSS modules feature flag from ButtonGroup

‎e2e/components/ButtonGroup.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,32 @@ test.describe('ButtonGroup', () => {
142142
})
143143
}
144144
})
145+
146+
test.describe('SX Prop', () => {
147+
for (const theme of themes) {
148+
test.describe(theme, () => {
149+
test('default @vrt', async ({page}) => {
150+
await visit(page, {
151+
id: 'components-buttongroup-devonly--sx-prop',
152+
globals: {
153+
colorScheme: theme,
154+
},
155+
})
156+
157+
// Default state
158+
expect(await page.screenshot()).toMatchSnapshot(`ButtonGroup.SX Prop.${theme}.png`)
159+
})
160+
161+
test('axe @aat', async ({page}) => {
162+
await visit(page, {
163+
id: 'components-buttongroup-devonly--sx-prop',
164+
globals: {
165+
colorScheme: theme,
166+
},
167+
})
168+
await expect(page).toHaveNoViolations()
169+
})
170+
})
171+
}
172+
})
145173
})

‎packages/react/src/ButtonGroup/ButtonGroup.dev.stories.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ export const LinkButtonWithIconButtons = () => (
6363
<IconButton icon={CopilotIcon} aria-label="Open GitHub Copilot chat" />
6464
</ButtonGroup>
6565
)
66+
67+
export const SxProp = () => (
68+
<ButtonGroup sx={{border: '1px solid red'}}>
69+
<Button>Button 1</Button>
70+
<Button>Button 2</Button>
71+
<Button>Button 3</Button>
72+
</ButtonGroup>
73+
)

‎packages/react/src/ButtonGroup/ButtonGroup.tsx

+22-105
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,25 @@
1-
import styled from 'styled-components'
2-
import React from 'react'
3-
import sx from '../sx'
4-
import type {ComponentProps} from '../utils/types'
1+
import React, {type PropsWithChildren} from 'react'
2+
import {type SxProp} from '../sx'
53
import classes from './ButtonGroup.module.css'
6-
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
74
import {clsx} from 'clsx'
8-
import {useFeatureFlag} from '../FeatureFlags'
95
import {FocusKeys, useFocusZone} from '../hooks/useFocusZone'
106
import {useProvidedRefOrCreate} from '../hooks'
117
import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../utils/polymorphic'
8+
import Box from '../Box'
9+
import {defaultSxProp} from '../utils/defaultSxProp'
1210

13-
const StyledButtonGroup = toggleStyledComponent(
14-
'primer_react_css_modules_ga',
15-
'div',
16-
styled.div`
17-
display: inline-flex;
18-
vertical-align: middle;
19-
isolation: isolate;
20-
21-
& > *:not([data-loading-wrapper]) {
22-
/* stylelint-disable-next-line primer/spacing */
23-
margin-inline-end: -1px;
24-
position: relative;
25-
26-
/* reset border-radius */
27-
button,
28-
a {
29-
border-radius: 0;
30-
}
31-
32-
&:first-child {
33-
button,
34-
a {
35-
border-top-left-radius: var(--borderRadius-medium);
36-
border-bottom-left-radius: var(--borderRadius-medium);
37-
}
38-
}
39-
40-
&:last-child {
41-
button,
42-
a {
43-
border-top-right-radius: var(--borderRadius-medium);
44-
border-bottom-right-radius: var(--borderRadius-medium);
45-
}
46-
}
47-
48-
&:focus,
49-
&:active,
50-
&:hover {
51-
z-index: 1;
52-
}
53-
}
54-
55-
/* this is a workaround until portal based tooltips are fully removed from dotcom */
56-
&:has(div:last-child:empty) {
57-
button,
58-
a {
59-
border-radius: var(--borderRadius-medium);
60-
}
61-
}
62-
63-
/* if child is loading button */
64-
& > *[data-loading-wrapper] {
65-
/* stylelint-disable-next-line primer/spacing */
66-
margin-inline-end: -1px;
67-
position: relative;
68-
/* reset border-radius */
69-
button,
70-
a {
71-
border-radius: 0;
72-
}
73-
74-
&:focus,
75-
&:active,
76-
&:hover {
77-
z-index: 1;
78-
}
79-
&:first-child {
80-
button,
81-
a {
82-
border-top-left-radius: var(--borderRadius-medium);
83-
border-bottom-left-radius: var(--borderRadius-medium);
84-
}
85-
}
86-
87-
&:last-child {
88-
button,
89-
a {
90-
border-top-right-radius: var(--borderRadius-medium);
91-
border-bottom-right-radius: var(--borderRadius-medium);
92-
}
93-
}
94-
}
95-
96-
${sx};
97-
`,
98-
)
99-
100-
export type ButtonGroupProps = ComponentProps<typeof StyledButtonGroup>
11+
export type ButtonGroupProps = {
12+
/** The role of the group */
13+
role?: string
14+
/** className passed in for styling */
15+
className?: string
16+
} & PropsWithChildren &
17+
SxProp
10118

10219
const ButtonGroup = React.forwardRef<HTMLElement, ButtonGroupProps>(function ButtonGroup(
103-
{children, className, role, ...rest},
20+
{children, className, role, sx, ...rest},
10421
forwardRef,
10522
) {
106-
const enabled = useFeatureFlag('primer_react_css_modules_ga')
10723
const buttons = React.Children.map(children, (child, index) => <div key={index}>{child}</div>)
10824
const buttonRef = useProvidedRefOrCreate(forwardRef as React.RefObject<HTMLDivElement>)
10925

@@ -114,17 +30,18 @@ const ButtonGroup = React.forwardRef<HTMLElement, ButtonGroupProps>(function But
11430
focusOutBehavior: 'wrap',
11531
})
11632

33+
if (sx !== defaultSxProp) {
34+
return (
35+
<Box as="div" className={clsx(className, classes.ButtonGroup)} role={role} {...rest} sx={sx} ref={buttonRef}>
36+
{buttons}
37+
</Box>
38+
)
39+
}
40+
11741
return (
118-
<StyledButtonGroup
119-
ref={buttonRef}
120-
className={clsx(className, {
121-
[classes.ButtonGroup]: enabled,
122-
})}
123-
role={role}
124-
{...rest}
125-
>
42+
<div ref={buttonRef} className={clsx(className, classes.ButtonGroup)} role={role} {...rest}>
12643
{buttons}
127-
</StyledButtonGroup>
44+
</div>
12845
)
12946
}) as PolymorphicForwardRefComponent<'div', ButtonGroupProps>
13047

0 commit comments

Comments
 (0)
Please sign in to comment.