-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.html
87 lines (82 loc) · 2.85 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>vanilla-colorful</title>
<meta
name="description"
content="A tiny (2,7 KB) color picker web component for modern web apps"
/>
<meta name="keywords" content="color, picker, component, accessible, hex, rgb, hsl, hsv" />
<meta
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
name="viewport"
/>
<meta property="og:image" content="demo/assets/og.png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Recursive&family=PT+Mono&display=swap"
/>
<link rel="stylesheet" href="demo/styles.css" />
</head>
<body>
<div class="wrapper" style="color: var(--contrast, #fff)">
<header class="header">
<div class="demo">
<rgba-color-picker></rgba-color-picker>
</div>
<div class="header-content">
<h1 class="header-title">Vanilla Colorful 🎨</h1>
<p class="header-description">
A tiny framework agnostic color picker. Port of
<a href="https://github.com/omgovich/react-colorful" target="_blank" rel="noreferrer"
>React Colorful</a
>
to vanilla Custom Elements.
</p>
<nav class="links">
<a
href="https://github.com/web-padawan/vanilla-colorful"
target="_blank"
rel="noreferrer"
>
GitHub
</a>
<a
href="https://www.npmjs.com/package/vanilla-colorful"
target="_blank"
rel="noreferrer"
>
NPM
</a>
<a
href="https://fosstodon.org/@kulykov"
target="_blank"
rel="me"
>
Mastodon
</a>
</nav>
</div>
</header>
</div>
<script type="module">
import './rgba-color-picker.js';
import { setFaviconColor } from './demo/favicon.js';
// See http://www.w3.org/TR/AERT#color-contrast
const getBrightness = ({ r, g, b }) => (r * 299 + g * 587 + b * 114) / 1000;
const picker = document.querySelector('rgba-color-picker');
picker.addEventListener('color-changed', (event) => {
const rgba = event.detail.value;
const color = `rgba(${rgba.r}, ${rgba.g}, ${rgba.b}, ${rgba.a})`;
document.body.style.backgroundColor = color;
const contrast = getBrightness(rgba) > 128 || rgba.a < 0.5 ? '#000' : '#fff';
document.body.style.setProperty('--contrast', contrast);
setFaviconColor(color)();
});
picker.color = { r: 30, g: 136, b: 229, a: 1 };
</script>
</body>
</html>