Skip to content

Commit

Permalink
Add gap to progressbar with multiple sections (#4995)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people committed Sep 23, 2024
1 parent 619b705 commit 48a56e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-pets-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

ProgressBar: Adding default gap between sections for progressbars with more than one section
31 changes: 26 additions & 5 deletions packages/react/src/ProgressBar/ProgressBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react'
import type {Meta, StoryFn} from '@storybook/react'
import {ProgressBar} from '..'
import type {Meta} from '@storybook/react'
import {ProgressBar, type ProgressBarProps} from '..'

const sectionColors = ['success.emphasis', 'done.emphasis', 'severe.emphasis', 'danger.emphasis', 'attention.emphasis']

export default {
title: 'Components/ProgressBar',
Expand All @@ -9,15 +11,26 @@ export default {

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

export const Playground: StoryFn<typeof ProgressBar> = args => (
<ProgressBar {...args} sx={args.inline ? {width: '100px'} : {}} aria-label="Upload test.png" />
)
export const Playground = ({sections, ...args}: ProgressBarProps & {sections: number}) => {
if (sections === 1) {
return <ProgressBar {...args} sx={args.inline ? {width: '100px'} : {}} aria-label="Upload test.png" />
} else {
return (
<ProgressBar aria-label="Upload test.png">
{[...Array(sections).keys()].map(i => (
<ProgressBar.Item key={i} progress={100 / sections} sx={{bg: sectionColors[i]}} />
))}
</ProgressBar>
)
}
}

Playground.args = {
progress: 66,
barSize: 'default',
inline: false,
bg: 'success.emphasis',
sections: 1,
}

Playground.argTypes = {
Expand All @@ -37,4 +50,12 @@ Playground.argTypes = {
type: 'boolean',
},
},
sections: {
control: {
type: 'number',
min: 1,
max: 5,
step: 1,
},
},
}
2 changes: 1 addition & 1 deletion packages/react/src/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ProgressContainer = styled.span<StyledProgressContainerProps>`
background-color: ${get('colors.border.default')};
border-radius: ${get('radii.1')};
height: ${props => sizeMap[props.barSize || 'default']};
gap: 2px;
${width}
${sx};
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports[`ProgressBar respects the "progress" prop 1`] = `
background-color: var(--borderColor-default,var(--color-border-default,#d0d7de));
border-radius: 3px;
height: 8px;
gap: 2px;
}
@media (prefers-reduced-motion:no-preference) {
Expand Down

0 comments on commit 48a56e9

Please sign in to comment.