UNPKG

lightview

Version:

A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation

470 lines (428 loc) 22.5 kB
<!-- SEO-friendly SPA Shim --> <script src="/lightview-router.js"></script> <script> if (globalThis.LightviewRouter) { LightviewRouter.base('/index.html'); } </script> <!-- Load the page-specific stylesheet --> <link rel="stylesheet" href="./index.css"> <!-- Gallery Structure --> <div class="gallery-page"> <div class="gallery-layout"> <!-- Sidebar Overlay --> <div id="sidebar-overlay" class="sidebar-overlay"></div> <!-- Sidebar --> <div id="gallery-sidebar" class="gallery-sidebar" style="visibility: hidden" src="./component-nav.html"></div> <!-- Main Content --> <div id="gallery-main" class="gallery-main"> <!-- Header Container --> <div style="position: sticky; top: 0; z-index: 30; background: var(--gallery-surface); border-bottom: 1px solid var(--gallery-border); backdrop-filter: blur(8px);"> <!-- Breadcrumbs Row --> <div style="padding: 0.75rem 1.5rem 0;"> <script> (() => { const { Breadcrumbs } = Lightview.tags; const breadcrumbs = Breadcrumbs({ id: 'page-breadcrumbs', items: [ { label: 'Components', href: '/docs/components' }, { label: 'Countdown' } ] }); document.currentScript.replaceWith(breadcrumbs.domEl); })(); </script> </div> <!-- Title Row --> <div class="gallery-header" style="border-bottom: none; height: auto; padding-top: 0.5rem; padding-bottom: 0.75rem;"> <button id="toggle-btn" class="toggle-btn" aria-label="Toggle Sidebar"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="toggle-icon" style="stroke: currentColor; stroke-width: 2;"> <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" /> <path stroke-linecap="round" stroke-linejoin="round" d="M11 19l-7-7 7-7" /> </svg> </button> <h1 class="gallery-title">Countdown</h1> </div> </div> <!-- Content --> <div class="gallery-content"> <div class="section-content" style="max-width: 1000px;"> <p class="text-lg" style="opacity: 0.7; margin-bottom: 1.5rem;"> Countdown displays a numeric value with smooth transition animation. Supports reactive values for live countdowns. </p> <!-- Basic Example with Examplify --> <div class="card bg-base-200" style="margin-bottom: 2rem;"> <div class="card-body"> <h2 class="card-title">Basic Example</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Static countdown values</p> <!-- Tabs --> <script> globalThis.switchSyntaxTab = (tabId) => { const tabs = ['tagged', 'vdom', 'object']; tabs.forEach(t => { const tabEl = document.getElementById(`tab-btn-${t}`); const contentEl = document.getElementById(`syntax-${t}`); if (t === tabId) { tabEl.classList.add('syntax-tab-active'); contentEl.style.display = 'block'; } else { tabEl.classList.remove('syntax-tab-active'); contentEl.style.display = 'none'; } }); }; </script> <div role="tablist" class="syntax-tabs" style="margin-bottom: 1rem;"> <button id="tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active" onclick="switchSyntaxTab('tagged')">Tagged</button> <button id="tab-btn-vdom" role="tab" class="syntax-tab" onclick="switchSyntaxTab('vdom')">vDOM</button> <button id="tab-btn-object" role="tab" class="syntax-tab" onclick="switchSyntaxTab('object')">Object DOM</button> </div> <!-- Tagged Syntax --> <div id="syntax-tagged"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 80, autoRun: true }); </script><code contenteditable="true">await import('/components/data-display/countdown.js'); const { tags, $ } = Lightview; const { div, span, Countdown } = tags; const display = div({ style: 'display: flex; gap: 1.25rem' }, Countdown({ value: 15, class: 'font-mono text-4xl' }), span({ class: 'text-4xl' }, ':'), Countdown({ value: 30, class: 'font-mono text-4xl' }), span({ class: 'text-4xl' }, ':'), Countdown({ value: 45, class: 'font-mono text-4xl' }) ); $('#example').content(display);</code></pre> </div> <!-- vDOM Syntax --> <div id="syntax-vdom" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 80 }); </script><code contenteditable="true">await import('/components/data-display/countdown.js'); const { $, tags } = Lightview; const { Countdown, div, span } = tags; const display = { tag: div, attributes: { style: 'display: flex; gap: 1.25rem' }, children: [ { tag: Countdown, attributes: { value: 15, class: 'font-mono text-4xl' } }, { tag: span, attributes: { class: 'text-4xl' }, children: [':'] }, { tag: Countdown, attributes: { value: 30, class: 'font-mono text-4xl' } }, { tag: span, attributes: { class: 'text-4xl' }, children: [':'] }, { tag: Countdown, attributes: { value: 45, class: 'font-mono text-4xl' } } ] }; $('#example').content(display);</code></pre> </div> <!-- Object DOM Syntax --> <div id="syntax-object" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 80 }); </script><code contenteditable="true">await import('/components/data-display/countdown.js'); const { $ } = Lightview; const display = { div: { style: 'display: flex; gap: 1.25rem', children: [ { Countdown: { value: 15, class: 'font-mono text-4xl' } }, { span: { class: 'text-4xl', children: [':'] } }, { Countdown: { value: 30, class: 'font-mono text-4xl' } }, { span: { class: 'text-4xl', children: [':'] } }, { Countdown: { value: 45, class: 'font-mono text-4xl' } } ] } }; $('#example').content(display);</code></pre> </div> </div> </div> <!-- Reactive Example with Examplify --> <div class="card bg-base-200" style="margin-bottom: 2rem;"> <div class="card-body"> <h2 class="card-title">Live Timer</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Reactive countdown with animated transitions</p> <!-- Tabs --> <script> globalThis.switchReactiveSyntaxTab = (tabId) => { const tabs = ['tagged', 'vdom', 'object']; tabs.forEach(t => { const tabEl = document.getElementById(`reactive-tab-btn-${t}`); const contentEl = document.getElementById(`reactive-syntax-${t}`); if (t === tabId) { tabEl.classList.add('syntax-tab-active'); contentEl.style.display = 'block'; } else { tabEl.classList.remove('syntax-tab-active'); contentEl.style.display = 'none'; } }); }; </script> <div role="tablist" class="syntax-tabs" style="margin-bottom: 1rem;"> <button id="reactive-tab-btn-tagged" role="tab" class="syntax-tab syntax-tab-active" onclick="switchReactiveSyntaxTab('tagged')">Tagged</button> <button id="reactive-tab-btn-vdom" role="tab" class="syntax-tab" onclick="switchReactiveSyntaxTab('vdom')">vDOM</button> <button id="reactive-tab-btn-object" role="tab" class="syntax-tab" onclick="switchReactiveSyntaxTab('object')">Object DOM</button> </div> <!-- Tagged Syntax --> <div id="reactive-syntax-tagged"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 160 }); </script><code contenteditable="true">await import('/components/data-display/countdown.js'); await import('/components/actions/button.js'); const { signal, tags, $ } = Lightview; const { div, Countdown, Button } = tags; const seconds = signal(30); const running = signal(false); let interval = null; const toggle = () => { if (running.value) { clearInterval(interval); running.value = false; } else { running.value = true; interval = setInterval(() => { if (seconds.value > 0) { seconds.value--; } else { clearInterval(interval); running.value = false; } }, 1000); } }; const reset = () => { clearInterval(interval); running.value = false; seconds.value = 30; }; const demo = div({ style: 'display: flex; flex-direction: column; align-items: center; gap: 1rem' }, Countdown({ value: () => seconds.value, class: 'font-mono text-6xl' }), div({ style: 'display: flex; gap: 0.5rem' }, Button({ color: () => running.value ? 'error' : 'primary', onclick: toggle }, () => running.value ? 'Pause' : 'Start'), Button({ onclick: reset }, 'Reset') ) ); $('#example').content(demo);</code></pre> </div> <!-- vDOM Syntax --> <div id="reactive-syntax-vdom" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 160 }); </script><code contenteditable="true">await import('/components/data-display/countdown.js'); await import('/components/actions/button.js'); const { signal, $, tags } = Lightview; const { Countdown, div, Button } = tags; const seconds = signal(30); const running = signal(false); let interval = null; const toggle = () => { if (running.value) { clearInterval(interval); running.value = false; } else { running.value = true; interval = setInterval(() => { if (seconds.value > 0) { seconds.value--; } else { clearInterval(interval); running.value = false; } }, 1000); } }; const reset = () => { clearInterval(interval); running.value = false; seconds.value = 30; }; const demo = { tag: div, attributes: { style: 'display: flex; flex-direction: column; align-items: center; gap: 1rem' }, children: [ { tag: Countdown, attributes: { value: () => seconds.value, class: 'font-mono text-6xl' } }, { tag: div, attributes: { style: 'display: flex; gap: 0.5rem' }, children: [ { tag: Button, attributes: { color: () => running.value ? 'error' : 'primary', onclick: toggle }, children: [() => running.value ? 'Pause' : 'Start'] }, { tag: Button, attributes: { onclick: reset }, children: ['Reset'] } ] } ] }; $('#example').content(demo);</code></pre> </div> <!-- Object DOM Syntax --> <div id="reactive-syntax-object" style="display: none;"> <pre><script> examplify(document.currentScript.nextElementSibling, { at: document.currentScript.parentElement, scripts: ['/lightview.js', '/lightview-x.js'], styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'], type: 'module', minHeight: 160 }); </script><code contenteditable="true">await import('/components/data-display/countdown.js'); await import('/components/actions/button.js'); const { signal, $ } = Lightview; const seconds = signal(30); const running = signal(false); let interval = null; const toggle = () => { if (running.value) { clearInterval(interval); running.value = false; } else { running.value = true; interval = setInterval(() => { if (seconds.value > 0) { seconds.value--; } else { clearInterval(interval); running.value = false; } }, 1000); } }; const reset = () => { clearInterval(interval); running.value = false; seconds.value = 30; }; const demo = { div: { style: 'display: flex; flex-direction: column; align-items: center; gap: 1rem', children: [ { Countdown: { value: () => seconds.value, class: 'font-mono text-6xl' } }, { div: { style: 'display: flex; gap: 0.5rem', children: [ { Button: { color: () => running.value ? 'error' : 'primary', onclick: toggle, children: [() => running.value ? 'Pause' : 'Start'] } }, { Button: { onclick: reset, children: ['Reset'] } } ] } } ] } }; $('#example').content(demo);</code></pre> </div> </div> </div> <!-- Props Table --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Props</h2> <div style="overflow-x: auto; margin-bottom: 2rem;"> <table class="table table-zebra"> <thead> <tr> <th>Prop</th> <th>Type</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>value</code></td> <td>number | function</td> <td>0</td> <td>Countdown value (0-99, reactive)</td> </tr> </tbody> </table> </div> <!-- Static Examples --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">With Labels</h2> <div style="display: grid; grid-auto-flow: column; grid-auto-columns: max-content; gap: 1.25rem; text-align: center; margin-bottom: 2rem;"> <div style="display: flex; flex-direction: column; padding: 0.5rem;" class="bg-neutral rounded-box text-neutral-content"> <span class="countdown font-mono text-5xl" style="line-height: 1.2em; height: 1.2em;"><span id="cd-days" style="--value:15; height: 1.2em;"></span></span> days </div> <div style="display: flex; flex-direction: column; padding: 0.5rem;" class="bg-neutral rounded-box text-neutral-content"> <span class="countdown font-mono text-5xl" style="line-height: 1.2em; height: 1.2em;"><span id="cd-hours" style="--value:10; height: 1.2em;"></span></span> hours </div> <div style="display: flex; flex-direction: column; padding: 0.5rem;" class="bg-neutral rounded-box text-neutral-content"> <span class="countdown font-mono text-5xl" style="line-height: 1.2em; height: 1.2em;"><span id="cd-min" style="--value:24; height: 1.2em;"></span></span> min </div> <div style="display: flex; flex-direction: column; padding: 0.5rem;" class="bg-neutral rounded-box text-neutral-content"> <span class="countdown font-mono text-5xl" style="line-height: 1.2em; height: 1.2em;"><span id="cd-sec" style="--value:59; height: 1.2em;"></span></span> sec </div> </div> </div> </div> <script> // Animate the seconds countdown let sec = 59; setInterval(() => { sec = sec > 0 ? sec - 1 : 59; const el = document.getElementById('cd-sec'); if (el) el.style.setProperty('--value', sec); }, 1000);