UNPKG

lightview

Version:

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

611 lines (574 loc) 27.2 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: 'Range' } ] }); 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">Range</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;"> Range slider allows the user to select a value from a range. Supports labels, value display, and reactive state binding. </p> <!-- Basic Example with Examplify --> <div class="card bg-base-200" style="margin-bottom: 2rem;"> <div class="card-body"> <h2 class="card-title">Basic Examples</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Range sliders with various configurations </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'], type: 'module', minHeight: 220, autoRun: true }); </script><code contenteditable="true">const { default: Range } = await import('/components/data-input/range.js'); const { tags, $ } = Lightview; const { div } = tags; // 1. Basic range const basic = Range({ min: 0, max: 100, defaultValue: 50 }); // 2. Range with label and value display const withLabel = Range({ label: 'Volume', min: 0, max: 100, defaultValue: 75, showValue: true, color: 'primary' }); // 3. Range with custom formatting const formatted = Range({ label: 'Price Range', min: 0, max: 1000, step: 50, defaultValue: 500, showValue: true, formatValue: (v) => `$${v}`, color: 'accent' }); // Insert all examples $('#example').content( div({ style: 'display: flex; flex-direction: column; gap: 1.5rem; max-width: 28rem' }, basic, withLabel, formatted) );</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'], type: 'module', minHeight: 220 }); </script><code contenteditable="true">const { default: Range } = await import('/components/data-input/range.js'); const { $ } = Lightview; const basic = { tag: Range, attributes: { min: 0, max: 100, defaultValue: 50 } }; const withLabel = { tag: Range, attributes: { label: 'Volume', min: 0, max: 100, defaultValue: 75, showValue: true, color: 'primary' } }; const formatted = { tag: Range, attributes: { label: 'Price Range', min: 0, max: 1000, step: 50, defaultValue: 500, showValue: true, formatValue: (v) => `$${v}`, color: 'accent' } }; $('#example').content({ tag: 'div', attributes: { style: 'display: flex; flex-direction: column; gap: 1.5rem; max-width: 28rem' }, children: [basic, withLabel, formatted] });</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'], type: 'module', minHeight: 220 }); </script><code contenteditable="true">const { default: Range } = await import('/components/data-input/range.js'); const { tags, $ } = Lightview; tags.Range = Range; $('#example').content({ div: { style: 'display: flex; flex-direction: column; gap: 1.5rem; max-width: 28rem', children: [ { Range: { min: 0, max: 100, defaultValue: 50 } }, { Range: { label: 'Volume', min: 0, max: 100, defaultValue: 75, showValue: true, color: 'primary' } }, { Range: { label: 'Price Range', min: 0, max: 1000, step: 50, defaultValue: 500, showValue: true, formatValue: (v) => `$${v}`, color: 'accent' } } ] } });</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">Reactive Example</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Two-way binding with signals </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'], type: 'module', minHeight: 280 }); </script><code contenteditable="true">const { default: Range } = await import('/components/data-input/range.js'); const { signal, tags, $ } = Lightview; const { div, p } = tags; // Signals for values const brightness = signal(70); const contrast = signal(50); const saturation = signal(100); // Reactive range sliders const reactiveDemo = div({ style: 'display: flex; flex-direction: column; gap: 1rem; max-width: 28rem' }, Range({ label: 'Brightness', min: 0, max: 100, value: brightness, showValue: true, formatValue: (v) => `${v}%`, color: 'warning' }), Range({ label: 'Contrast', min: 0, max: 100, value: contrast, showValue: true, formatValue: (v) => `${v}%`, color: 'info' }), Range({ label: 'Saturation', min: 0, max: 200, value: saturation, showValue: true, formatValue: (v) => `${v}%`, color: 'success' }), div({ class: 'divider' }), p({ class: 'text-sm font-mono opacity-70' }, () => `B: ${brightness.value}% | C: ${contrast.value}% | S: ${saturation.value}%` ) ); $('#example').content(reactiveDemo);</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'], type: 'module', minHeight: 280 }); </script><code contenteditable="true">const { default: Range } = await import('/components/data-input/range.js'); const { signal, $ } = Lightview; const brightness = signal(70); const contrast = signal(50); const saturation = signal(100); const reactiveDemo = { tag: 'div', attributes: { style: 'display: flex; flex-direction: column; gap: 1rem; max-width: 28rem' }, children: [ { tag: Range, attributes: { label: 'Brightness', min: 0, max: 100, value: brightness, showValue: true, formatValue: (v) => `${v}%`, color: 'warning' } }, { tag: Range, attributes: { label: 'Contrast', min: 0, max: 100, value: contrast, showValue: true, formatValue: (v) => `${v}%`, color: 'info' } }, { tag: Range, attributes: { label: 'Saturation', min: 0, max: 200, value: saturation, showValue: true, formatValue: (v) => `${v}%`, color: 'success' } }, { tag: 'div', attributes: { class: 'divider' } }, { tag: 'p', attributes: { class: 'text-sm font-mono opacity-70' }, children: [ () => `B: ${brightness.value}% | C: ${contrast.value}% | S: ${saturation.value}%` ] } ] }; $('#example').content(reactiveDemo);</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'], type: 'module', minHeight: 280 }); </script><code contenteditable="true">const { default: Range } = await import('/components/data-input/range.js'); const { signal, tags, $ } = Lightview; tags.Range = Range; const brightness = signal(70); const contrast = signal(50); const saturation = signal(100); const reactiveDemo = { div: { style: 'display: flex; flex-direction: column; gap: 1rem; max-width: 28rem', children: [ { Range: { label: 'Brightness', min: 0, max: 100, value: brightness, showValue: true, formatValue: (v) => `${v}%`, color: 'warning' } }, { Range: { label: 'Contrast', min: 0, max: 100, value: contrast, showValue: true, formatValue: (v) => `${v}%`, color: 'info' } }, { Range: { label: 'Saturation', min: 0, max: 200, value: saturation, showValue: true, formatValue: (v) => `${v}%`, color: 'success' } }, { div: { class: 'divider' } }, { p: { class: 'text-sm font-mono opacity-70', children: [ () => `B: ${brightness.value}% | C: ${contrast.value}% | S: ${saturation.value}%` ] } } ] } }; $('#example').content(reactiveDemo);</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 | signal</td> <td>-</td> <td>Current value (reactive with signals)</td> </tr> <tr> <td><code>defaultValue</code></td> <td>number</td> <td>0</td> <td>Default value for uncontrolled mode</td> </tr> <tr> <td><code>min</code></td> <td>number</td> <td>0</td> <td>Minimum value</td> </tr> <tr> <td><code>max</code></td> <td>number</td> <td>100</td> <td>Maximum value</td> </tr> <tr> <td><code>step</code></td> <td>number</td> <td>1</td> <td>Step increment</td> </tr> <tr> <td><code>label</code></td> <td>string</td> <td>-</td> <td>Label text displayed above the range</td> </tr> <tr> <td><code>helper</code></td> <td>string</td> <td>-</td> <td>Helper text displayed below the range</td> </tr> <tr> <td><code>showValue</code></td> <td>boolean</td> <td>false</td> <td>Display current value</td> </tr> <tr> <td><code>formatValue</code></td> <td>function</td> <td>(v) => v</td> <td>Format function for displayed value</td> </tr> <tr> <td><code>color</code></td> <td>string</td> <td>-</td> <td>'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error' </td> </tr> <tr> <td><code>size</code></td> <td>string</td> <td>'md'</td> <td>'xs' | 'sm' | 'md' | 'lg'</td> </tr> <tr> <td><code>disabled</code></td> <td>boolean</td> <td>false</td> <td>Disable the range slider</td> </tr> <tr> <td><code>onChange</code></td> <td>function</td> <td>-</td> <td>Callback when value changes: <code>(value, event) => void</code></td> </tr> <tr> <td><code>useShadow</code></td> <td>boolean</td> <td>*</td> <td>Render in Shadow DOM</td> </tr> </tbody> </table> </div> <!-- Colors Example --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Colors</h2> <div class="example-stack" style="max-width: 28rem; margin-bottom: 2rem;"> <input type="range" min="0" max="100" value="40" class="range range-primary" /> <input type="range" min="0" max="100" value="50" class="range range-secondary" /> <input type="range" min="0" max="100" value="60" class="range range-accent" /> <input type="range" min="0" max="100" value="70" class="range range-success" /> <input type="range" min="0" max="100" value="80" class="range range-warning" /> <input type="range" min="0" max="100" value="90" class="range range-info" /> <input type="range" min="0" max="100" value="100" class="range range-error" /> </div> <!-- Sizes Example --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Sizes</h2> <div class="example-stack" style="max-width: 28rem; margin-bottom: 2rem;"> <input type="range" min="0" max="100" value="40" class="range range-xs" /> <input type="range" min="0" max="100" value="50" class="range range-sm" /> <input type="range" min="0" max="100" value="60" class="range range-md" /> <input type="range" min="0" max="100" value="70" class="range range-lg" /> </div> <!-- With Steps --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">With Steps</h2> <div style="max-width: 28rem; margin-bottom: 2rem;"> <input type="range" min="0" max="100" value="25" class="range" step="25" /> <div class="w-full flex justify-between text-xs px-2 mt-2"> <span>|</span><span>|</span><span>|</span><span>|</span><span>|</span> </div> </div> </div> </div> </div> </div>