lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
257 lines (235 loc) • 13.3 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: 'Diff' }
]
});
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">Diff</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;">
Diff component shows a side-by-side or before/after comparison.
Perfect for image comparisons and visual changes.
</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;">Image comparison with drag
resizer</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>
<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'],
type: 'module',
minHeight: 300,
autoRun: true
});
</script><code contenteditable="true">const { default: Diff } = await import('/components/data-display/diff.js');
const { tags, $ } = Lightview;
const diff = Diff({ style: 'max-width: 500px; min-height: 300px;' },
Diff.Item1({ src: 'https://picsum.photos/600/400?grayscale', alt: 'Before (Grayscale)' }),
Diff.Item2({ src: 'https://picsum.photos/600/400', alt: 'After (Color)' }),
Diff.Resizer({})
);
$('#example').content(diff);</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'],
type: 'module',
minHeight: 350
});
</script><code contenteditable="true">const { default: Diff } = await import('/components/data-display/diff.js');
const { $ } = Lightview;
const diff = {
tag: Diff,
attributes: { style: 'max-width: 500px; min-height: 300px;' },
children: [
{ tag: Diff.Item1, attributes: { src: 'https://picsum.photos/600/400?grayscale', alt: 'Before (Grayscale)' } },
{ tag: Diff.Item2, attributes: { src: 'https://picsum.photos/600/400', alt: 'After (Color)' } },
{ tag: Diff.Resizer }
]
};
$('#example').content(diff);</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'],
type: 'module',
minHeight: 350
});
</script><code contenteditable="true">const { default: Diff } = await import('/components/data-display/diff.js');
const { tags, $ } = Lightview;
tags.Diff = Diff;
tags['Diff.Item1'] = Diff.Item1;
tags['Diff.Item2'] = Diff.Item2;
tags['Diff.Resizer'] = Diff.Resizer;
const diff = {
Diff: {
style: 'max-width: 500px; min-height: 300px;',
children: [
{ 'Diff.Item1': { src: 'https://picsum.photos/600/400?grayscale', alt: 'Before (Grayscale)' } },
{ 'Diff.Item2': { src: 'https://picsum.photos/600/400', alt: 'After (Color)' } },
{ 'Diff.Resizer': {} }
]
}
};
$('#example').content(diff);</code></pre>
</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'],
type: 'module',
language: 'html',
minHeight: 350
});
</script><code contenteditable="true" class="language-html"><!-- Import the component (registers lv-diff, lv-diff-item1, etc.) -->
<script type="module" src="/components/data-display/diff.js"></script>
<lv-diff style="max-width: 500px; min-height: 300px;">
<lv-diff-item1 src="https://picsum.photos/600/400?grayscale" alt="Before"></lv-diff-item1>
<lv-diff-item2 src="https://picsum.photos/600/400" alt="After"></lv-diff-item2>
<lv-diff-resizer></lv-diff-resizer>
</lv-diff></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>aspectRatio</td>
<td>string</td>
<td>'aspect-video'</td>
<td>Aspect ratio class (aspect-video, aspect-square, etc.)</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>Diff.Item1</code></td>
<td>src, alt</td>
<td>Top comparison item (The "Before" overlay)</td>
</tr>
<tr>
<td><code>Diff.Item2</code></td>
<td>src, alt</td>
<td>Bottom comparison item (The "After" background)</td>
</tr>
<tr>
<td><code>Diff.Resizer</code></td>
<td>-</td>
<td>Drag handle for resizing</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>