Skip to content

Commit

Permalink
Fix ColorHandler to adjust to pickr
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiaaziz committed Oct 25, 2023
1 parent 1f647fd commit 80a7ec8
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ Canvas leverages the following technologies:
- Introduce a dotted brush option.

- **Thursday Morning:**
- Bonus: Rewrite this proposal as a production README.
- Rewrite this proposal as a production README.
2 changes: 1 addition & 1 deletion dist/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<!-- pickr -->
<script src="https://cdn.jsdelivr.net/npm/@simonwep/[email protected]/dist/pickr.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@simonwep/[email protected]/dist/themes/classic.min.css" />

<link rel="stylesheet" href="./dist/main.css" />
<script src="./dist/main.js" defer></script>
<title>Canvas</title>
Expand Down Expand Up @@ -32,9 +36,8 @@ <h1>Canvas</h1>
<button id="undo"><img src="assets/menu icons/undo-btn.png" alt=""></button>
<button id="redo"><img src="assets/menu icons/redo-btn.png" alt=""></button>
<!-- color -->
<input type="color" id="color-picker" value="#FFFFFF">
<input type="color" id="background-color-picker" value="#FFFFFF">
<label for="background-color-picker">Bg Color</label>
<div id="color-picker" class="pickr"></div>
<!-- <input type="color" id="color-picker" value="#FFFFFF"> -->
<!-- tools -->
<input type="range" id="size-slider" min="1" max="30" value="5">
<input type="radio" id="brush" name="tool" checked>
Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@simonwep/pickr": "^1.9.0",
"babel-loader": "^9.1.3",
"core-js": "^3.33.0",
"css-loader": "^6.8.1",
Expand Down
10 changes: 1 addition & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import CanvasHandler from "./scripts/canvasHandler";
import ToolIcon from "./scripts/toolIcon";

document.addEventListener("DOMContentLoaded", () => {
new CanvasHandler();
const canvasHandler = new CanvasHandler();
new ToolIcon();
});








50 changes: 23 additions & 27 deletions src/scripts/colorHandler.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
import Pickr from "@simonwep/pickr";

class ColorHandler {
constructor(canvasHandler) {
this.canvasHandler = canvasHandler
this.setupColorHandling()
this.canvasHandler = canvasHandler;
this.setupColorPicker();
this.setupColorHandling();
}

setupColorPicker () {
this.brushColorPicker = Pickr.create({
el: "#color-picker",
theme: "classic",
default: "#ECD1E2",
components: {
preview: true,
hue: true,
},
});
// have the color picker be open immediately
this.brushColorPicker.show();
}

setupColorHandling() {
this.currentColor = "black";

// if a brush color has been selected..
this.brushColorPicker = document.getElementById("color-picker");
this.brushColorPicker.addEventListener("input", () => {
this.currentColor = this.brushColorPicker.value;
// color change event for brush color
this.brushColorPicker.on("change", (color) => {
this.currentColor = color.toHEXA().toString()
});

// if a bg color has been selected..
this.bgColorPicker = document.getElementById("background-color-picker");

// for erase action
this.bgColorPicker.addEventListener(
"input",
() => {
const drawnPaths = this.canvasHandler.undoAndRedoHandler.drawnPaths;
const redoStack = this.canvasHandler.undoAndRedoHandler.redoStack;
this.canvasHandler.eraseAndClearHandler.clear();
this.canvasHandler.undoAndRedoHandler.drawnPaths = drawnPaths;
this.canvasHandler.undoAndRedoHandler.redoStack = redoStack;
this.canvasHandler.undoAndRedoHandler.drawnPaths.forEach((path) =>
this.canvasHandler.undoAndRedoHandler.redrawPath(path)
);
this.canvasHandler.canvas.style.backgroundColor = this.bgColorPicker.value;
}
);
}
}

export default ColorHandler
export default ColorHandler;
4 changes: 2 additions & 2 deletions src/styles/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ button:hover {
transition: 0.5s;
background-color: black;
}

// colors
// TEMP colors
input[type="color"] {
height: 40px;
width: 40px;
Expand Down

0 comments on commit 80a7ec8

Please sign in to comment.