Skip to content

Commit 55f149d

Browse files
committed
feat: add playground component ThemeCustomize
1 parent 13eb34a commit 55f149d

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
'use client';
2+
3+
import { builtinColorMap, builtinRadiuses } from '@soybean-react-ui/tailwind-plugin';
4+
import { useState } from 'react';
5+
import type { ThemeSize } from 'soybean-react-ui';
6+
import { Button, Icon, Label, cn } from 'soybean-react-ui';
7+
8+
const sizes: ThemeSize[] = ['xs', 'sm', 'md', 'lg', 'xl', '2xl'];
9+
10+
const ThemeCustomize = () => {
11+
const [color, setColor] = useState('default');
12+
13+
const [size, setSize] = useState('md');
14+
15+
const [radius, setRadius] = useState(0.5);
16+
17+
return (
18+
<div className="p-4">
19+
<div className="grid space-y-1">
20+
<h1 className="text-md text-foreground font-semibold">Customize</h1>
21+
<p className="text-xs text-muted-foreground">Pick a style and color for your components.</p>
22+
</div>
23+
24+
<div className="pt-6 space-y-1.5">
25+
<Label
26+
className="text-xs"
27+
htmlFor="color"
28+
>
29+
Color
30+
</Label>
31+
32+
<div className="grid grid-cols-3 gap-2 py-1.5">
33+
{Object.entries(builtinColorMap).map(([key, value]) => (
34+
<div
35+
className={key === 'default' ? 'col-span-3' : ''}
36+
key={key}
37+
>
38+
<Button
39+
className={cn('justify-start', key !== 'default' && 'w-full')}
40+
size="sm"
41+
variant={color === key ? 'outline' : 'pure'}
42+
onClick={() => setColor(key)}
43+
>
44+
<span
45+
className="size-4 flex shrink-0 items-center justify-center rounded-full"
46+
style={{ backgroundColor: `hsl(${value})` }}
47+
>
48+
{color === key && (
49+
<Icon
50+
className="size-3 text-white"
51+
icon="lucide:check"
52+
/>
53+
)}
54+
</span>
55+
<span className="ml-2 text-xs capitalize">{key}</span>
56+
</Button>
57+
</div>
58+
))}
59+
</div>
60+
61+
<div className="pt-6 space-y-1.5">
62+
<Label
63+
className="text-xs"
64+
htmlFor="radius"
65+
>
66+
Radius
67+
</Label>
68+
<div className="grid grid-cols-5 gap-2 py-1.5">
69+
{builtinRadiuses.map((r, index) => (
70+
<Button
71+
key={index}
72+
size="sm"
73+
variant={r === radius ? 'outline' : 'pure'}
74+
onClick={() => setRadius(r)}
75+
>
76+
<span className="text-xs">{r}</span>
77+
</Button>
78+
))}
79+
</div>
80+
</div>
81+
82+
<div className="pt-6 space-y-1.5">
83+
<Label
84+
className="text-xs"
85+
htmlFor="size"
86+
>
87+
Size
88+
</Label>
89+
<div className="grid grid-cols-5 gap-2 py-1.5">
90+
{sizes.map((s, index) => (
91+
<Button
92+
key={index}
93+
size="sm"
94+
variant={s === size ? 'outline' : 'pure'}
95+
onClick={() => setSize(s)}
96+
>
97+
<span className="text-xs">{s}</span>
98+
</Button>
99+
))}
100+
</div>
101+
</div>
102+
</div>
103+
</div>
104+
);
105+
};
106+
107+
export default ThemeCustomize;

0 commit comments

Comments
 (0)