Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gap to progressbar with multiple sections #4995

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
---

Adding default gap between sections for progressbars with more than one section
lukasoppermann marked this conversation as resolved.
Show resolved Hide resolved
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';
lukasoppermann marked this conversation as resolved.
Show resolved Hide resolved
${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
Loading