generated from daviddarnes/component-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
107 lines (95 loc) · 2.44 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Demo of storage-form Web Component" />
<title>storage-form Web Component Demo</title>
<style>
:root {
color-scheme: light dark;
}
:root:has([value="dark"]:checked) {
color-scheme: dark;
}
:root:has([value="light"]:checked) {
color-scheme: light;
}
:root:has([name="contrast"]:checked) {
font-weight: bold;
}
output {
font-family: monospace;
}
</style>
<script type="module" src="storage-form.js"></script>
</head>
<body>
<h2>General example</h2>
<storage-form>
<form>
<label>
Example
<input type="text" name="example" value="value" />
</label>
<button>Submit</button>
</form>
</storage-form>
<hr />
<h2>
Example of submitting with
<code>change</code>
event instead of a submit button
</h2>
<p>Use case for light/dark mode.</p>
<storage-form>
<form>
<label>
<input type="radio" name="theme" value="dark" />
<span>Dark mode</span>
</label>
<label>
<input type="radio" name="theme" value="light" />
<span>Light mode</span>
</label>
<label>
<input type="radio" name="theme" value="" checked />
<span>Default mode</span>
</label>
<br />
<label>
<input type="hidden" name="contrast" value />
<input type="checkbox" name="contrast" value="true" />
<span>High contrast</span>
</label>
</form>
</storage-form>
<hr />
<h2>
Example of hooking into
<code>storage</code>
event
</h2>
<storage-form>
<form>
<label>
Update the
<code>output</code>
by checking the box
<input type="hidden" name="output" value />
<input type="checkbox" name="output" value="updated" />
</label>
</form>
</storage-form>
<output></output>
<script>
const updatePage = () => {
document.querySelector("output").innerHTML = JSON.stringify(
window.localStorage
);
};
window.addEventListener("storage", updatePage);
updatePage();
</script>
</body>
</html>