-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add progress bar to ds * chore: update progress bar according to review
- Loading branch information
1 parent
8d2d695
commit dbd05fd
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { FC } from 'react'; | ||
import styled, { FlattenSimpleInterpolation } from 'styled-components'; | ||
|
||
import type { ProgressBarProps } from './ProgressBar.types'; | ||
import { getProgressWidthPercentage } from './ProgressBar.utils'; | ||
|
||
const StyledProgressBarContainer = styled.div<{ css?: FlattenSimpleInterpolation }>` | ||
/* 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<{ width: string }>` | ||
/* Default CSS */ | ||
border-radius: var(--radius-xxs, 8px); | ||
background-color: var(--components-progress-bar-background-progress); | ||
height: 100%; | ||
width: ${({ width }) => width}; | ||
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 width={`${getProgressWidthPercentage(progress, max)}%`} /> | ||
</StyledProgressBarContainer> | ||
); | ||
|
||
ProgressBar.displayName = 'ProgressBar'; | ||
|
||
export { ProgressBar }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { surfaceSemantics } from './semantics.surface'; | ||
|
||
export const progressBarSemantics = { | ||
'background-default': { light: surfaceSemantics['secondary'].light, dark: surfaceSemantics['secondary'].dark }, | ||
'background-progress': { light: surfaceSemantics['brand-medium'].light, dark: surfaceSemantics['brand-medium'].dark }, | ||
}; |