Skip to content

Commit bb89d1d

Browse files
committed
feat: add Progress component with styles and Storybook example
1 parent abeadc2 commit bb89d1d

3 files changed

Lines changed: 150 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Meta} from "@storybook/react-vite";
2+
import {Progress} from "./Progress";
3+
import React from "react";
4+
import {Card} from "../card/Card";
5+
import {Spacing} from "../spacing/Spacing";
6+
import {Text} from "../text/Text";
7+
8+
export default {
9+
title: "Progress",
10+
component: Progress,
11+
} as Meta
12+
13+
export const ProgressExample = () => {
14+
return <Card color={"secondary"} w={"300px"}>
15+
<Progress value={50} predictionValue={75} max={100} color={"linear-gradient(to right, #29BF12 0%, #D90429 100%)"}/>
16+
<Spacing spacing={"xs"}/>
17+
<Text>
18+
You used 50% of your available workflow executions and will used 75% until its reseted.
19+
</Text>
20+
<Spacing spacing={"xl"}/>
21+
<Progress value={30} predictionValue={120} max={100} color={"linear-gradient(to right, #29BF12 0%, #D90429 100%)"}/>
22+
<Spacing spacing={"xs"}/>
23+
<Text>
24+
You used 30% of your available workflow executions and will used 120% until its reseted.
25+
You need to upgrade your plan to be able to execute workflows seamlessly.
26+
</Text>
27+
</Card>
28+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
@use "../../styles/helpers";
2+
@use "../../styles/box";
3+
@use "../../styles/variables";
4+
5+
6+
.progress {
7+
8+
& {
9+
@include box.box(variables.$tertiary);
10+
@include helpers.borderRadius();
11+
width: 100%;
12+
height: 10px;
13+
position: relative;
14+
transform: translateZ(0);
15+
}
16+
17+
&__dot {
18+
@include box.box(variables.$white);
19+
background: helpers.backgroundColor(variables.$white, 2);
20+
position: absolute;
21+
max-width: 100%;
22+
aspect-ratio: 1/1;
23+
height: 200%;
24+
z-index: 2;
25+
top: 50%;
26+
transform: translateX(50%) translateY(-50%);
27+
border-radius: 50rem;
28+
right: calc(100% - (1% * (var(--progress, 0))));
29+
overflow: hidden;
30+
31+
&:after {
32+
content: "";
33+
position: absolute;
34+
top: 50%;
35+
left: 50%;
36+
border-radius: inherit;
37+
width: 60%;
38+
height: 60%;
39+
transform: translate(-50%, -50%);
40+
background: var(--color);
41+
background-repeat: no-repeat;
42+
}
43+
}
44+
45+
&__indicator {
46+
position: absolute;
47+
background: var(--color);
48+
background-position: left center;
49+
background-repeat: no-repeat;
50+
background-size: calc(100% * (100 / var(--progress, 100))) 100%;
51+
width: 100%;
52+
height: 100%;
53+
z-index: 1;
54+
55+
&--prediction {
56+
background: repeating-linear-gradient(
57+
-45deg,
58+
rgba(0,0,0,.5),
59+
rgba(0,0,0,.5) 2.5px,
60+
transparent 2.5px,
61+
transparent 5px
62+
), var(--color);
63+
z-index: 0;
64+
opacity: 0.5;
65+
background-position: left center;
66+
background-repeat: no-repeat;
67+
background-size: calc(100% * (100 / var(--progressPrediction, 100))) 100%;
68+
}
69+
}
70+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {ComponentProps, mergeComponentProps} from "../../utils";
2+
import * as Radix from "@radix-ui/react-progress"
3+
import React, {CSSProperties} from "react";
4+
import "./Progress.style.scss"
5+
6+
export type ProgressProps = ComponentProps & Radix.ProgressProps & {
7+
color?: CSSProperties['background']
8+
predictionValue?: number | null
9+
}
10+
11+
export const Progress: React.FC<ProgressProps> = (props) => {
12+
13+
const {color = "white", predictionValue, ...rest} = props
14+
15+
const progress = ((Math.min(props.value ?? 0, props.max ?? 100)) / (props.max ?? 100)) * 100;
16+
const transformValue = `translateX(-${100 - progress}%)`;
17+
18+
const progressPrediction = ((Math.min(props.predictionValue ?? 0, props.max ?? 100)) / (props.max ?? 100)) * 100;
19+
const transformPredictionValue = `translateX(-${100 - progressPrediction}%)`;
20+
21+
return <Radix.Progress {...mergeComponentProps('progress', {
22+
...rest,
23+
style: {
24+
...rest.style,
25+
['--progress' as any]: progress,
26+
['--progressPrediction' as any]: progressPrediction,
27+
['--color' as any]: color,
28+
}
29+
})}>
30+
31+
<div className={"progress__dot"}/>
32+
33+
<div style={{
34+
width: "100%",
35+
height: "100%",
36+
overflow: "hidden",
37+
borderRadius: "inherit",
38+
position: "relative",
39+
}}>
40+
<Radix.ProgressIndicator
41+
className="progress__indicator"
42+
style={{
43+
transform: transformValue
44+
}}/>
45+
{typeof props.predictionValue === "number" && <Radix.ProgressIndicator
46+
className="progress__indicator progress__indicator--prediction"
47+
style={{
48+
transform: transformPredictionValue
49+
}}/>}
50+
</div>
51+
</Radix.Progress>
52+
}

0 commit comments

Comments
 (0)