UNPKG

lightview

Version:

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

474 lines (433 loc) 23.7 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: 'Toast' } ] }); 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">Toast</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;"> Toast is a wrapper to position alert components at the corner of the screen. Perfect for notifications and temporary messages. </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;">Toast with alert at different positions </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: 100, autoRun: true, html: '<div id="demo" style="height: 80px; position: relative;"></div>' }); </script><code contenteditable="true">await import('/components/data-display/toast.js'); await import('/components/data-display/alert.js'); const { tags, $ } = Lightview; const { span, Toast, Alert } = tags; // Toast positioned at bottom-end (default) const toast = Toast({ position: 'end', vertical: 'bottom' }, Alert({ color: 'success', icon: 'success' }, span({}, 'Message sent successfully!') ) ); $('#demo').content(toast);</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: 100, html: '<div id="demo" style="height: 80px; position: relative;"></div>' }); </script><code contenteditable="true">await import('/components/data-display/toast.js'); await import('/components/data-display/alert.js'); const { $, tags } = Lightview; const { Toast, Alert, span } = tags; const toast = { tag: Toast, attributes: { position: 'end', vertical: 'bottom' }, children: [ { tag: Alert, attributes: { color: 'success', icon: 'success' }, children: [{ tag: span, children: ['Message sent successfully!'] }] } ] }; $('#demo').content(toast);</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: 100, html: '<div id="demo" style="height: 80px; position: relative;"></div>' }); </script><code contenteditable="true">await import('/components/data-display/toast.js'); await import('/components/data-display/alert.js'); const { $ } = Lightview; const toast = { Toast: { position: 'end', vertical: 'bottom', children: [ { Alert: { color: 'success', icon: 'success', children: [ { span: { children: ['Message sent successfully!'] } } ] } } ] } }; $('#demo').content(toast);</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">Notification System</h2> <p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Dynamic toasts with auto-dismiss</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: 180, html: '<div id="demo" style="height: 150px; position: relative;"></div>' }); </script><code contenteditable="true">await import('/components/data-display/toast.js'); await import('/components/data-display/alert.js'); await import('/components/actions/button.js'); const { signal, tags, $ } = Lightview; const { div, span, Toast, Alert, Button } = tags; const notifications = signal([]); let id = 0; const addNotification = (type) => { const messages = { success: '✓ Action completed!', info: 'ℹ️ New update available', warning: '⚠️ Please review', error: '✕ Something went wrong' }; const newId = ++id; notifications.value = [...notifications.value, { id: newId, type, msg: messages[type] }]; // Auto-remove after 3 seconds setTimeout(() => { notifications.value = notifications.value.filter(n => n.id !== newId); }, 3000); }; const demo = div({}, div({ style: 'display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem' }, Button({ color: 'success', size: 'sm', onclick: () => addNotification('success') }, 'Success'), Button({ color: 'info', size: 'sm', onclick: () => addNotification('info') }, 'Info'), Button({ color: 'warning', size: 'sm', onclick: () => addNotification('warning') }, 'Warning'), Button({ color: 'error', size: 'sm', onclick: () => addNotification('error') }, 'Error') ), () => Toast({ position: 'end', vertical: 'top' }, ...notifications.value.map(n => Alert({ color: n.type, key: n.id }, span({}, n.msg)) ) ) ); $('#demo').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: 180, html: '<div id="demo" style="height: 150px; position: relative;"></div>' }); </script><code contenteditable="true">await import('/components/data-display/toast.js'); await import('/components/data-display/alert.js'); await import('/components/actions/button.js'); const { signal, $, tags } = Lightview; const { Toast, Alert, Button, div, span } = tags; const notifications = signal([]); let id = 0; const addNotification = (type) => { const messages = { success: '✓ Action completed!', info: 'ℹ️ New update available', warning: '⚠️ Please review', error: '✕ Something went wrong' }; const newId = ++id; notifications.value = [...notifications.value, { id: newId, type, msg: messages[type] }]; setTimeout(() => { notifications.value = notifications.value.filter(n => n.id !== newId); }, 3000); }; const demo = { tag: div, children: [ { tag: div, attributes: { style: 'display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem' }, children: [ { tag: Button, attributes: { color: 'success', size: 'sm', onclick: () => addNotification('success') }, children: ['Success'] }, { tag: Button, attributes: { color: 'info', size: 'sm', onclick: () => addNotification('info') }, children: ['Info'] }, { tag: Button, attributes: { color: 'warning', size: 'sm', onclick: () => addNotification('warning') }, children: ['Warning'] }, { tag: Button, attributes: { color: 'error', size: 'sm', onclick: () => addNotification('error') }, children: ['Error'] } ] }, () => ({ tag: Toast, attributes: { position: 'end', vertical: 'top' }, children: notifications.value.map(n => ({ tag: Alert, attributes: { color: n.type, key: n.id }, children: [{ tag: span, children: [n.msg] }] })) }) ] }; $('#demo').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: 180, html: '<div id="demo" style="height: 150px; position: relative;"></div>' }); </script><code contenteditable="true">await import('/components/data-display/toast.js'); await import('/components/data-display/alert.js'); await import('/components/actions/button.js'); const { signal, $ } = Lightview; const notifications = signal([]); let id = 0; const addNotification = (type) => { const messages = { success: '✓ Action completed!', info: 'ℹ️ New update available', warning: '⚠️ Please review', error: '✕ Something went wrong' }; const newId = ++id; notifications.value = [...notifications.value, { id: newId, type, msg: messages[type] }]; setTimeout(() => { notifications.value = notifications.value.filter(n => n.id !== newId); }, 3000); }; const demo = { div: { children: [ { div: { style: 'display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem', children: [ { Button: { color: 'success', size: 'sm', onclick: () => addNotification('success'), children: ['Success'] } }, { Button: { color: 'info', size: 'sm', onclick: () => addNotification('info'), children: ['Info'] } }, { Button: { color: 'warning', size: 'sm', onclick: () => addNotification('warning'), children: ['Warning'] } }, { Button: { color: 'error', size: 'sm', onclick: () => addNotification('error'), children: ['Error'] } } ] } }, () => ({ Toast: { position: 'end', vertical: 'top', children: notifications.value.map(n => ({ Alert: { color: n.type, key: n.id, children: [ { span: { children: [n.msg] } } ] } })) } }) ] } }; $('#demo').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>'end'</td> <td>'start' | 'center' | 'end'</td> </tr> <tr> <td><code>vertical</code></td> <td>string</td> <td>'bottom'</td> <td>'top' | 'middle' | 'bottom'</td> </tr> </tbody> </table> </div> <!-- Positions Demo --> <h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Positions</h2> <p style="opacity: 0.7; margin-bottom: 1rem;">Click to see toast position (shown for 3 seconds):</p> <div class="example-flex" style="margin-bottom: 2rem;"> <button class="btn btn-sm" onclick="showToast('top', 'start')">Top Start</button> <button class="btn btn-sm" onclick="showToast('top', 'center')">Top Center</button> <button class="btn btn-sm" onclick="showToast('top', 'end')">Top End</button> <button class="btn btn-sm" onclick="showToast('bottom', 'start')">Bottom Start</button> <button class="btn btn-sm" onclick="showToast('bottom', 'center')">Bottom Center</button> <button class="btn btn-sm" onclick="showToast('bottom', 'end')">Bottom End</button> </div> <div id="toast-container"></div> </div> </div> <script> function showToast(vertical, horizontal) { const container = document.getElementById('toast-container'); container.innerHTML = ` <div class="toast toast-${vertical} toast-${horizontal}"> <div class="alert alert-success"> <span>Toast at ${vertical}-${horizontal}!</span> </div> </div> `; setTimeout(() => container.innerHTML = '', 3000); } </script>