forked from sparkbox/logo-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent.html
256 lines (241 loc) · 6.16 KB
/
component.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Web Component Logo</title>
<link rel="stylesheet" type="text/css" href="all.css">
<style>
.subtitle {
text-align: center;
margin-bottom: 4em;
}
.block-title {
margin-top: 0;
}
.el-source {
font-weight: bold;
font-size: 16px;
margin-bottom: 0;
}
.wrapper {
max-width: 490px;
margin: 0 auto;
}
.contents {
text-align: center;
}
.select {
min-width: 75px;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var select = document.getElementById('select');
select.addEventListener('change', function(e) {
var value = select.value;
if (value === 'dark' || value === 'light') {
var component = document.querySelector('sparkbox-logo');
component.setAttribute("theme", value);
}
});
});
</script>
</head>
<body>
<div class="wrapper clearfix">
<h1 class="title">Web Component Logo</h1>
<p class="subtitle">(best viewed in Chrome)</p>
<div class="contents">
<sparkbox-logo theme="dark"></sparkbox-logo>
<pre class="el-source"><code>
<sparkbox-logo theme="dark">
</code></pre>
<code class="demo">theme="</code>
<select id="select" class="select">
<option value="dark">dark</option>
<option value="light">light</option>
</select>
<code>"</code>
</div>
</div>
<template>
<style type="text/css">
/* Border-box rules */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
/* Defines the "B" in the logo */
#sparkbox {
margin: 0 auto;
width: 186px;
height: 186px;
padding: 45px;
border-radius: 4px;
position: relative;
}
#sparkbox::before,
#sparkbox::after {
display: block;
height: 36px;
width: 100%;
border-width: 8px;
border-style: solid;
border-radius: 0 22px 22px 0;
content: '';
}
#sparkbox::before {
margin-bottom: 24px;
}
/* Defines the top of the lightning bolt */
.zig {
content: "";
position: absolute;
top: 18px;
left: 36px;
border-width: 79px 79px 0 0;
border-style: solid;
-webkit-transform: skewX(-26deg);
-moz-transform: skewX(-26deg);
transform: skewX(-26deg);
}
.zig::before {
content: "";
position: absolute;
top: -52px;
left: 24px;
border-width: 44px 44px 0 0;
border-style: solid;
}
.zig::after {
content: "";
position: absolute;
top: -16px;
left: 64px;
height: 8px;
width: 20px;
display: block;
-webkit-transform: skewX(26deg);
-moz-transform: skewX(26deg);
transform: skewX(26deg);
}
/* Defines the bottom of the lightning bolt */
.zag {
content: "";
position: absolute;
top: 89px;
left: 61px;
border-width: 0 0 79px 79px;
border-style: solid;
-webkit-transform: skewX(-26deg);
-moz-transform: skewX(-26deg);
transform: skewX(-26deg);
}
.zag::before {
content: "";
position: absolute;
top: 8px;
left: -68px;
border-width: 0 0 44px 44px;
border-style: solid;
}
.zag::after {
content: "";
position: absolute;
top: 8px;
left: -84px;
height: 8px;
width: 20px;
display: block;
-webkit-transform: skewX(26deg);
-moz-transform: skewX(26deg);
transform: skewX(26deg);
}
/* Themes */
.dark {
background-color: #252525;
}
.dark#sparkbox::before,
.dark#sparkbox::after {
border-color: #e3e3e3;
}
.dark .zig {
border-color: transparent #e3e3e3;
}
.dark .zig::before {
border-color: transparent #252525;
}
.dark .zig::after {
background-color: #252525;
}
.dark .zag {
border-color: transparent #e3e3e3;
}
.dark .zag::before {
border-color: transparent #252525;
}
.dark .zag::after {
background-color: #252525;
}
.light {
background-color: #e3e3e3;
}
.light#sparkbox::before,
.light#sparkbox::after {
border-color: #252525;
}
.light .zig {
border-color: transparent #252525;
}
.light .zig::before {
border-color: transparent #e3e3e3;
}
.light .zig::after {
background-color: #e3e3e3;
}
.light .zag {
border-color: transparent #252525;
}
.light .zag::before {
border-color: transparent #e3e3e3;
}
.light .zag::after {
background-color: #e3e3e3;
}
</style>
<div id="sparkbox" class="">
<div class="zig"></div>
<div class="zag"></div>
</div>
</template>
<script>
// Get the contents of our template.
var tmpl = document.querySelector('template');
// Create a prototype for a new element that extends HTMLElement.
var logoPrototype = Object.create(HTMLElement.prototype);
logoPrototype.updateTheme = function updateTheme(theme) {
var shdw = this.shadowRoot;
shdw.querySelector('#sparkbox').className = '';
shdw.querySelector('#sparkbox').classList.add(theme);
};
// Setup our Shadow DOM and clone the template
logoPrototype.createdCallback = function() {
var root = this.createShadowRoot();
root.appendChild(document.importNode(tmpl.content, true));
};
logoPrototype.attachedCallback = function() {
var theme = this.getAttribute('theme');
this.updateTheme(theme);
}
logoPrototype.attributeChangedCallback = function(name, oldVal, newVal) {
this.updateTheme(newVal);
}
// Register the new element.
var logo = document.registerElement('sparkbox-logo', {
prototype: logoPrototype
});
</script>
</body>
</html>