Skip to content

Commit a682735

Browse files
authored
Fix ButtonGroup component and add docs (#2054)
* Make ButtonGroup display inline-flex * Create documentation page for ButtonGroup * Update Button docs * Create six-mirrors-call.md * Update tests * Update stories * Update six-mirrors-call.md
1 parent 1e82c72 commit a682735

File tree

8 files changed

+90
-20
lines changed

8 files changed

+90
-20
lines changed

.changeset/six-mirrors-call.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+
Fixes layout bug with ButtonGroup by changing the `display` property from `inline-block` to `inline-flex`

docs/content/Button.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ storybook: '/react/storybook?path=/story/composite-components-button'
77
description: Use button for the main actions on a page or form.
88
---
99

10-
import {Button, IconButton, LinkButton} from '@primer/react'
11-
12-
## Usage
13-
14-
### Installation
15-
1610
```js
1711
import {Button} from '@primer/react'
1812
```
1913

14+
## Examples
15+
2016
### Default button
2117

2218
This is the default variant for the `Button` component.
@@ -122,7 +118,7 @@ Here's an example of a block button which takes 100% of available width. Checkou
122118
<Button sx={{width: '100%'}}>Block</Button>
123119
```
124120

125-
## API reference
121+
## Props
126122

127123
Native `<button>` HTML attributes are forwarded to the underlying React `button` component and are not listed below.
128124

@@ -165,7 +161,7 @@ Native `<button>` HTML attributes are forwarded to the underlying React `button`
165161
<PropsTableSxRow />
166162
</PropsTable>
167163

168-
## Component status
164+
## Status
169165

170166
<ComponentChecklist
171167
items={{
@@ -174,7 +170,7 @@ Native `<button>` HTML attributes are forwarded to the underlying React `button`
174170
adaptsToThemes: true,
175171
adaptsToScreenSizes: true,
176172
fullTestCoverage: true,
177-
usedInProduction: false,
173+
usedInProduction: true,
178174
usageExamplesDocumented: true,
179175
designReviewed: false,
180176
a11yReviewed: false,
@@ -184,3 +180,7 @@ Native `<button>` HTML attributes are forwarded to the underlying React `button`
184180
hasFigmaComponent: false
185181
}}
186182
/>
183+
184+
## Related components
185+
186+
- [ButtonGroup](/ButtonGroup)

docs/content/ButtonGroup.mdx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: ButtonGroup
3+
componentId: button_group
4+
status: Alpha
5+
source: https://github.com/primer/react/tree/main/src/ButtonGroup
6+
---
7+
8+
```js
9+
import {ButtonGroup} from '@primer/react'
10+
```
11+
12+
## Examples
13+
14+
### Default
15+
16+
```jsx live
17+
<ButtonGroup>
18+
<Button>Button 1</Button>
19+
<Button>Button 2</Button>
20+
<Button>Button 3</Button>
21+
</ButtonGroup>
22+
```
23+
24+
### With icon buttons
25+
26+
```jsx live
27+
<ButtonGroup>
28+
<IconButton aria-label="Zoom out" icon={DashIcon} />
29+
<IconButton aria-label="Zoom in" icon={PlusIcon} />
30+
</ButtonGroup>
31+
```
32+
33+
## Props
34+
35+
### ButtonGroup
36+
37+
<PropsTable>
38+
<PropsTableSxRow />
39+
<PropsTableRefRow refType="HTMLDivElement" />
40+
</PropsTable>
41+
42+
## Status
43+
44+
<ComponentChecklist
45+
items={{
46+
propsDocumented: true,
47+
noUnnecessaryDeps: true,
48+
adaptsToThemes: true,
49+
adaptsToScreenSizes: true,
50+
fullTestCoverage: true,
51+
usedInProduction: false,
52+
usageExamplesDocumented: true,
53+
hasStorybookStories: false,
54+
designReviewed: false,
55+
a11yReviewed: false,
56+
stableApi: false,
57+
addressedApiFeedback: false,
58+
hasDesignGuidelines: false,
59+
hasFigmaComponent: false
60+
}}
61+
/>
62+
63+
## Related components
64+
65+
- [Button](/Button)

docs/src/@primer/gatsby-theme-doctocat/nav.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
url: /Breadcrumbs
5656
- title: Button
5757
url: /Button
58+
- title: ButtonGroup
59+
url: /ButtonGroup
5860
- title: Checkbox
5961
url: /Checkbox
6062
- title: CheckboxGroup

src/ButtonGroup.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import styled from 'styled-components'
2-
import Box from './Box'
32
import {get} from './constants'
43
import sx from './sx'
54
import {ComponentProps} from './utils/types'
65

7-
const ButtonGroup = styled(Box)`
6+
const ButtonGroup = styled.div`
7+
display: inline-flex;
88
vertical-align: middle;
99
1010
&& > * {
@@ -47,9 +47,5 @@ const ButtonGroup = styled(Box)`
4747
${sx};
4848
`
4949

50-
ButtonGroup.defaultProps = {
51-
display: 'inline-block'
52-
}
53-
5450
export type ButtonGroupProps = ComponentProps<typeof ButtonGroup>
5551
export default ButtonGroup

src/__tests__/deprecated/__snapshots__/Button.test.tsx.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ exports[`ButtonDanger renders correct disabled styles 1`] = `
298298

299299
exports[`ButtonGroup renders consistently 1`] = `
300300
.c0 {
301-
display: inline-block;
301+
display: -webkit-inline-box;
302+
display: -webkit-inline-flex;
303+
display: -ms-inline-flexbox;
304+
display: inline-flex;
302305
vertical-align: middle;
303306
}
304307
@@ -344,7 +347,6 @@ exports[`ButtonGroup renders consistently 1`] = `
344347
345348
<div
346349
className="c0"
347-
display="inline-block"
348350
/>
349351
`;
350352

src/stories/Overlay.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export const NestedOverlays = () => {
249249
<div>
250250
primary overlay open: {String(listOverlayOpen)}, secondary overlay open: {String(createListOverlayOpen)}
251251
</div>
252-
<ButtonGroup display="block" my={2}>
252+
<ButtonGroup>
253253
<Button>Star</Button>
254254
<Button
255255
aria-label="Add this repository to a list"
@@ -332,7 +332,7 @@ export const MemexNestedOverlays = () => {
332332

333333
return (
334334
<div>
335-
<ButtonGroup display="block" my={2}>
335+
<ButtonGroup>
336336
<Button>Add iteration</Button>
337337
<Button
338338
aria-label="Add custom iteration"

src/stories/deprecated/Button.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const closeButton = (args: ButtonStyleProps) => (
6666
<ButtonClose {...args} onClick={() => alert('button clicked.')} />
6767
)
6868
export const buttonGroup = (args: StrictButtonStyleProps) => (
69-
<ButtonGroup display="block" my={2}>
69+
<ButtonGroup>
7070
<Button {...args}>Button 1</Button>
7171
<Button {...args}>Button 2</Button>
7272
<Button {...args}>Button 3</Button>

0 commit comments

Comments
 (0)