-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.html
137 lines (116 loc) · 3.79 KB
/
colors.html
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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Color</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="copy.js"></script>
<script src="https://unpkg.com/@jaames/iro@5"></script>
<style>
section {
grid-template-columns: 1fr 1fr;
grid-gap: 1em;
}
td:first-child {
font-weight: bold;
}
.preview {
aspect-ratio: 5/2;
border-radius: 7px;
margin-bottom: 0.5em;
}
label {
display: block;
margin-top: 1.5em;
}
</style>
</head>
<body>
<header>
<h1><a href="index.html">Tools</a></h1>
</header>
<main>
<header class="bar">
<h2>Colors</h2>
<a href="palette.html" class="button">Open in palette</a>
</header>
<noscript>
<p class="placeholder-text">This tool requires Javascript to work.</p>
</noscript>
<section hidden>
<div id="picker"></div>
<div>
<div class="preview"></div>
<table>
<tr>
<td>Hex</td>
<td onclick="copy(event)" class="hex8"></td>
</tr>
<tr>
<td>RGBa</td>
<td onclick="copy(event)" class="rgba"></td>
</tr>
<tr>
<td>HSLa</td>
<td onclick="copy(event)" class="hsla"></td>
</tr>
</table>
<!-- This works, but I like the clipboard solution better:
<label for="color">Or, set color to:</label>
<input type="text" oninput="handleInput(event)" name="color" placeholder="#777">
-->
<p><kbd>Ctrl + V</kbd> to set color from clipboard.</p>
</div>
</section>
</main>
<script>
document.querySelector("section").style.display = "grid";
const colorPicker = new iro.ColorPicker('#picker', {
color: "#000000",
layoutDirection: "vertical",
layout: [
{ component: iro.ui.Box },
{ component: iro.ui.Slider, options: { sliderType: "hue" } },
{ component: iro.ui.Slider, options: { sliderType: "alpha" } }
]
});
function tick(color) {
setColorPreview(color);
setTableContents(color);
setPaletteLink(color);
}
function setColorPreview(color) {
document.querySelector(".preview").style.background = color.hex8String;
}
function setTableContents(color) {
document.querySelector(".hex8").innerText = color.hex8String;
document.querySelector(".rgba").innerText = color.rgbaString;
document.querySelector(".hsla").innerText = color.hslaString;
}
function setPaletteLink(color) {
const link = document.querySelector("a.button");
link.href = link.href.split('#')[0] + color.hexString;
}
function maybeTick() {
if(location.hash) colorPicker.color.set(location.hash);
tick(colorPicker.color);
}
function handleInput(e) {
colorPicker.color.set(e.target.value);
tick(colorPicker.color);
}
function handlePaste(e) {
const pasted = (e.clipboardData || window.clipboardData).getData("text");
colorPicker.color.set(pasted);
tick(colorPicker.color);
}
colorPicker.on('color:change', tick);
window.onload = maybeTick;
window.addEventListener("hashchange", maybeTick);
document.addEventListener('paste', handlePaste);
</script>
<script src="//instant.page/5.2.0" type="module" integrity="sha384-jnZyxPjiipYXnSU0ygqeac2q7CVYMbh84q0uHVRRxEtvFPiQYbXWUorga2aqZJ0z"></script>
</body>
</html>