Newer
Older
import { useAppContext } from "../../contexts/AppContext";
import { Canvas } from "../../lib/canvas";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faXmark } from "@fortawesome/free-solid-svg-icons";

Grant
committed
import { IPaletteContext } from "@sc07-canvas/lib/src/net";

Grant
committed
const [pallete, setPallete] = useState<IPaletteContext>({});
useEffect(() => {
if (!Canvas.instance) return;
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
}, [pallete]);
return (
<div id="pallete">
<div className="pallete-colors">
<button
aria-label="Deselect Color"
className="pallete-color--deselect"
title="Deselect Color"
onClick={() => {
setPallete(({ color, ...pallete }) => {
return pallete;
});
}}
>
<FontAwesomeIcon icon={faXmark} />
</button>
{config.pallete.colors.map((color) => (
<button
key={color.id}
aria-label={color.name}
className={["pallete-color", color.id === pallete.color && "active"]
.filter((a) => a)
.join(" ")}
style={{
backgroundColor: "#" + color.hex,
}}
title={color.name}
onClick={() => {
setPallete((pallete) => {
return {
...pallete,
color: color.id,
};
});
}}
></button>
))}
</div>
{!user && (
<div className="pallete-user-overlay">
You are not logged in
<a href="/api/login" className="user-login">
Login
</a>
</div>
)}
</div>
);
};