Skip to content

Commit 51bad09

Browse files
committed
feat: add component progress
1 parent 779ded8 commit 51bad09

File tree

10 files changed

+234
-0
lines changed

10 files changed

+234
-0
lines changed

packages/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@radix-ui/react-menubar": "1.1.15",
3939
"@radix-ui/react-navigation-menu": "1.2.13",
4040
"@radix-ui/react-popover": "1.1.14",
41+
"@radix-ui/react-progress": "^1.1.7",
4142
"@radix-ui/react-radio-group": "1.3.7",
4243
"@radix-ui/react-scroll-area": "1.2.9",
4344
"@radix-ui/react-select": "^2.2.5",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Indicator, Root } from '@radix-ui/react-progress';
2+
import type { ComponentRef } from 'react';
3+
import { forwardRef } from 'react';
4+
5+
import { cn } from '@/lib/utils';
6+
7+
import { progressVariants } from './progress-variants';
8+
import type { ProgressProps } from './types';
9+
10+
const Progress = forwardRef<ComponentRef<typeof Root>, ProgressProps>((props, ref) => {
11+
const { className, classNames, color, size, value, ...rest } = props;
12+
13+
const { indicator, root } = progressVariants({ color, size });
14+
15+
const mergedCls = {
16+
indicator: cn(indicator(), classNames?.indicator),
17+
root: cn(root(), className, classNames?.root)
18+
};
19+
20+
return (
21+
<Root
22+
className={mergedCls.root}
23+
data-slot="progress-root"
24+
ref={ref}
25+
value={value}
26+
{...rest}
27+
>
28+
<Indicator
29+
className={mergedCls.indicator}
30+
data-slot="progress-indicator"
31+
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
32+
/>
33+
</Root>
34+
);
35+
});
36+
37+
Progress.displayName = 'Progress';
38+
39+
export default Progress;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as Progress } from './Progress';
2+
3+
export * from './types';
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { tv } from 'tailwind-variants';
2+
3+
export const progressVariants = tv({
4+
defaultVariants: {
5+
color: 'primary',
6+
size: 'md'
7+
},
8+
slots: {
9+
indicator: 'flex-1 size-full transition-all duration-200',
10+
root: 'relative w-full overflow-hidden rounded-full'
11+
},
12+
variants: {
13+
color: {
14+
accent: {
15+
indicator: 'bg-accent-foreground',
16+
root: 'bg-accent-foreground/20'
17+
},
18+
carbon: {
19+
indicator: 'bg-carbon',
20+
root: 'bg-carbon/20'
21+
},
22+
destructive: {
23+
indicator: 'bg-destructive',
24+
root: 'bg-destructive/20'
25+
},
26+
info: {
27+
indicator: 'bg-info',
28+
root: 'bg-info/20'
29+
},
30+
primary: {
31+
indicator: 'bg-primary',
32+
root: 'bg-primary/20'
33+
},
34+
secondary: {
35+
indicator: 'bg-secondary-foreground',
36+
root: 'bg-secondary-foreground/20'
37+
},
38+
success: {
39+
indicator: 'bg-success',
40+
root: 'bg-success/20'
41+
},
42+
warning: {
43+
indicator: 'bg-warning',
44+
root: 'bg-warning/20'
45+
}
46+
},
47+
size: {
48+
'2xl': {
49+
root: 'h-4'
50+
},
51+
lg: {
52+
root: 'h-3'
53+
},
54+
md: {
55+
root: 'h-2.5'
56+
},
57+
sm: {
58+
root: 'h-2'
59+
},
60+
xl: {
61+
root: 'h-3.5'
62+
},
63+
xs: {
64+
root: 'h-1.75'
65+
}
66+
}
67+
}
68+
});
69+
70+
export type ProgressSlots = keyof typeof progressVariants.slots;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { ProgressProps as _ProgressProps } from '@radix-ui/react-progress';
2+
3+
import type { BaseNodeProps, ClassValue, ThemeColor } from '@/types/other';
4+
5+
import type { ProgressSlots } from './progress-variants';
6+
7+
export type ProgressClassNames = Partial<Record<ProgressSlots, ClassValue>>;
8+
9+
export interface ProgressProps extends BaseNodeProps<Omit<_ProgressProps, 'children'>> {
10+
classNames?: ProgressClassNames;
11+
color?: ThemeColor;
12+
}

packages/ui/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export * from './components/label';
5252

5353
export * from './components/popover';
5454

55+
export * from './components/progress';
56+
5557
export * from './components/radio';
5658

5759
export * from './components/scroll-area';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { ProgressProps } from 'soybean-react-ui';
2+
import { Card, Progress } from 'soybean-react-ui';
3+
4+
const colors: ProgressProps['color'][] = [
5+
'primary',
6+
'destructive',
7+
'success',
8+
'warning',
9+
'info',
10+
'carbon',
11+
'secondary',
12+
'accent'
13+
];
14+
15+
export const Color = () => {
16+
return (
17+
<Card
18+
split
19+
title="Color"
20+
>
21+
<div className="flex w-[320px] flex-col gap-[12px] lt-sm:w-auto">
22+
{colors.map(color => (
23+
<Progress
24+
color={color}
25+
defaultValue={66}
26+
key={color}
27+
value={50}
28+
/>
29+
))}
30+
</div>
31+
</Card>
32+
);
33+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { ProgressProps } from 'soybean-react-ui';
2+
import { Card, Progress } from 'soybean-react-ui';
3+
4+
const sizes: ProgressProps['size'][] = ['xs', 'sm', 'md', 'lg', 'xl', '2xl'];
5+
6+
const colors: ProgressProps['color'][] = [
7+
'primary',
8+
'destructive',
9+
'success',
10+
'warning',
11+
'info',
12+
'carbon',
13+
'secondary',
14+
'accent'
15+
];
16+
17+
export const Size = () => {
18+
return (
19+
<Card
20+
split
21+
title="Size"
22+
>
23+
<div className="flex w-[320px] flex-col gap-[12px] lt-sm:w-auto">
24+
{sizes.map((size, index) => (
25+
<Progress
26+
color={colors[index]}
27+
defaultValue={66}
28+
key={size}
29+
size={size}
30+
value={50}
31+
/>
32+
))}
33+
</div>
34+
</Card>
35+
);
36+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Color } from './modules/Color';
2+
import { Size } from './modules/Size';
3+
4+
export default function ProgressPage() {
5+
return (
6+
<div className="flex-c gap-4">
7+
<Color />
8+
9+
<Size />
10+
</div>
11+
);
12+
}

pnpm-lock.yaml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)