-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcode-preview.tsx
72 lines (62 loc) · 2.02 KB
/
code-preview.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"use client";
import useColors from "@/store/useColors";
import { formatOptions } from "@/config/colors";
import { generateCSSCode, generateTailwindCode } from "@/lib/colors";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { TabCodeProps, TypeFormat } from "@/types/colors";
import TabsCodeViewer from "./tabs-code-viewer";
export default function CodePreview() {
const variables = useColors((state) => state.variables);
const format = useColors((state) => state.format);
const updateFormat = useColors((state) => state.updateFormat);
const handleSelectFormat = (value: TypeFormat) => {
updateFormat(value);
};
const cssGenerated = generateCSSCode(variables, format);
const twConfigGenerated = generateTailwindCode(variables, format);
const tabData: TabCodeProps[] = [
{
tabValue: "account",
label: "tailwind.config.js",
displayCode: twConfigGenerated.display,
copyCode: twConfigGenerated.copy,
language: "javascript",
},
{
tabValue: "password",
label: "globals.css",
displayCode: cssGenerated,
language: "css",
},
];
return (
<div className="flex flex-col h-full lg:h-[820px] mt-3 w-full text-sm relative">
{/* Select - Float top right */}
<div className="z-20 absolute top-0 right-0">
<Select
defaultValue={format}
onValueChange={(value: TypeFormat) => handleSelectFormat(value)}
>
<SelectTrigger className="w-auto sm:w-[150px] h-9">
<span className="hidden sm:block text-slate-500">Format: </span>
<SelectValue placeholder="Select a format" />
</SelectTrigger>
<SelectContent>
{formatOptions.map((option) => (
<SelectItem key={option.label} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<TabsCodeViewer data={tabData} />
</div>
);
}