Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 9b2e177

Browse files
lekoafboilund
authored andcommitted
feat: secondary progress
Adds a "secondary" variant to the the progress. This will not break any existing usage of this component since the "primary" color will be default for the progress bar.
1 parent 7f9c291 commit 9b2e177

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

packages/core/src/Progress/index.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { spacing, shape } from '../designparams'
77
type BaseElement = HTMLDivElement
88
type BaseProps = HTMLAttributes<BaseElement>
99

10+
type ProgressMeterVariants = 'primary' | 'secondary'
11+
12+
interface ProgressMeterProps {
13+
readonly fraction: number
14+
readonly variant: ProgressMeterVariants
15+
}
16+
1017
const ProgressContainer = styled.div`
1118
display: flex;
1219
align-items: center;
@@ -22,8 +29,11 @@ const ProgressIndicator = styled.div`
2229
overflow: hidden;
2330
`
2431

25-
const ProgressMeter = styled.div<{ readonly fraction: number }>`
26-
background-color: ${({ theme }) => theme.color.elementPrimary()};
32+
const ProgressMeter = styled.div<ProgressMeterProps>`
33+
background-color: ${({ theme, variant }) =>
34+
variant === 'primary'
35+
? theme.color.elementPrimary()
36+
: theme.color.element14()};
2737
border-radius: inherit;
2838
height: 100%;
2939
width: ${({ fraction }) => `${Math.round(fraction * 100)}%`};
@@ -50,12 +60,21 @@ export interface ProgressProps extends BaseProps {
5060
* A string used to tell the user information regarding the progress value.
5161
*/
5262
readonly label: string
63+
/**
64+
* Primary or secondary variant of the progress meter
65+
*/
66+
readonly variant?: ProgressMeterVariants
5367
}
5468

55-
export const Progress: FC<ProgressProps> = ({ value, label, ...props }) => (
69+
export const Progress: FC<ProgressProps> = ({
70+
value,
71+
label,
72+
variant = 'primary',
73+
...props
74+
}) => (
5675
<ProgressContainer {...props}>
5776
<ProgressIndicator>
58-
<ProgressMeter fraction={value} />
77+
<ProgressMeter fraction={value} variant={variant} />
5978
</ProgressIndicator>
6079
<ProgressLabel>{label}</ProgressLabel>
6180
</ProgressContainer>

packages/docs/src/mdx/coreComponents/Progress.mdx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ export const meta = {
55
}
66

77
import styled from 'styled-components'
8-
import { Progress } from 'practical-react-components-core'
8+
import {
9+
Progress,
10+
SpaceBlock,
11+
Typography,
12+
} from 'practical-react-components-core'
913

1014
# Progress
1115

@@ -15,14 +19,23 @@ A Progress inform users about the status of ongoing progresses.
1519

1620
export const total = 84
1721
export const data = 31
18-
export const value = (data / total).toFixed(2)
22+
export const value = parseFloat((data / total).toFixed(2))
1923

24+
<Typography>Primary</Typography>
2025
<Progress value={value} label={`${data}/${total}Mb`} className="progress" />
26+
<SpaceBlock variant={32} />
27+
<Typography>Secondary</Typography>
28+
<Progress
29+
value={value}
30+
label={`${data}/${total}Mb`}
31+
className="progress"
32+
variant="secondary"
33+
/>
2134

2235
## Basic usage
2336

2437
```typescript type="live"
25-
<Progress value={0.5} label="50%" />
38+
<Progress value={0.5} label="50%" variant="primary" />
2639
```
2740

2841
## Props

0 commit comments

Comments
 (0)