lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
286 lines (262 loc) • 15.4 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: 'Carousel' }
]
});
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">Carousel</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;">
Carousel shows images or content in a scrollable horizontal view.
Supports snap points, vertical layout, and full-width items.
</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;">Navigable carousel with
buttons</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: 400,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/carousel.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, a, Carousel } = tags;
const slides = [
{ id: 'slide1', img: 'https://picsum.photos/800/400?random=10', title: 'Welcome' },
{ id: 'slide2', img: 'https://picsum.photos/800/400?random=11', title: 'Features' },
{ id: 'slide3', img: 'https://picsum.photos/800/400?random=12', title: 'Get Started' }
];
const demo = Carousel({ full: true, style: 'width: 100%' },
...slides.map((slide, i) =>
div({ id: slide.id, class: 'carousel-item', style: 'position: relative; width: 100%' },
tags.img({ src: slide.img, style: 'width: 100%' }),
a({ href: `#${slides[(i - 1 + slides.length) % slides.length].id}`, class: 'btn btn-circle', style: 'position: absolute; left: 1.25rem; top: 50%; transform: translateY(-50%)' }, '❮'),
a({ href: `#${slides[(i + 1) % slides.length].id}`, class: 'btn btn-circle', style: 'position: absolute; right: 1.25rem; top: 50%; transform: translateY(-50%)' }, '❯')
)
)
);
$('#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: 400
});
</script><code contenteditable="true">await import('/components/data-display/carousel.js');
await import('/components/actions/button.js');
const { $, tags } = Lightview;
const { div, img, a, Carousel } = tags;
const slides = [
{ id: 'slide1', img: 'https://picsum.photos/800/400?random=10', title: 'Welcome' },
{ id: 'slide2', img: 'https://picsum.photos/800/400?random=11', title: 'Features' },
{ id: 'slide3', img: 'https://picsum.photos/800/400?random=12', title: 'Get Started' }
];
const demo = {
tag: Carousel,
attributes: { full: true, style: 'width: 100%' },
children: slides.map((slide, i) => ({
tag: div,
attributes: { id: slide.id, class: 'carousel-item', style: 'position: relative; width: 100%' },
children: [
{ tag: img, attributes: { src: slide.img, style: 'width: 100%' } },
{ tag: a, attributes: { href: `#${slides[(i - 1 + slides.length) % slides.length].id}`, class: 'btn btn-circle', style: 'position: absolute; left: 1.25rem; top: 50%; transform: translateY(-50%)' }, children: ['❮'] },
{ tag: a, attributes: { href: `#${slides[(i + 1) % slides.length].id}`, class: 'btn btn-circle', style: 'position: absolute; right: 1.25rem; top: 50%; transform: translateY(-50%)' }, children: ['❯'] }
]
}))
};
$('#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: 400
});
</script><code contenteditable="true">await import('/components/data-display/carousel.js');
await import('/components/actions/button.js');
const { $ } = Lightview;
const slides = [
{ id: 'slide1', img: 'https://picsum.photos/800/400?random=10', title: 'Welcome' },
{ id: 'slide2', img: 'https://picsum.photos/800/400?random=11', title: 'Features' },
{ id: 'slide3', img: 'https://picsum.photos/800/400?random=12', title: 'Get Started' }
];
const demo = {
Carousel: {
full: true,
style: 'width: 100%',
children: slides.map((slide, i) => ({
div: {
id: slide.id,
class: 'carousel-item',
style: 'position: relative; width: 100%',
children: [
{ img: { src: slide.img, style: 'width: 100%' } },
{ a: { href: `#${slides[(i - 1 + slides.length) % slides.length].id}`, class: 'btn btn-circle', style: 'position: absolute; left: 1.25rem; top: 50%; transform: translateY(-50%)', children: ['❮'] } },
{ a: { href: `#${slides[(i + 1) % slides.length].id}`, class: 'btn btn-circle', style: 'position: absolute; right: 1.25rem; top: 50%; transform: translateY(-50%)', children: ['❯'] } }
]
}
}))
}
};
$('#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>snap</code></td>
<td>string</td>
<td>'start'</td>
<td>'start' | 'center' | 'end'</td>
</tr>
<tr>
<td><code>vertical</code></td>
<td>boolean</td>
<td>false</td>
<td>Vertical layout</td>
</tr>
<tr>
<td><code>full</code></td>
<td>boolean</td>
<td>false</td>
<td>Full width container</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>Carousel.Item</code></td>
<td>id, src, alt</td>
<td>Individual slide item</td>
</tr>
</tbody>
</table>
</div>
<!-- Static Examples -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Centered Carousel</h2>
<div class="carousel carousel-center bg-neutral rounded-box"
style="margin-right: 1rem; padding: 1rem; margin-bottom: 2rem;">
<div class="carousel-item"><img src="https://picsum.photos/300/200?random=5" class="rounded-box"
alt="Slide" /></div>
<div class="carousel-item"><img src="https://picsum.photos/300/200?random=6" class="rounded-box"
alt="Slide" /></div>
<div class="carousel-item"><img src="https://picsum.photos/300/200?random=7" class="rounded-box"
alt="Slide" /></div>
</div>
</div>
</div>
</div>
</div>