-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.js
39 lines (29 loc) · 1.08 KB
/
history.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Color from 'colorjs.io'
// TODO: utilise <template>
function addToHistory(color) {
const historyItem = document.createElement("tr");
const swatch = document.createElement("td");
const info = document.createElement("td");
const actions = document.createElement("td");
const buttons = {
fill: document.createElement("button"),
};
swatch.classList.add("swatch");
swatch.style.setProperty("background-color", color.display());
info.textContent = color.to(options["color-space"].value);
buttons.fill.textContent = "Fill " + color.toString({ format: "hex" });
buttons.fill.setAttribute("data-action", "fill");
buttons.fill.setAttribute("type", "button");
buttons.fill.addEventListener("click", function (event) {
document.body.style.setProperty("background-color", color.display());
});
actions.appendChild(buttons.fill);
historyItem.appendChild(swatch);
historyItem.appendChild(info);
historyItem.appendChild(actions);
document.querySelector("#color-history tbody").appendChild(historyItem);
historyItem.scrollIntoView();
}
export {
addToHistory
};