Skip to content

Commit 4ce474a

Browse files
feat: new progress components (#80)
1 parent c1dde6b commit 4ce474a

8 files changed

+148
-2
lines changed

.changeset/nervous-goats-tie.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zenml-io/react-component-library": minor
3+
---
4+
5+
add radial progress & progress bar

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"@radix-ui/react-collapsible": "^1.0.3",
9191
"@radix-ui/react-dialog": "^1.0.5",
9292
"@radix-ui/react-dropdown-menu": "^2.0.6",
93+
"@radix-ui/react-progress": "^1.0.3",
9394
"@radix-ui/react-select": "^2.0.0",
9495
"@radix-ui/react-slot": "^1.0.2",
9596
"@radix-ui/react-switch": "^1.0.3",

pnpm-lock.yaml

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Meta } from "@storybook/react";
2+
import { ProgressBar } from "./index";
3+
import { StoryObj } from "@storybook/react";
4+
import React from "react";
5+
6+
const meta = {
7+
title: "Elements/Progress/ProgressBar",
8+
component: ProgressBar,
9+
10+
parameters: {
11+
layout: "centered"
12+
},
13+
decorators: [
14+
(Story) => (
15+
<div className="w-[400px] h-[200px]">
16+
<Story />
17+
</div>
18+
)
19+
],
20+
tags: ["autodocs"]
21+
} satisfies Meta<typeof ProgressBar>;
22+
23+
export default meta;
24+
25+
type Story = StoryObj<typeof meta>;
26+
27+
export const DefaultVariant: Story = {
28+
name: "Default",
29+
args: {
30+
className: "rounded-rounded",
31+
value: 45
32+
}
33+
};
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as ProgressPrimitive from "@radix-ui/react-progress";
2+
import React, { ComponentPropsWithoutRef, ElementRef, forwardRef } from "react";
3+
import { cn } from "../../utilities";
4+
5+
const ProgressBar = forwardRef<
6+
ElementRef<typeof ProgressPrimitive.Root>,
7+
ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
8+
>(({ className, value, ...props }, ref) => (
9+
<ProgressPrimitive.Root
10+
ref={ref}
11+
className={cn("rounded-full relative h-4 w-full overflow-hidden bg-primary-50", className)}
12+
{...props}
13+
>
14+
<ProgressPrimitive.Indicator
15+
className="h-full w-full flex-1 bg-primary-400 transition-all"
16+
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
17+
/>
18+
</ProgressPrimitive.Root>
19+
));
20+
ProgressBar.displayName = ProgressPrimitive.Root.displayName;
21+
22+
export { ProgressBar };

src/components/Progress/ProgressItems.tsx

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { HTMLAttributes } from "react";
2-
import { cn } from "../../utilities";
31
import { cva, VariantProps } from "class-variance-authority";
2+
import React, { CSSProperties, HTMLAttributes } from "react";
3+
4+
import { cn } from "../../utilities";
45

56
export const progressTickCircleVariants = cva(
67
"shrink-0 flex items-center justify-center rounded-rounded border-success-300 bg-success-50",
@@ -64,3 +65,38 @@ export function ProgressOutstanding({
6465
}: HTMLAttributes<HTMLDivElement> & VariantProps<typeof progressOutstandingVariants>) {
6566
return <div {...rest} className={cn(progressOutstandingVariants({ size }), className)}></div>;
6667
}
68+
69+
type RadialProgressProps = {
70+
value: number;
71+
outerCirlcle?: number;
72+
innerCircle?: number;
73+
};
74+
export function RadialProgress({
75+
value,
76+
outerCirlcle = 40,
77+
innerCircle = 30,
78+
children,
79+
className,
80+
...rest
81+
}: HTMLAttributes<HTMLDivElement> & RadialProgressProps) {
82+
return (
83+
<div
84+
{...rest}
85+
style={
86+
{
87+
"--value": `${value * 3.6}deg`,
88+
"--outer-circle": `${outerCirlcle}px`,
89+
"--inner-circle": `${innerCircle}px`
90+
} as CSSProperties
91+
}
92+
className={cn(
93+
"relative flex h-[var(--outer-circle)] w-[var(--outer-circle)] shrink-0 items-center justify-center rounded-rounded bg-[conic-gradient(hsl(var(--color-primary-400))_var(--value),hsl(var(--color-primary-050))_var(--value))] after:h-[var(--inner-circle)] after:w-[var(--inner-circle)] after:rounded-rounded after:bg-theme-surface-primary after:content-['']",
94+
className
95+
)}
96+
aria-label="Radial Progress Bar"
97+
role="progressbar"
98+
>
99+
{children}
100+
</div>
101+
);
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Meta } from "@storybook/react";
2+
import { RadialProgress } from "./index";
3+
import { StoryObj } from "@storybook/react";
4+
5+
const meta = {
6+
title: "Elements/Progress/Radial Progress",
7+
component: RadialProgress,
8+
9+
parameters: {
10+
layout: "centered"
11+
},
12+
tags: ["autodocs"]
13+
} satisfies Meta<typeof RadialProgress>;
14+
15+
export default meta;
16+
17+
type Story = StoryObj<typeof meta>;
18+
19+
export const DefaultVariant: Story = {
20+
name: "Default",
21+
args: {
22+
value: 45
23+
}
24+
};

src/components/Progress/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./ProgressItems";
2+
export * from "./ProgressBar";

0 commit comments

Comments
 (0)