Skip to content

Commit b8cf221

Browse files
add gap to progressbar with multiple sections
1 parent dc80aa6 commit b8cf221

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

.changeset/stale-pets-tan.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+
Adding default gap between sections for progressbars with more than one section

packages/react/src/ProgressBar/ProgressBar.stories.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
2-
import type {Meta, StoryFn} from '@storybook/react'
3-
import {ProgressBar} from '..'
2+
import type {Meta} from '@storybook/react'
3+
import {ProgressBar, type ProgressBarProps} from '..'
4+
5+
const sectionColors = ['success.emphasis', 'done.emphasis', 'severe.emphasis', 'danger.emphasis', 'attention.emphasis']
46

57
export default {
68
title: 'Components/ProgressBar',
@@ -9,15 +11,26 @@ export default {
911

1012
export const Default = () => <ProgressBar aria-label="Upload test.png" />
1113

12-
export const Playground: StoryFn<typeof ProgressBar> = args => (
13-
<ProgressBar {...args} sx={args.inline ? {width: '100px'} : {}} aria-label="Upload test.png" />
14-
)
14+
export const Playground = ({sections, ...args}: ProgressBarProps & {sections: number}) => {
15+
if (sections === 1) {
16+
return <ProgressBar {...args} sx={args.inline ? {width: '100px'} : {}} aria-label="Upload test.png" />
17+
} else {
18+
return (
19+
<ProgressBar aria-label="Upload test.png">
20+
{[...Array(sections).keys()].map(i => (
21+
<ProgressBar.Item key={i} progress={100 / sections} sx={{bg: sectionColors[i]}} />
22+
))}
23+
</ProgressBar>
24+
)
25+
}
26+
}
1527

1628
Playground.args = {
1729
progress: 66,
1830
barSize: 'default',
1931
inline: false,
2032
bg: 'success.emphasis',
33+
sections: 1,
2134
}
2235

2336
Playground.argTypes = {
@@ -37,4 +50,12 @@ Playground.argTypes = {
3750
type: 'boolean',
3851
},
3952
},
53+
sections: {
54+
control: {
55+
type: 'number',
56+
min: 1,
57+
max: 5,
58+
step: 1,
59+
},
60+
},
4061
}

packages/react/src/ProgressBar/ProgressBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const ProgressContainer = styled.span<StyledProgressContainerProps>`
5252
background-color: ${get('colors.border.default')};
5353
border-radius: ${get('radii.1')};
5454
height: ${props => sizeMap[props.barSize || 'default']};
55-
55+
gap: ${props => (props.children ? '2px' : '0')};
5656
${width}
5757
${sx};
5858
`

0 commit comments

Comments
 (0)