-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.html
More file actions
519 lines (456 loc) · 16.5 KB
/
docs.html
File metadata and controls
519 lines (456 loc) · 16.5 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React Dark Mode Toggle Demo | @gozenc/react-dark-mode</title>
<meta name="description"
content="Interactive playground for the @gozenc/react-dark-mode toggle — a 4.56 KB (1.76 KB gzipped) React theme switcher with polished animations and full customization.">
<meta name="keywords"
content="@gozenc/react-dark-mode, react dark mode toggle, react theme switch, dark mode component, theme button demo">
<meta name="author" content="gozenc">
<meta name="robots" content="index,follow">
<meta name="theme-color" content="#1565c0">
<link rel="canonical" href="https://react-dark-mode-toggle.pages.dev">
<meta property="og:type" content="website">
<meta property="og:title" content="React Dark Mode Toggle Demo">
<meta property="og:description"
content="Preview the @gozenc/react-dark-mode component — just 4.56 KB (1.76 KB gzipped) with smooth, accessible animations.">
<meta property="og:url" content="https://react-dark-mode-toggle.pages.dev">
<meta property="og:image" content="https://react-dark-mode-toggle.pages.dev/demo.gif">
<meta property="og:site_name" content="@gozenc/react-dark-mode">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="React Dark Mode Toggle Demo">
<meta name="twitter:description"
content="Try the featherlight @gozenc/react-dark-mode toggle — 4.56 KB (1.76 KB gzipped) and packed with customization.">
<meta name="twitter:image" content="https://react-dark-mode-toggle.pages.dev/demo.gif">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "@gozenc/react-dark-mode",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "Cross-platform",
"description": "React dark mode toggle component with animated, accessible theme switching and a 4.56 KB (1.76 KB gzipped) footprint.",
"softwareVersion": "0.0.8",
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "USD"
},
"downloadUrl": "https://www.npmjs.com/package/@gozenc/react-dark-mode-toggle",
"publisher": {
"@type": "Organization",
"name": "gozenc",
"url": "https://github.com/gozenc"
}
}
</script>
<style>
:root {
color-scheme: light dark;
}
body {
margin: 0;
padding: 2.5rem 1.5rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
background: linear-gradient(135deg, #f5f5f5 0%, #ffffff 100%);
color: #1f2933;
transition: background-color 0.3s ease, color 0.3s ease;
}
.dark body {
background: radial-gradient(circle at top, #1f1f1f 0%, #0d0d0d 100%);
color: #f8fafc;
}
.container {
max-width: 960px;
margin: 0 auto;
text-align: center;
display: grid;
gap: 2rem;
}
h1 {
margin: 0;
font-size: clamp(2rem, 3vw, 3rem);
letter-spacing: -0.03em;
}
h2 {
margin-bottom: 0.75rem;
letter-spacing: -0.01em;
}
p.lead {
margin: 0 auto;
max-width: 540px;
color: #475569;
}
.dark p.lead {
color: #cbd5f5;
}
.demo-section {
margin: 0;
padding: 2.5rem 2rem;
border-radius: 18px;
box-shadow: 0 18px 45px rgba(31, 41, 55, 0.12);
transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
position: relative;
overflow: hidden;
backdrop-filter: blur(6px);
}
.dark .demo-section {
box-shadow: 0 18px 45px rgba(15, 23, 42, 0.45);
}
.demo-section::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), transparent 55%);
pointer-events: none;
}
.palette-sky {
background: linear-gradient(135deg, rgba(227, 242, 253, 0.9), rgba(187, 222, 251, 0.95));
color: #0f1f3d;
}
.dark .palette-sky {
background: linear-gradient(135deg, rgba(13, 71, 161, 0.75), rgba(21, 101, 192, 0.85));
color: #e3f2fd;
}
.palette-grape {
background: linear-gradient(135deg, rgba(243, 229, 245, 0.9), rgba(225, 190, 231, 0.95));
color: #311b64;
}
.dark .palette-grape {
background: linear-gradient(135deg, rgba(81, 45, 109, 0.8), rgba(123, 31, 162, 0.85));
color: #f3e5f5;
}
.palette-warm {
background: linear-gradient(135deg, rgba(255, 241, 212, 0.92), rgba(255, 224, 178, 0.95));
color: #5b3415;
}
.dark .palette-warm {
background: linear-gradient(135deg, rgba(191, 87, 0, 0.85), rgba(255, 111, 0, 0.78));
color: #fff3e0;
}
.palette-carbon {
background: linear-gradient(135deg, rgba(244, 245, 247, 0.95), rgba(226, 232, 240, 0.92));
color: #111827;
}
.dark .palette-carbon {
background: linear-gradient(135deg, rgba(15, 23, 42, 0.85), rgba(30, 41, 59, 0.88));
color: #f8fafc;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
gap: 1.5rem;
margin: 1.5rem 0 0;
position: relative;
z-index: 1;
}
.toggle-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
padding: 1rem 1.25rem;
border-radius: 14px;
background: rgba(255, 255, 255, 0.55);
box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
min-width: 96px;
}
.dark .toggle-card {
background: rgba(15, 23, 42, 0.55);
box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
}
.chip {
font-size: 0.75rem;
letter-spacing: 0.08em;
text-transform: uppercase;
font-weight: 600;
padding: 0.35rem 0.6rem;
border-radius: 999px;
background: rgba(15, 23, 42, 0.08);
color: inherit;
}
.dark .chip {
background: rgba(148, 163, 184, 0.16);
}
.status {
padding: 1.25rem;
margin: 0;
border-radius: 14px;
background: linear-gradient(135deg, rgba(227, 242, 253, 0.9), rgba(209, 233, 252, 0.9));
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
text-align: left;
}
.status strong {
display: inline-block;
min-width: 7.5rem;
}
.dark .status {
background: linear-gradient(135deg, rgba(21, 101, 192, 0.75), rgba(13, 71, 161, 0.78));
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.status p {
margin: 0.35rem 0;
}
.page-footer {
margin: 0;
padding: 2rem 0 1rem;
color: #64748b;
font-size: 0.95rem;
line-height: 1.6;
}
.page-footer code {
background: rgba(15, 23, 42, 0.08);
padding: 0.25rem 0.4rem;
border-radius: 6px;
font-size: 0.9rem;
}
.page-footer a {
color: #1565c0;
text-decoration: none;
font-weight: 600;
}
.page-footer a:hover {
text-decoration: underline;
}
.dark .page-footer {
color: #cbd5f5;
}
.dark .page-footer code {
background: rgba(148, 163, 184, 0.18);
}
.dark .page-footer a {
color: #9cc4ff;
}
@media (max-width: 640px) {
body {
padding: 2rem 1rem;
}
.demo-section {
padding: 2rem 1.5rem;
}
}
</style>
</head>
<body>
<main class="container" role="main">
<header>
<h1>@gozenc/react-dark-mode-toggle</h1>
<h2>Live Demo & QA Playground</h2>
<p class="lead">Explore the animated React dark mode toggle that powers @gozenc/react-dark-mode. It ships at just
4.56 KB (1.76 KB gzipped) yet delivers smooth, accessible theme switching for any design system.</p>
</header>
<div class="status">
<p><strong>Bundle Size:</strong> <span id="bundle-size">4.56 KB (1.76 KB gzipped)</span></p>
<p><strong>Status:</strong> <span id="status">Loading...</span></p>
</div>
<section class="demo-section palette-carbon">
<h2>Default Toggle</h2>
<p>Click the toggle to flip the document theme. This uses the library defaults.</p>
<div class="toggle-row">
<span class="chip">Light</span>
<div id="toggle-1"></div>
<span class="chip">Dark</span>
</div>
</section>
<section class="demo-section palette-sky">
<h2>Custom Sizes</h2>
<p>Different `size` values rendered side by side.</p>
<div class="toggle-row" id="toggle-2"></div>
</section>
<section class="demo-section palette-grape">
<h2>Color Palettes</h2>
<p>Brand-friendly background / icon colors with hover overrides.</p>
<div class="toggle-row" id="toggle-3"></div>
</section>
<section class="demo-section palette-warm">
<h2>Radius & Padding</h2>
<p>Demonstrates the optional `radius` and `padding` props working together.</p>
<div class="toggle-row" id="toggle-4"></div>
</section>
<footer class="page-footer">
<p>Install the package with <code>npm install @gozenc/react-dark-mode-toggle</code> and drop the component into
your
app to give users a delightful theme switch.</p>
<p><a href="https://www.npmjs.com/package/@gozenc/react-dark-mode-toggle">View the npm package</a> · <a
href="https://github.com/gozenc/react-dark-mode-toggle">Browse the source on GitHub</a></p>
</footer>
</main>
<!-- React CDN -->
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<!-- Import map to resolve React modules -->
<script type="importmap">
{
"imports": {
"react": "data:text/javascript,export default window.React; export const createElement = window.React.createElement; export const useEffect = window.React.useEffect; export const useRef = window.React.useRef; export const useState = window.React.useState; export const Fragment = window.React.Fragment;",
"react-dom": "data:text/javascript,export const createPortal = window.ReactDOM.createPortal;"
}
}
</script>
<script type="module">
try {
// Get bundle size first
const response = await fetch('./dist/index.js');
const text = await response.text();
const sizeKB = (text.length / 1024).toFixed(2);
const sizeGzipped = await getGzippedSize(text);
// Check for react-jsx-runtime
const hasJsxRuntime = text.includes('react-jsx-runtime') || text.includes('jsx-runtime');
const runtimeStatus = hasJsxRuntime ? '❌ YES (should be excluded)' : '✅ NO (correctly excluded)';
document.getElementById('bundle-size').innerHTML = `${sizeKB} KB (${sizeGzipped} KB gzipped)`;
document.getElementById('status').innerHTML = `Loading component...<br>React JSX Runtime: ${runtimeStatus}`;
// Import the built component
const { DarkModeToggle } = await import('./dist/index.js');
document.getElementById('status').innerHTML = `✅ Component loaded successfully!<br>React JSX Runtime: ${runtimeStatus}`;
// Create React elements
const { createElement } = React;
const { createRoot } = ReactDOM;
const fragment = (children) => createElement(React.Fragment, null, ...children);
// Default toggle
const root1 = createRoot(document.getElementById('toggle-1'));
root1.render(createElement(DarkModeToggle, {
onModeChange: (mode) => console.log('Mode changed to:', mode)
}));
// Custom size gallery
const root2 = createRoot(document.getElementById('toggle-2'));
root2.render(fragment([
createElement('div', { className: 'toggle-card', key: 'size-16' },
createElement(DarkModeToggle, { size: 16 }),
createElement('span', { className: 'chip' }, '16px')
),
createElement('div', { className: 'toggle-card', key: 'size-24' },
createElement(DarkModeToggle, { size: 24 }),
createElement('span', { className: 'chip' }, '24px')
),
createElement('div', { className: 'toggle-card', key: 'size-32' },
createElement(DarkModeToggle, { size: 32 }),
createElement('span', { className: 'chip' }, '32px')
),
createElement('div', { className: 'toggle-card', key: 'size-48' },
createElement(DarkModeToggle, { size: 48 }),
createElement('span', { className: 'chip' }, '48px')
)
]));
// Custom colors
const root3 = createRoot(document.getElementById('toggle-3'));
root3.render(fragment([
createElement('div', { className: 'toggle-card', key: 'sky' },
createElement(DarkModeToggle, {
colors: {
backgroundColor: '#e3f2fd',
backgroundColorDark: '#1565c0',
color: '#1976d2',
colorHover: '#0d47a1',
colorDark: '#bbdefb',
colorHoverDark: '#e3f2fd'
}
}),
createElement('span', { className: 'chip' }, 'Sky')
),
createElement('div', { className: 'toggle-card', key: 'grape' },
createElement(DarkModeToggle, {
colors: {
backgroundColor: '#f3e5f5',
backgroundColorDark: '#7b1fa2',
color: '#9c27b0',
colorHover: '#b863ddff',
colorDark: '#e1bee7',
colorHoverDark: '#d1a1daff'
}
}),
createElement('span', { className: 'chip' }, 'Grape')
),
createElement('div', { className: 'toggle-card', key: 'mint' },
createElement(DarkModeToggle, {
colors: {
backgroundColor: '#e0f7f4',
backgroundColorDark: '#00695c',
color: '#009688',
colorHover: '#004d40',
colorDark: '#b2dfdb',
colorHoverDark: '#80cbc4'
}
}),
createElement('span', { className: 'chip' }, 'Mint')
)
]));
// Radius & padding variations
const root4 = createRoot(document.getElementById('toggle-4'));
root4.render(fragment([
createElement('div', { className: 'toggle-card', key: 'rounded' },
createElement(DarkModeToggle, {
radius: '8px',
padding: 6,
colors: {
backgroundColor: '#fff7ed',
backgroundColorDark: '#ff6f00',
color: '#fb8c00',
colorHover: '#ef6c00',
colorDark: '#ffe0b2',
colorHoverDark: '#fff3e0'
}
}),
createElement('span', { className: 'chip' }, 'Soft 8px')
),
createElement('div', { className: 'toggle-card', key: 'pill' },
createElement(DarkModeToggle, {
radius: '999px',
padding: 10,
colors: {
backgroundColor: '#fef3c7',
backgroundColorDark: '#d97706',
color: '#f59e0b',
colorHover: '#c2410c',
colorDark: '#fde68a',
colorHoverDark: '#fff7cc'
}
}),
createElement('span', { className: 'chip' }, 'Pill 999px')
),
createElement('div', { className: 'toggle-card', key: 'edge' },
createElement(DarkModeToggle, {
radius: '2px',
padding: 4,
colors: {
backgroundColor: '#e5e7eb',
backgroundColorDark: '#1f2937',
color: '#111827',
colorHover: '#000000',
colorDark: '#d1d5db',
colorHoverDark: '#f9fafb'
}
}),
createElement('span', { className: 'chip' }, 'Edge 2px')
)
]));
} catch (error) {
console.error('Error loading component:', error);
document.getElementById('status').textContent = 'Error: ' + error.message;
}
async function getGzippedSize(text) {
if ('CompressionStream' in window) {
const stream = new CompressionStream('gzip');
const writer = stream.writable.getWriter();
const reader = stream.readable.getReader();
writer.write(new TextEncoder().encode(text));
writer.close();
let compressedSize = 0;
let done = false;
while (!done) {
const { value, done: readerDone } = await reader.read();
done = readerDone;
if (value) {
compressedSize += value.length;
}
}
return (compressedSize / 1024).toFixed(2);
}
return 'N/A';
}
</script>
</body>
</html>