Skip to content

Commit 51abbd7

Browse files
authored
Merge pull request #34 from apsinghdev/Add/canvas-color
connect canvasColor UI with functionality
2 parents 65e96de + 61581be commit 51abbd7

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

client/src/atoms.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ export const eraserState = atom({
88
export const cursorPosition = atom({
99
key: "cursor-position",
1010
default: {x: 0, y: 0}
11-
})
11+
})
12+
13+
export const canvasColors = atom({
14+
key: "canvasColor",
15+
default: "#D2B55B",
16+
});

client/src/components/Canvas.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/* eslint-disable react/prop-types */
22
import Menu from "./Menu";
3+
import { useRecoilValue } from "recoil";
4+
import { canvasColors } from "../atoms";
35

46
function Canvas(props){
7+
const canvasColor = useRecoilValue(canvasColors);
58
return (
69
<div className="flex justify-center items-center h-full w-80vw overflow-hidden">
710
<canvas
8-
className="h-full w-86vw bg-yellow-600"
11+
className="h-full w-86vw"
12+
style={{backgroundColor: `${canvasColor}`}}
913
ref={props.canvasRef}
1014
></canvas>
1115
{props.showMenu && <Menu></Menu>}

client/src/components/CanvasColor.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
/* eslint-disable react/prop-types */
2+
import { useRecoilState } from "recoil";
3+
import { canvasColors } from "../atoms";
4+
5+
26
function CanvasColor(props) {
7+
8+
const [canvasColor, setCanvasColor] = useRecoilState(canvasColors);
9+
10+
function changeHandler(e){
11+
setCanvasColor(e.target.value);
12+
}
13+
314
return (
415
<div className="flex p-1 items-center justify-around mt-3">
516
<h1 className="font-sans text-lg antialiased font-semibold text-white">
617
{props.name}
718
</h1>
819
<input
920
type="color"
10-
value={props.defaultColor}
21+
value={canvasColor}
22+
onChange={changeHandler}
1123
className="p-1 h-10 w-10 block bg-white border border-gray-800 cursor-pointer rounded-lg disabled:opacity-50 disabled:pointer-events-none dark:bg-neutral-800 dark:border-neutral-700"
1224
></input>
1325
</div>

0 commit comments

Comments
 (0)