Skip to content

Commit 45d6f5b

Browse files
authored
progressbar component (#1556)
1 parent 9521e1d commit 45d6f5b

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2024, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
.progress-bar-container {
5+
position: relative;
6+
width: 100%;
7+
overflow: hidden;
8+
display: flex;
9+
align-items: center;
10+
justify-content: space-between;
11+
12+
.outer {
13+
border: 1px solid rgb(from var(--main-text-color) r g b / 15%);
14+
border-radius: 40px;
15+
padding: 4px;
16+
background-color: var(--main-bg-color);
17+
flex-grow: 1;
18+
19+
.progress-bar-fill {
20+
height: 100%;
21+
transition: width 0.3s ease-in-out;
22+
background-color: var(--success-color);
23+
border-radius: 9px;
24+
width: 100%;
25+
}
26+
}
27+
28+
.progress-bar-label {
29+
width: 40px;
30+
flex-shrink: 0;
31+
font-size: 0.9rem;
32+
color: var(--main-text-color);
33+
font-size: 12px;
34+
font-style: normal;
35+
font-weight: 400;
36+
line-height: normal;
37+
text-align: right;
38+
}
39+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2024, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import type { Meta, StoryObj } from "@storybook/react";
5+
import { ProgressBar } from "./progressbar";
6+
7+
const meta: Meta<typeof ProgressBar> = {
8+
title: "Elements/ProgressBar",
9+
component: ProgressBar,
10+
args: {
11+
progress: 0, // Default value
12+
label: "Progress",
13+
},
14+
argTypes: {
15+
progress: {
16+
description: "Percentage of progress (0-100)",
17+
control: { type: "range", min: 0, max: 100 },
18+
},
19+
label: {
20+
description: "Accessible label for the progress bar",
21+
control: "text",
22+
},
23+
},
24+
};
25+
26+
export default meta;
27+
28+
type Story = StoryObj<typeof ProgressBar>;
29+
30+
export const EmptyProgress: Story = {
31+
render: (args) => (
32+
<div style={{ padding: "20px", background: "#111", color: "#fff" }}>
33+
<ProgressBar {...args} />
34+
</div>
35+
),
36+
args: {
37+
progress: 0, // No progress
38+
label: "Empty progress bar",
39+
},
40+
};
41+
42+
export const FilledProgress: Story = {
43+
render: (args) => (
44+
<div style={{ padding: "20px", background: "#111", color: "#fff" }}>
45+
<ProgressBar {...args} />
46+
</div>
47+
),
48+
args: {
49+
progress: 90, // Filled to 90%
50+
label: "Filled progress bar",
51+
},
52+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { boundNumber } from "@/util/util";
5+
import "./progressbar.scss";
6+
7+
type ProgressBarProps = {
8+
progress: number;
9+
label?: string;
10+
};
11+
12+
const ProgressBar = ({ progress, label = "Progress" }: ProgressBarProps) => {
13+
const progressWidth = boundNumber(progress, 0, 100);
14+
15+
return (
16+
<div
17+
className="progress-bar-container"
18+
role="progressbar"
19+
aria-valuenow={progressWidth}
20+
aria-valuemin={0}
21+
aria-valuemax={100}
22+
aria-label={label}
23+
>
24+
<div className="outer">
25+
<div className="progress-bar-fill" style={{ width: `${progressWidth}%` }}></div>
26+
</div>
27+
<span className="progress-bar-label">{progressWidth}%</span>
28+
</div>
29+
);
30+
};
31+
32+
export { ProgressBar };

0 commit comments

Comments
 (0)