UNPKG

lightview

Version:

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

479 lines (442 loc) 23.9 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: 'Dropdown' } ] }); 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">Dropdown</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;"> Dropdown can open a menu or any other element when clicking or hovering. </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;">Dropdown with menu items</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: 160, autoRun: true }); </script><code contenteditable="true">await import('/components/actions/dropdown.js'); const { tags, $ } = Lightview; const { div, Dropdown } = tags; // Basic dropdown const dropdown = Dropdown({}, Dropdown.Trigger({}, 'Click me'), Dropdown.Content({}, Dropdown.Item({}, 'Profile'), Dropdown.Item({}, 'Settings'), Dropdown.Item({}, 'Logout') ) ); $('#example').content(div({ style: 'height: 10rem;' }, dropdown));</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: 160 }); </script><code contenteditable="true">await import('/components/actions/dropdown.js'); const { $, tags } = Lightview; const { Dropdown, div } = tags; const dropdown = { tag: Dropdown, children: [ { tag: Dropdown.Trigger, children: ['Click me'] }, { tag: Dropdown.Content, children: [ { tag: Dropdown.Item, children: ['Profile'] }, { tag: Dropdown.Item, children: ['Settings'] }, { tag: Dropdown.Item, children: ['Logout'] } ] } ] }; $('#example').content({ tag: div, attributes: { style: 'height: 10rem;' }, children: [dropdown] });</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: 160 }); </script><code contenteditable="true">await import('/components/actions/dropdown.js'); const { $ } = Lightview; const dropdown = { Dropdown: { children: [ { 'Dropdown.Trigger': { children: ['Click me'] } }, { 'Dropdown.Content': { children: [ { 'Dropdown.Item': { children: ['Profile'] } }, { 'Dropdown.Item': { children: ['Settings'] } }, { 'Dropdown.Item': { children: ['Logout'] } } ] } } ] } }; $('#example').content({ div: { style: 'height: 10rem;', children: [dropdown] } });</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">Dynamic Menu</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Dropdown with reactive menu items</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: 200 }); </script><code contenteditable="true">await import('/components/actions/dropdown.js'); const { signal, tags, $ } = Lightview; const { div, span, Dropdown } = tags; const selected = signal('Select an option'); const options = ['🍎 Apple', '🍌 Banana', '🍊 Orange', '🍇 Grape']; const dropdown = Dropdown({}, Dropdown.Trigger({ class: 'btn-primary' }, () => selected.value ), Dropdown.Content({}, ...options.map(opt => Dropdown.Item({ onclick: () => { selected.value = opt; } }, opt) ) ) ); const demo = div({ style: 'display: flex; gap: 1rem; align-items: center; height: 12rem;' }, dropdown, span({ style: 'font-size: 0.875rem; opacity: 0.7;' }, () => `Selected: ${selected.value}` ) ); $('#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: 200 }); </script><code contenteditable="true">await import('/components/actions/dropdown.js'); const { signal, $, tags } = Lightview; const { Dropdown, div, span } = tags; const selected = signal('Select an option'); const options = ['🍎 Apple', '🍌 Banana', '🍊 Orange', '🍇 Grape']; const dropdown = { tag: Dropdown, children: [ { tag: Dropdown.Trigger, attributes: { class: 'btn-primary' }, children: [() => selected.value] }, { tag: Dropdown.Content, children: options.map(opt => ({ tag: Dropdown.Item, attributes: { onclick: () => { selected.value = opt; } }, children: [opt] })) } ] }; const demo = { tag: div, attributes: { style: 'display: flex; gap: 1rem; align-items: center; height: 12rem;' }, children: [ dropdown, { tag: span, attributes: { style: 'font-size: 0.875rem; opacity: 0.7;' }, children: [() => `Selected: ${selected.value}`] } ] }; $('#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: 200 }); </script><code contenteditable="true">await import('/components/actions/dropdown.js'); const { signal, $ } = Lightview; const selected = signal('Select an option'); const options = ['🍎 Apple', '🍌 Banana', '🍊 Orange', '🍇 Grape']; const dropdown = { Dropdown: { children: [ { 'Dropdown.Trigger': { class: 'btn-primary', children: [() => selected.value] } }, { 'Dropdown.Content': { children: options.map(opt => ({ 'Dropdown.Item': { onclick: () => { selected.value = opt; }, children: [opt] } })) } } ] } }; const demo = { div: { style: 'display: flex; gap: 1rem; align-items: center; height: 12rem;', children: [ dropdown, { span: { style: 'font-size: 0.875rem; opacity: 0.7;', children: [() => `Selected: ${selected.value}`] } } ] } }; $('#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>position</code></td> <td>string</td> <td>-</td> <td>'top' | 'bottom' | 'left' | 'right' | 'end'</td> </tr> <tr> <td><code>hover</code></td> <td>boolean</td> <td>false</td> <td>Open on hover instead of click</td> </tr> <tr> <td><code>open</code></td> <td>boolean</td> <td>false</td> <td>Force open state</td> </tr> </tbody> </table> </div> <!-- Sub-components --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Sub-components</h2> <div style="overflow-x: auto; margin-bottom: 2rem;"> <table class="table table-zebra"> <thead> <tr> <th>Component</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>Dropdown.Trigger</code></td> <td>The clickable element that toggles the dropdown</td> </tr> <tr> <td><code>Dropdown.Content</code></td> <td>The menu/content container</td> </tr> <tr> <td><code>Dropdown.Item</code></td> <td>Individual menu item</td> </tr> </tbody> </table> </div> <!-- Positions --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Positions</h2> <div style="display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; margin-bottom: 2rem; padding-top: 8rem; padding-bottom: 8rem;"> <div class="dropdown dropdown-bottom"> <div tabindex="0" role="button" class="btn">Bottom</div> <ul tabindex="0" class="dropdown-content menu" style="background-color: oklch(var(--b1)); border-radius: var(--rounded-box, 1rem); z-index: 10; width: 13rem; padding: 0.5rem; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);"> <li><a>Item</a></li> </ul> </div> <div class="dropdown dropdown-top"> <div tabindex="0" role="button" class="btn">Top</div> <ul tabindex="0" class="dropdown-content menu" style="background-color: oklch(var(--b1)); border-radius: var(--rounded-box, 1rem); z-index: 10; width: 13rem; padding: 0.5rem; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);"> <li><a>Item</a></li> </ul> </div> <div class="dropdown dropdown-left"> <div tabindex="0" role="button" class="btn">Left</div> <ul tabindex="0" class="dropdown-content menu" style="background-color: oklch(var(--b1)); border-radius: var(--rounded-box, 1rem); z-index: 10; width: 13rem; padding: 0.5rem; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);"> <li><a>Item</a></li> </ul> </div> <div class="dropdown dropdown-right"> <div tabindex="0" role="button" class="btn">Right</div> <ul tabindex="0" class="dropdown-content menu" style="background-color: oklch(var(--b1)); border-radius: var(--rounded-box, 1rem); z-index: 10; width: 13rem; padding: 0.5rem; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);"> <li><a>Item</a></li> </ul> </div> </div> <!-- Hover --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Hover</h2> <div class="dropdown dropdown-hover" style="margin-bottom: 2rem; height: 8rem;"> <div tabindex="0" role="button" class="btn" style="margin: 0.25rem;">Hover me</div> <ul tabindex="0" class="dropdown-content menu" style="background-color: oklch(var(--b1)); border-radius: var(--rounded-box, 1rem); z-index: 10; width: 13rem; padding: 0.5rem; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);"> <li><a>Item 1</a></li> <li><a>Item 2</a></li> </ul> </div> </div> </div> </div> </div>