-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
313 lines (286 loc) · 10.6 KB
/
index.html
File metadata and controls
313 lines (286 loc) · 10.6 KB
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>slideVars - Automatic Sliders for CSS Custom Properties</title>
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Work+Sans:wght@300;400;500;600&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="./index.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/syntax-highlight-element@1/dist/themes/prettylights.min.css"
/>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/syntax-highlight-element@1/+esm"
></script>
</head>
<body>
<div class="hero">
<slidevars-logo class="hero-logo" open="true"></slidevars-logo>
<h1>slideVars</h1>
<p>
Interactive UI controls for your CSS <code>--custom-properties</code>,
<em>automatically</em>. From your pals at
<a href="https://codepen.io"
><svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 138 26"
fill="none"
stroke="#fff"
stroke-width="2.3"
stroke-linecap="round"
stroke-linejoin="round"
style="width: 140px; vertical-align: middle; margin-top: -2px"
>
<path
d="M80 6h-9v14h9 M114 6h-9 v14h9 M111 13h-6 M77 13h-6 M122 20V6l11 14V6 M22 16.7L33 24l11-7.3V9.3L33 2L22 9.3V16.7z M44 16.7L33 9.3l-11 7.4 M22 9.3l11 7.3 l11-7.3 M33 2v7.3 M33 16.7V24 M88 14h6c2.2 0 4-1.8 4-4s-1.8-4-4-4h-6v14 M15 8c-1.3-1.3-3-2-5-2c-4 0-7 3-7 7s3 7 7 7 c2 0 3.7-0.8 5-2 M64 13c0 4-3 7-7 7h-5V6h5C61 6 64 9 64 13z"
/></svg></a
>.
</p>
<div class="install-command">npm install @codepen/slidevars</div>
<div class="code-block">
<!-- prettier-ignore -->
<syntax-highlight language="js"
>import { slideVars } from "@codepen/slidevars";
slideVars.init(); // That's it!</syntax-highlight
>
</div>
<p>
<a href="https://codepen.io/chriscoyier/pen/raLxxRY"
>Basic Usage Pen ↗</a
>
·
<a href="https://github.com/codepen/slideVars">GitHub</a> ·
<a href="https://www.npmjs.com/package/@codepen/slidevars">npm</a>
</p>
</div>
<div class="container">
<section class="section">
<h2>Live Demo</h2>
<p>
<strong
>Click the
<slidevars-logo class="inline-logo"></slidevars-logo>
button in the top right</strong
>
to open the controls. Move the sliders (and pick colors) to see the
changes reflected in the demo below.
</p>
<div class="demo-tabs" role="tablist" aria-label="Demo examples">
<button
class="tab-button active"
data-tab="auto"
role="tab"
aria-selected="true"
aria-controls="auto-tab"
id="auto-tab-button"
>
Auto-Detection
</button>
<button
class="tab-button"
data-tab="manual"
role="tab"
aria-selected="false"
aria-controls="manual-tab"
id="manual-tab-button"
>
Manual Configuration
</button>
</div>
<!-- Auto Detection Tab -->
<div
class="tab-content active"
id="auto-tab"
role="tabpanel"
aria-labelledby="auto-tab-button"
>
<h3>Auto-Detection Example</h3>
<p>
Just define CSS variables in your stylesheet. SlideVars figures out
the rest:
</p>
<div class="demo-area">
<div class="demo-box" id="auto-demo">Auto!</div>
</div>
<div class="code-block">
<pre class="live-css">/* Your CSS */
:root {
--size: <span class="live-value" data-var="--size"></span>;
--bg: <span class="live-value" data-var="--bg"></span>;
--border-radius: <span class="live-value" data-var="--border-radius"></span>;
--rotation: <span class="live-value" data-var="--rotation"></span>;
--shadow-size: <span class="live-value" data-var="--shadow-size"></span>;
}</pre>
</div>
<!-- prettier-ignore -->
<syntax-highlight language="js">/* Your JavaScript */
import { slideVars } from "@codepen/slidevars";
slideVars.init(); // Auto-detects all variables!</syntax-highlight>
</div>
<!-- Manual Configuration Tab -->
<div
class="tab-content"
id="manual-tab"
role="tabpanel"
aria-labelledby="manual-tab-button"
hidden
>
<h3>Manual Configuration Example</h3>
<p>
For more control, configure each variable manually with custom
ranges:
</p>
<div class="demo-area">
<div class="manual-demo" id="manual-demo">Manual</div>
</div>
<div class="code-block">
<!-- prettier-ignore -->
<syntax-highlight language="js">slideVars.init({
"--width": {
type: "slider",
min: 50,
max: 400,
default: 100,
unit: "px",
scope: "#manual-demo"
},
"--bg": {
type: "color",
default: "#667eea",
scope: "#manual-demo"
}
});</syntax-highlight>
</div>
</div>
</section>
<!-- Manual Placement -->
<section class="section">
<h2>Advanced</h2>
<h3>Manual Placement</h3>
<p>
You can manually place the
<code><slide-vars></code>
element wherever you want HTML (rather than it being auto-injected
into the bottom of the <code><body></code>). Children will be
slotted into the top of the control panel.
</p>
<div class="code-block">
<!-- prettier-ignore -->
<syntax-highlight language="html"><slide-vars>
<p>Welcome to the fun zone.</p>
</slide-vars></syntax-highlight>
</div>
<h3>Options</h3>
<p>The second parameter to `init()` accepts options:</p>
<div class="code-block">
<!-- prettier-ignore -->
<syntax-highlight language="js">slideVars.init({
/* Manual custom property config, see above. */
}, {
defaultOpen: false, // Optional: set to true to show controls on load
auto: false, // Optional: do automatic detection of custom properties, combining with manual config (manual config takes precedence)
scope: "#manual-demo", // Optional: select a specific element to read ALL variables from. Individual scope set on specific custom properties takes precedence.
filterVariables: ["--arc-"], // Optional: exclude variables with specific prefixes from auto-detection
});</syntax-highlight>
</div>
</section>
<section class="section">
<h2>Supported Values</h2>
<h3>Length Units</h3>
<p>
Auto-detected sliders support all
<a
href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Values_and_units/Numeric_data_types"
target="_blank"
rel="noopener"
>CSS numeric data types</a
>
with intelligent default ranges:
</p>
<ul>
<li>
<strong>Absolute:</strong> <code>px</code>, <code>cm</code>,
<code>mm</code>, <code>in</code>, <code>pt</code>, <code>pc</code>,
<code>Q</code>
</li>
<li>
<strong>Font-relative:</strong> <code>em</code>, <code>rem</code>,
<code>ex</code>, <code>ch</code>, <code>cap</code>, <code>lh</code>,
and root variants (<code>rex</code>, <code>rch</code>, etc.)
</li>
<li>
<strong>Viewport:</strong> <code>vw</code>, <code>vh</code>,
<code>vmin</code>, <code>vmax</code>, and variants
(<code>svw</code>, <code>lvh</code>, <code>dvw</code>, etc.)
</li>
<li>
<strong>Container:</strong> <code>cqw</code>, <code>cqh</code>,
<code>cqi</code>, <code>cqb</code>, <code>cqmin</code>,
<code>cqmax</code>
</li>
<li>
<strong>Angle:</strong> <code>deg</code>, <code>grad</code>,
<code>rad</code>, <code>turn</code>
</li>
<li><strong>Time:</strong> <code>s</code>, <code>ms</code></li>
<li><strong>Frequency:</strong> <code>Hz</code>, <code>kHz</code></li>
<li>
<strong>Resolution:</strong> <code>dpi</code>, <code>dpcm</code>,
<code>dppx</code>
</li>
<li><strong>Percentage:</strong> <code>%</code></li>
<li><strong>Grid:</strong> <code>fr</code></li>
</ul>
<p>
<strong>💡 Smart Adaptation:</strong> Ranges automatically expand if
the current value is outside the defaults.
</p>
<h3>Color Values</h3>
<p>Auto-detected color variables support:</p>
<ul>
<li>
<strong>Hex:</strong> <code>#rgb</code>, <code>#rrggbb</code>,
<code>#rrggbbaa</code>
</li>
<li>
<strong>Functional:</strong> <code>rgb()</code>,
<code>rgba()</code>, <code>hsl()</code>, <code>hsla()</code>
</li>
<li>
<strong>Modern Color Spaces:</strong> <code>oklch()</code>,
<code>oklab()</code>, <code>lch()</code>, <code>lab()</code>,
<code>hwb()</code>, <code>color()</code>
<span style="font-size: 0.9em; opacity: 0.8"
>✨ Uses advanced color picker with gamut mapping</span
>
</li>
<li>
<strong>Named:</strong> standard CSS named colors (including
<code>transparent</code> and <code>currentColor</code>)
</li>
</ul>
</section>
<section class="section">
<h2>Programmatic Control</h3>
<div class="code-block">
<!-- prettier-ignore -->
<syntax-highlight language="js"
>slideVars.open(); // Open the controls panel
slideVars.close(); // Close the controls panel
slideVars.toggle(); // Toggle open/closed
slideVars.destroy(); // Remove component from DOM</syntax-highlight
>
</div>
</section>
</div>
<script type="module" src="./index.js"></script>
</body>
</html>