lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
374 lines (345 loc) • 18.2 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: 'Tabs' }
]
});
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">Tabs</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;">
Tabs allow showing and hiding content to organize information.
Supports boxed, bordered, and lifted variants.
</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;">Interactive tabs with content
panels</p>
<!-- Tabs -->
<script>
globalThis.switchSyntaxTab = (tabId) => {
const tabs = ['tagged', 'vdom', 'object', 'html'];
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>
<button id="tab-btn-html" role="tab" class="syntax-tab"
onclick="switchSyntaxTab('html')">HTML</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@5.5.14/daisyui.min.css'],
type: 'module',
minHeight: 150,
autoRun: true
});
</script><code contenteditable="true">await import('/components/navigation/tabs.js');
const { signal, tags, $ } = Lightview;
const { div, Tabs } = tags;
const activeTab = signal(0);
const tabLabels = ['Profile', 'Settings', 'Messages'];
const demo = div({ style: 'display: flex; flex-direction: column; gap: 1rem;' },
Tabs({ variant: 'bordered' },
...tabLabels.map((label, i) =>
Tabs.Tab({
active: () => activeTab.value === i,
onclick: () => { activeTab.value = i; }
}, label)
)
),
div({ style: 'padding: 1.5rem; border: 1px solid oklch(var(--b3)); border-radius: var(--rounded-box, 1rem); background-color: oklch(var(--b1));' },
() => `Content for: ${tabLabels[activeTab.value]}`
)
);
$('#example').content(demo);</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@5.5.14/daisyui.min.css'],
type: 'module',
minHeight: 150
});
</script><code contenteditable="true">await import('/components/navigation/tabs.js');
const { signal, $, tags } = Lightview;
const { Tabs, div } = tags;
const activeTab = signal(0);
const tabLabels = ['Profile', 'Settings', 'Messages'];
const demo = {
tag: div,
attributes: { style: 'display: flex; flex-direction: column; gap: 1rem;' },
children: [
{
tag: Tabs,
attributes: { variant: 'bordered' },
children: tabLabels.map((label, i) => ({
tag: Tabs.Tab,
attributes: {
active: () => activeTab.value === i,
onclick: () => { activeTab.value = i; }
},
children: [label]
}))
},
{
tag: div,
attributes: { style: 'padding: 1.5rem; border: 1px solid oklch(var(--b3)); border-radius: var(--rounded-box, 1rem); background-color: oklch(var(--b1));' },
children: [() => `Content for: ${tabLabels[activeTab.value]}`]
}
]
};
$('#example').content(demo);</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@5.5.14/daisyui.min.css'],
type: 'module',
minHeight: 150
});
</script><code contenteditable="true">await import('/components/navigation/tabs.js');
const { signal, $ } = Lightview;
const activeTab = signal(0);
const tabLabels = ['Profile', 'Settings', 'Messages'];
const demo = {
div: {
style: 'display: flex; flex-direction: column; gap: 1rem;',
children: [
{
Tabs: {
variant: 'bordered',
children: tabLabels.map((label, i) => ({
'Tabs.Tab': {
active: () => activeTab.value === i,
onclick: () => { activeTab.value = i; },
children: [label]
}
}))
}
},
{
div: {
style: 'padding: 1.5rem; border: 1px solid oklch(var(--b3)); border-radius: var(--rounded-box, 1rem); background-color: oklch(var(--b1));',
children: [() => `Content for: ${tabLabels[activeTab.value]}`]
}
}
]
}
};
$('#example').content(demo);</code></pre>
</div>
</div>
<!-- HTML Syntax -->
<div id="syntax-html" 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@5.5.14/daisyui.min.css'],
type: 'module',
language: 'html',
minHeight: 150
});
</script><code contenteditable="true" class="language-html"><!-- Import the component (registers lv-tabs, lv-tab) -->
<script type="module" src="/components/navigation/tabs.js"></script>
<script>
globalThis.activeTab = Lightview.signal(0);
</script>
<div style="display: flex; flex-direction: column; gap: 1rem;">
<lv-tabs variant="bordered">
<lv-tab active="${activeTab.value === 0}" onclick="activeTab.value = 0">Profile</lv-tab>
<lv-tab active="${activeTab.value === 1}" onclick="activeTab.value = 1">Settings</lv-tab>
<lv-tab active="${activeTab.value === 2}" onclick="activeTab.value = 2">Messages</lv-tab>
</lv-tabs>
<div style="padding: 1.5rem; border: 1px solid oklch(var(--b3)); border-radius: var(--rounded-box, 1rem); background-color: oklch(var(--b1));">
Content for: ${['Profile', 'Settings', 'Messages'][activeTab.value]}
</div>
</div></code></pre>
</div>
</div>
</div>
<!-- Props Table -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Props (Tabs)</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>variant</code></td>
<td>string</td>
<td>-</td>
<td>'boxed' | 'bordered' | 'lifted'</td>
</tr>
<tr>
<td><code>size</code></td>
<td>string</td>
<td>-</td>
<td>'xs' | 'sm' | 'lg' | 'xl'</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>Tabs.Tab</code></td>
<td>active, disabled</td>
<td>Individual tab button</td>
</tr>
<tr>
<td><code>Tabs.Content</code></td>
<td>-</td>
<td>Content panel for lifted tabs</td>
</tr>
</tbody>
</table>
</div>
<!-- Variants -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Variants</h2>
<script type="module">
await import('/components/navigation/tabs.js');
</script>
<div style="display: flex; flex-direction: column; gap: 2rem; margin-bottom: 2rem;">
<div>
<h3 style="font-weight: 700; margin-bottom: 0.5rem;">Bordered</h3>
<lv-tabs variant="bordered">
<lv-tab>Tab 1</lv-tab>
<lv-tab active="true">Tab 2</lv-tab>
<lv-tab>Tab 3</lv-tab>
</lv-tabs>
</div>
<div>
<h3 style="font-weight: 700; margin-bottom: 0.5rem;">Boxed</h3>
<lv-tabs variant="boxed">
<lv-tab>Tab 1</lv-tab>
<lv-tab active="true">Tab 2</lv-tab>
<lv-tab>Tab 3</lv-tab>
</lv-tabs>
</div>
<div>
<h3 style="font-weight: 700; margin-bottom: 0.5rem;">Lifted</h3>
<lv-tabs variant="lifted">
<lv-tab>Tab 1</lv-tab>
<lv-tab active="true">Tab 2</lv-tab>
<lv-tab>Tab 3</lv-tab>
</lv-tabs>
</div>
</div>
<!-- Sizes -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Sizes</h2>
<div style="display: flex; flex-direction: column; gap: 1rem; margin-bottom: 2rem;">
<lv-tabs variant="bordered" size="xs">
<lv-tab active="true">xs</lv-tab>
<lv-tab>xs</lv-tab>
</lv-tabs>
<lv-tabs variant="bordered" size="sm">
<lv-tab active="true">sm</lv-tab>
<lv-tab>sm</lv-tab>
</lv-tabs>
<lv-tabs variant="bordered">
<lv-tab active="true">md (default)</lv-tab>
<lv-tab>md (default)</lv-tab>
</lv-tabs>
<lv-tabs variant="bordered" size="lg">
<lv-tab active="true">lg</lv-tab>
<lv-tab>lg</lv-tab>
</lv-tabs>
<lv-tabs variant="bordered" size="xl">
<lv-tab active="true">xl</lv-tab>
<lv-tab>xl</lv-tab>
</lv-tabs>
</div>
</div>
</div>
</div>
</div>