Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 677
Add bg prop to ProgressBar.Item#5007
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': minor | ||
| --- | ||
| ProgressBar: Add `bg` prop to `ProgressBar.Item` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,15 @@ | ||
| import React from 'react' | ||
| import React, {useEffect} from 'react' | ||
| import type {Meta} from '@storybook/react' | ||
| import {ProgressBar, type ProgressBarProps} from '..' | ||
| const sectionColors = ['success.emphasis', 'done.emphasis', 'severe.emphasis', 'danger.emphasis', 'attention.emphasis'] | ||
| const sectionColorsDefault = [ | ||
| 'success.emphasis', | ||
| 'accent.emphasis', | ||
| 'done.emphasis', | ||
| 'severe.emphasis', | ||
| 'danger.emphasis', | ||
| 'attention.emphasis', | ||
| ] | ||
| export default { | ||
| title: 'Components/ProgressBar', | ||
| @@ -12,13 +19,21 @@ export default { | ||
| export const Default = () => <ProgressBar aria-label="Upload test.png" /> | ||
| export const Playground = ({sections, ...args}: ProgressBarProps & {sections: number}) => { | ||
| const [sectionColors, setSectionColors] = React.useState(sectionColorsDefault) | ||
| useEffect(() => { | ||
| if (args.bg && args.bg !== '') { | ||
| setSectionColors([args.bg, ...sectionColorsDefault]) | ||
| } | ||
| }, [args.bg]) | ||
| ||
| 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.Item key={i} progress={100 / sections} bg={sectionColors[i]} /> | ||
| ))} | ||
| </ProgressBar> | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,7 +7,10 @@ import type {SxProp} from '../sx' | ||
| import sx from '../sx' | ||
| import {warning} from '../utils/warning' | ||
| type ProgressProp = {progress?: string | number} | ||
| type ProgressProp = { | ||
| progress?: string | number | ||
lukasoppermann marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| bg?: string | ||
| } | ||
| const shimmer = keyframes` | ||
| from { mask-position: 200%; } | ||
| @@ -16,7 +19,7 @@ const shimmer = keyframes` | ||
| export const Item = styled.span<ProgressProp & SxProp>` | ||
| width: ${props => (props.progress ? `${props.progress}%` : 0)}; | ||
| background-color: ${get('colors.success.emphasis')}; | ||
| background-color: ${props => get(`colors.${props.bg || 'success.emphasis'}`)}; | ||
| @media (prefers-reduced-motion: no-preference) { | ||
| &[data-animated='true'] { | ||
| @@ -86,7 +89,7 @@ export const ProgressBar = forwardRef<HTMLSpanElement, ProgressBarProps>( | ||
| return ( | ||
| <ProgressContainer ref={forwardRef} role="progressbar" barSize={barSize} {...ariaAttributes} {...rest}> | ||
| {children ?? <Item data-animated={animated} progress={progress} sx={{backgroundColor: bg}} />} | ||
| {children ?? <Item data-animated={animated} progress={progress} bg={bg} />} | ||
| </ProgressContainer> | ||
| ) | ||
| }, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,7 +4,6 @@ exports[`ProgressBar respects the "progress" prop 1`] = ` | ||
| .c1 { | ||
| width: 80%; | ||
| background-color: var(--bgColor-success-emphasis,var(--color-success-emphasis,#1f883d)); | ||
| background-color: var(--bgColor-success-emphasis,var(--color-success-emphasis,#1f883d)); | ||
lukasoppermann marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| .c0 { | ||
Uh oh!
There was an error while loading. Please reload this page.