color-picker-demo.tsx
color-picker.tsx
prompt.md
Collapse
Reset
Copy Code
Download
Run
1
"use client";
2
3
import * as React from "react"
4
import { createPortal } from "react-dom"
5
import { ColorPicker } from "./color-picker"
6
import { Select } from "./select"
7
8
export function ColorPickerDemo() {
9
const [mounted, setMounted] = React.useState(false)
10
const [mode, setMode] = React.useState("solid")
11
12
React.useEffect(() => {
13
setMounted(true)
14
}, [])
15
16
// Custom Controls to render in the right panel portal
17
const controls = (
18
<div className="flex flex-col gap-5 mt-6 border-t border-black/5 dark:border-white/5 pt-6">
19
<div className="flex items-center gap-2 text-[13px] font-semibold text-[#1F1F1F] dark:text-[#D4D4D8]">
20
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="text-[#9FE870]"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>
21
Preview
22
</div>
23
24
<div className="flex flex-col gap-2">
25
<Select
26
value={mode}
27
onValueChange={setMode}
28
options={[
29
{ value: "solid", label: "Solid" },
30
{ value: "gradient", label: "Gradient" }
31
]}
32
className="w-full"
33
/>
34
</div>
35
</div>
36
)
37
38
const portalTarget = typeof document !== "undefined" ? document.getElementById("custom-controls-portal") : null
39
40
return (
41
<div className="w-full h-full flex items-center justify-center p-4 sm:p-6 md:p-8 bg-zinc-50 dark:bg-[#141414]">
42
{mounted && portalTarget && createPortal(controls, portalTarget)}
43
44
<ColorPicker mode={mode as "solid" | "gradient"} />
45
</div>
46
)
47
}
48

