Skip to content

Commit 8a1ee22

Browse files
lukasoppermannTylerJDevsiddharthkp
authored
Add gap to progressbar with multiple sections (#4995)
* add gap to progressbar with multiple sections * update etst * Update packages/react/src/ProgressBar/ProgressBar.tsx Co-authored-by: Tyler Jones <[email protected]> * Update .changeset/stale-pets-tan.md Co-authored-by: Siddharth Kshetrapal <[email protected]> * update snapshots --------- Co-authored-by: Tyler Jones <[email protected]> Co-authored-by: Siddharth Kshetrapal <[email protected]>
1 parent 9fa9989 commit 8a1ee22

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-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+
ProgressBar: 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: 2px;
5656
${width}
5757
${sx};
5858
`

packages/react/src/__tests__/__snapshots__/ProgressBar.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exports[`ProgressBar respects the "progress" prop 1`] = `
1616
background-color: var(--borderColor-default,var(--color-border-default,#d0d7de));
1717
border-radius: 3px;
1818
height: 8px;
19+
gap: 2px;
1920
}
2021
2122
@media (prefers-reduced-motion:no-preference) {

0 commit comments

Comments
 (0)