lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
461 lines (423 loc) • 22.7 kB
HTML
<!-- 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: 'Menu' }
]
});
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">Menu</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;">
Menu is used to display a list of links vertically or horizontally.
Supports icons, submenus, and collapsible sections.
</p>
<!-- Basic Usage -->
<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;">Vertical menu with active
state</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: 200,
autoRun: true
});
</script><code contenteditable="true">await import('/components/navigation/menu.js');
const { signal, tags, $ } = Lightview;
const { Menu } = tags;
const active = signal('home');
const items = ['home', 'profile', 'settings', 'logout'];
const menu = Menu({ style: 'background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); width: 14rem;' },
...items.map(item =>
Menu.Item({
active: () => active.value === item,
onclick: () => { active.value = item; }
}, item.charAt(0).toUpperCase() + item.slice(1))
)
);
$('#example').content(menu);</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: 200
});
</script><code contenteditable="true">await import('/components/navigation/menu.js');
const { signal, $, tags } = Lightview;
const { Menu } = tags;
const active = signal('home');
const items = ['home', 'profile', 'settings', 'logout'];
const menu = {
tag: Menu,
attributes: { style: 'background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); width: 14rem;' },
children: items.map(item => ({
tag: Menu.Item,
attributes: {
active: () => active.value === item,
onclick: () => { active.value = item; }
},
children: [item.charAt(0).toUpperCase() + item.slice(1)]
}))
};
$('#example').content(menu);</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: 200
});
</script><code contenteditable="true">await import('/components/navigation/menu.js');
const { signal, $ } = Lightview;
const active = signal('home');
const items = ['home', 'profile', 'settings', 'logout'];
const menu = {
Menu: {
style: 'background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); width: 14rem;',
children: items.map(item => ({
'Menu.Item': {
active: () => active.value === item,
onclick: () => { active.value = item; },
children: [item.charAt(0).toUpperCase() + item.slice(1)]
}
}))
}
};
$('#example').content(menu);</code></pre>
</div>
</div>
</div>
<!-- Horizontal Example -->
<div class="card bg-base-200" style="margin-bottom: 2rem;">
<div class="card-body">
<h2 class="card-title">Horizontal Menu</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Navigation bar style menu</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: 120
});
</script><code contenteditable="true">await import('/components/navigation/menu.js');
const { signal, tags, $ } = Lightview;
const { Menu } = tags;
const current = signal('features');
const menu = Menu({ horizontal: true, style: 'background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem);' },
Menu.Item({
active: () => current.value === 'features',
onclick: () => { current.value = 'features'; }
}, '✨ Features'),
Menu.Item({
active: () => current.value === 'pricing',
onclick: () => { current.value = 'pricing'; }
}, '💰 Pricing'),
Menu.Item({
active: () => current.value === 'docs',
onclick: () => { current.value = 'docs'; }
}, '📚 Docs')
);
$('#example').content(menu);</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: 120
});
</script><code contenteditable="true">await import('/components/navigation/menu.js');
const { signal, $, tags } = Lightview;
const { Menu } = tags;
const current = signal('features');
const menu = {
tag: Menu,
attributes: { horizontal: true, style: 'background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem);' },
children: [
{
tag: Menu.Item,
attributes: {
active: () => current.value === 'features',
onclick: () => { current.value = 'features'; }
},
children: ['✨ Features']
},
{
tag: Menu.Item,
attributes: {
active: () => current.value === 'pricing',
onclick: () => { current.value = 'pricing'; }
},
children: ['💰 Pricing']
},
{
tag: Menu.Item,
attributes: {
active: () => current.value === 'docs',
onclick: () => { current.value = 'docs'; }
},
children: ['📚 Docs']
}
]
};
$('#example').content(menu);</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: 120
});
</script><code contenteditable="true">await import('/components/navigation/menu.js');
const { signal, $ } = Lightview;
const current = signal('features');
const menu = {
Menu: {
horizontal: true,
style: 'background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem);',
children: [
{
'Menu.Item': {
active: () => current.value === 'features',
onclick: () => { current.value = 'features'; },
children: ['✨ Features']
}
},
{
'Menu.Item': {
active: () => current.value === 'pricing',
onclick: () => { current.value = 'pricing'; },
children: ['💰 Pricing']
}
},
{
'Menu.Item': {
active: () => current.value === 'docs',
onclick: () => { current.value = 'docs'; },
children: ['📚 Docs']
}
}
]
}
};
$('#example').content(menu);</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>horizontal</code></td>
<td>boolean</td>
<td>false</td>
<td>Horizontal layout</td>
</tr>
<tr>
<td><code>size</code></td>
<td>string</td>
<td>-</td>
<td>'xs' | 'sm' | 'md' | 'lg'</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>Props</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Menu.Item</code></td>
<td>active, disabled</td>
<td>Menu list item (li with a inside)</td>
</tr>
<tr>
<td><code>Menu.Title</code></td>
<td>-</td>
<td>Section header</td>
</tr>
<tr>
<td><code>Menu.Dropdown</code></td>
<td>label, open</td>
<td>Collapsible submenu</td>
</tr>
</tbody>
</table>
</div>
<!-- Static Examples -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">With Title</h2>
<ul class="menu"
style="background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); width: 14rem; margin-bottom: 2rem;">
<li class="menu-title">Title</li>
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
<li><a>Item 3</a></li>
</ul>
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">With Submenu</h2>
<ul class="menu"
style="background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); width: 14rem; margin-bottom: 2rem;">
<li><a>Item 1</a></li>
<li>
<details open>
<summary>Parent</summary>
<ul>
<li><a>Submenu 1</a></li>
<li><a>Submenu 2</a></li>
</ul>
</details>
</li>
<li><a>Item 3</a></li>
</ul>
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Sizes</h2>
<div style="display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 2rem;">
<ul class="menu menu-xs"
style="background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); width: 10rem;">
<li><a>xs Item</a></li>
</ul>
<ul class="menu menu-lg"
style="background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); width: 12rem;">
<li><a>lg Item</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>