MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / ColorsPanel

Function ColorsPanel

packages/plugin-ui/src/components/ColorsPanel.tsx:4–81  ·  view source on GitHub ↗
(props: {
  colors: SolidColorConversion[];
  onColorClick: (color: string) => void;
})

Source from the content-addressed store, hash-verified

2import { SolidColorConversion } from "types";
3
4const ColorsPanel = (props: {
5 colors: SolidColorConversion[];
6 onColorClick: (color: string) => void;
7}) => {
8 const [isPressed, setIsPressed] = useState(-1);
9
10 const handleButtonClick = (value: string, idx: number) => {
11 setIsPressed(idx);
12 setTimeout(() => setIsPressed(-1), 250);
13 props.onColorClick(value);
14 };
15
16 // Helper function to format complex color values
17 const formatColorValue = (value: string) => {
18 // Extract CSS variable name if present
19 if (value.includes("var(--")) {
20 const varMatch = value.match(/var\(--([\w-]+)/);
21 return varMatch ? `--${varMatch[1]}` : value;
22 }
23 return value;
24 };
25
26 return (
27 <div className="bg-card border w-full rounded-lg p-3 flex flex-col gap-2">
28 <div className="p-0 pb-2">
29 <div className="flex items-center justify-between">
30 <h2 className="text-lg font-semibold text-foreground flex items-center gap-2">
31 Color Palette
32 </h2>
33 <span className="text-xs bg-muted dark:bg-muted px-2 py-1 rounded-xl text-muted-foreground">
34 {props.colors.length} color{props.colors.length > 1 ? "s" : ""}
35 </span>
36 </div>
37 </div>
38
39 <div className="grid grid-cols-3 gap-2">
40 {props.colors.map((color, idx) => (
41 <button
42 key={"button" + idx}
43 className={`w-full h-16 rounded-lg text-sm font-semibold shadow-sm transition-all duration-300 ${
44 isPressed === idx
45 ? "ring-4 ring-primary ring-opacity-50 animate-pulse"
46 : "ring-0"
47 }`}
48 style={{ backgroundColor: color.hex }}
49 onClick={() => {
50 handleButtonClick(color.exportValue, idx);
51 }}
52 title={color.exportValue} // Show full value on hover
53 >
54 <div className="flex flex-col h-full justify-center items-center">
55 <span
56 className={`text-xs font-semibold ${
57 color.contrastWhite > color.contrastBlack
58 ? "text-white"
59 : "text-black"
60 }`}
61 >

Callers

nothing calls this directly

Calls 2

formatColorValueFunction · 0.85
handleButtonClickFunction · 0.70

Tested by

no test coverage detected