-
Notifications
You must be signed in to change notification settings - Fork 44
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 progress bar to ds #1787
Add progress bar to ds #1787
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||
import type { FC } from 'react'; | ||||||
import styled from 'styled-components'; | ||||||
|
||||||
import type { ProgressBarProps } from './ProgressBar.types'; | ||||||
import { getProgressWidthPercentage } from './ProgressBar.utils'; | ||||||
|
||||||
const StyledProgressBarContainer = styled.div<Omit<ProgressBarProps, 'progress' | 'max'>>` | ||||||
/* Default CSS */ | ||||||
background-color: var(--components-progress-bar-background-default); | ||||||
width: 100%; | ||||||
height: 4px; | ||||||
border-radius: var(--radius-xxs, 8px); | ||||||
|
||||||
/* Extra CSS prop */ | ||||||
${({ css }) => css || ''} | ||||||
`; | ||||||
|
||||||
const StyledProgressBar = styled.div<ProgressBarProps>` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/* Default CSS */ | ||||||
border-radius: var(--radius-xxs, 8px); | ||||||
background-color: var(--components-progress-bar-background-progress); | ||||||
height: 100%; | ||||||
width: ${({ progress, max }) => `${getProgressWidthPercentage(progress, max)}%`}; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
transition: width 0.3s ease; | ||||||
`; | ||||||
|
||||||
const ProgressBar: FC<ProgressBarProps> = ({ progress, max = 100, ...rest }) => ( | ||||||
<StyledProgressBarContainer | ||||||
role="progressbar" | ||||||
aria-valuemin={0} | ||||||
aria-valuemax={max} | ||||||
aria-valuenow={progress} | ||||||
{...rest} | ||||||
> | ||||||
<StyledProgressBar {...{ progress, max }} /> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
</StyledProgressBarContainer> | ||||||
); | ||||||
|
||||||
ProgressBar.displayName = 'ProgressBar'; | ||||||
|
||||||
export { ProgressBar }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TransformedHTMLAttributes } from 'blocks/Blocks.types'; | ||
import { FlattenSimpleInterpolation } from 'styled-components'; | ||
|
||
export type ProgressBarProps = { | ||
/* Additional prop from styled components to apply custom css to ProgressBar */ | ||
css?: FlattenSimpleInterpolation; | ||
/* Progress value */ | ||
progress: number; | ||
/* Max value */ | ||
max?: number; | ||
} & TransformedHTMLAttributes<HTMLDivElement>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const getProgressWidthPercentage = (progress: number, total = 100) => { | ||
const percentage = (progress / total) * 100; | ||
return Math.min(Math.max(percentage, 0), 100); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './ProgressBar'; | ||
export * from './ProgressBar.utils'; | ||
export * from './ProgressBar.types'; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,6 @@ | ||||||||||
import { colorBrands } from '../colors/colors.brands'; | ||||||||||
|
||||||||||
export const progressBarSemantics = { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
'background-default': { light: colorBrands['neutral-100'], dark: colorBrands['neutral-800'] }, | ||||||||||
'background-progress': { light: colorBrands['primary-600'], dark: colorBrands['primary-500'] }, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.