Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 23 additions & 4 deletions packages/core/src/Progress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { spacing, shape } from '../designparams'
type BaseElement = HTMLDivElement
type BaseProps = HTMLAttributes<BaseElement>

type ProgressMeterVariants = 'primary' | 'secondary'

interface ProgressMeterProps {
readonly fraction: number
readonly variant: ProgressMeterVariants
}

const ProgressContainer = styled.div`
display: flex;
align-items: center;
Expand All @@ -22,8 +29,11 @@ const ProgressIndicator = styled.div`
overflow: hidden;
`

const ProgressMeter = styled.div<{ readonly fraction: number }>`
background-color: ${({ theme }) => theme.color.elementPrimary()};
const ProgressMeter = styled.div<ProgressMeterProps>`
background-color: ${({ theme, variant }) =>
variant === 'primary'
? theme.color.elementPrimary()
: theme.color.element14()};
border-radius: inherit;
height: 100%;
width: ${({ fraction }) => `${Math.round(fraction * 100)}%`};
Expand All @@ -50,12 +60,21 @@ export interface ProgressProps extends BaseProps {
* A string used to tell the user information regarding the progress value.
*/
readonly label: string
/**
* Primary or secondary variant of the progress meter
*/
readonly variant?: ProgressMeterVariants
}

export const Progress: FC<ProgressProps> = ({ value, label, ...props }) => (
export const Progress: FC<ProgressProps> = ({
value,
label,
variant = 'primary',
...props
}) => (
<ProgressContainer {...props}>
<ProgressIndicator>
<ProgressMeter fraction={value} />
<ProgressMeter fraction={value} variant={variant} />
</ProgressIndicator>
<ProgressLabel>{label}</ProgressLabel>
</ProgressContainer>
Expand Down
19 changes: 16 additions & 3 deletions packages/docs/src/mdx/coreComponents/Progress.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export const meta = {
}

import styled from 'styled-components'
import { Progress } from 'practical-react-components-core'
import {
Progress,
SpaceBlock,
Typography,
} from 'practical-react-components-core'

# Progress

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

export const total = 84
export const data = 31
export const value = (data / total).toFixed(2)
export const value = parseFloat((data / total).toFixed(2))

<Typography>Primary</Typography>
<Progress value={value} label={`${data}/${total}Mb`} className="progress" />
<SpaceBlock variant={32} />
<Typography>Secondary</Typography>
<Progress
value={value}
label={`${data}/${total}Mb`}
className="progress"
variant="secondary"
/>

## Basic usage

```typescript type="live"
<Progress value={0.5} label="50%" />
<Progress value={0.5} label="50%" variant="primary" />
```

## Props
Expand Down