lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
525 lines (479 loc) • 27.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: 'Loading' }
]
});
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">Loading</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;">
Loading shows an animated indicator for loading states.
Multiple types and sizes available.
</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;">Different loading types and
sizes</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@3.9.4/dist/full.min.css'],
type: 'module',
minHeight: 100,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/loading.js');
const { tags, $ } = Lightview;
const { div, p, Loading } = tags;
const types = ['spinner', 'dots', 'ring', 'ball', 'bars', 'infinity'];
const loaders = div({ style: 'display: flex; flex-wrap: wrap; gap: 2rem;' },
...types.map(type =>
div({ style: 'text-align: center;' },
Loading({ type, size: 'lg' }),
p({ style: 'font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;' }, type)
)
)
);
$('#example').content(loaders);</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
});
</script><code contenteditable="true">await import('/components/data-display/loading.js');
const { $, tags } = Lightview;
const { Loading, div, p } = tags;
const types = ['spinner', 'dots', 'ring', 'ball', 'bars', 'infinity'];
const loaders = {
tag: div,
attributes: { style: 'display: flex; flex-wrap: wrap; gap: 2rem;' },
children: types.map(type => ({
tag: div,
attributes: { style: 'text-align: center;' },
children: [
{ tag: Loading, attributes: { type, size: 'lg' } },
{ tag: p, attributes: { style: 'font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;' }, children: [type] }
]
}))
};
$('#example').content(loaders);</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
});
</script><code contenteditable="true">await import('/components/data-display/loading.js');
const { $ } = Lightview;
const types = ['spinner', 'dots', 'ring', 'ball', 'bars', 'infinity'];
const loaders = {
div: {
style: 'display: flex; flex-wrap: wrap; gap: 2rem;',
children: types.map(type => ({
div: {
style: 'text-align: center;',
children: [
{ Loading: { type, size: 'lg' } },
{ p: { style: 'font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;', children: [type] } }
]
}
}))
}
};
$('#example').content(loaders);</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'],
styles: ['https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.min.css'],
type: 'module',
language: 'html',
minHeight: 100
});
</script><code contenteditable="true" class="language-html"><!-- Import the component (registers lv-loading) -->
<script type="module" src="/components/data-display/loading.js"></script>
<div style="display: flex; flex-wrap: wrap; gap: 2rem;">
<div style="text-align: center;">
<lv-loading type="spinner" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">spinner</p>
</div>
<div style="text-align: center;">
<lv-loading type="dots" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">dots</p>
</div>
<div style="text-align: center;">
<lv-loading type="ring" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">ring</p>
</div>
<div style="text-align: center;">
<lv-loading type="ball" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">ball</p>
</div>
<div style="text-align: center;">
<lv-loading type="bars" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">bars</p>
</div>
<div style="text-align: center;">
<lv-loading type="infinity" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">infinity</p>
</div>
</div></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">Loading Button</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Button with reactive loading
state</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: 80,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/loading.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, span, Loading, Button } = tags;
const isLoading = signal(false);
const handleClick = async () => {
isLoading.value = true;
await new Promise(r => setTimeout(r, 2000));
isLoading.value = false;
};
const demo = div({ style: 'display: flex; gap: 1rem; align-items: center;' },
() => isLoading.value
? Button({ color: 'primary', disabled: true },
Loading({ type: 'spinner', size: 'sm' }),
span({}, ' Processing...')
)
: Button({ color: 'primary', onclick: handleClick }, 'Submit'),
span({ style: 'font-size: 0.875rem; opacity: 0.7;' },
() => isLoading.value ? 'Please wait...' : 'Click the button'
)
);
$('#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: 80,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/loading.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, span, Loading, Button } = tags;
const isLoading = signal(false);
const handleClick = async () => {
isLoading.value = true;
await new Promise(r => setTimeout(r, 2000));
isLoading.value = false;
};
const demo = {
tag: div,
attributes: { style: 'display: flex; gap: 1rem; align-items: center;' },
children: [
() => isLoading.value
? {
tag: Button,
attributes: { color: 'primary', disabled: true },
children: [
{ tag: Loading, attributes: { type: 'spinner', size: 'sm' } },
{ tag: span, children: [' Processing...'] }
]
}
: {
tag: Button,
attributes: { color: 'primary', onclick: handleClick },
children: ['Submit']
},
{
tag: span,
attributes: { style: 'font-size: 0.875rem; opacity: 0.7;' },
children: [() => isLoading.value ? 'Please wait...' : 'Click the button']
}
]
};
$('#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: 80,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/loading.js');
await import('/components/actions/button.js');
const { signal, $ } = Lightview;
const isLoading = signal(false);
const handleClick = async () => {
isLoading.value = true;
await new Promise(r => setTimeout(r, 2000));
isLoading.value = false;
};
const demo = {
div: {
style: 'display: flex; gap: 1rem; align-items: center',
children: [
() => isLoading.value
? {
Button: {
color: 'primary',
disabled: true,
children: [
{ Loading: { type: 'spinner', size: 'sm' } },
{ span: { children: [' Processing...'] } }
]
}
}
: {
Button: { color: 'primary', onclick: handleClick, children: ['Submit'] }
},
{
span: {
style: 'font-size: 0.875rem; opacity: 0.7;',
children: [() => isLoading.value ? 'Please wait...' : 'Click the button']
}
}
]
}
};
$('#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>type</code></td>
<td>string</td>
<td>'spinner'</td>
<td>'spinner' | 'dots' | 'ring' | 'ball' | 'bars' | 'infinity'</td>
</tr>
<tr>
<td><code>size</code></td>
<td>string</td>
<td>'md'</td>
<td>'xs' | 'sm' | 'md' | 'lg'</td>
</tr>
<tr>
<td><code>color</code></td>
<td>string</td>
<td>-</td>
<td>Color utility class e.g. 'text-primary'</td>
</tr>
</tbody>
</table>
</div>
<!-- Loading Gallery -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Loading Gallery</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1.5rem;">
Live examples using <code><lv-loading></code> custom elements.
</p>
<script type="module" src="/components/data-display/loading.js"></script>
<!-- All Types -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">All Types</h3>
<div style="display: flex; flex-wrap: wrap; gap: 2rem; margin-bottom: 2rem;">
<div style="text-align: center;">
<lv-loading type="spinner" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">spinner</p>
</div>
<div style="text-align: center;">
<lv-loading type="dots" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">dots</p>
</div>
<div style="text-align: center;">
<lv-loading type="ring" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">ring</p>
</div>
<div style="text-align: center;">
<lv-loading type="ball" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">ball</p>
</div>
<div style="text-align: center;">
<lv-loading type="bars" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">bars</p>
</div>
<div style="text-align: center;">
<lv-loading type="infinity" size="lg"></lv-loading>
<p style="font-size: 0.875rem; margin-top: 0.5rem; opacity: 0.5;">infinity</p>
</div>
</div>
<!-- All Sizes -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">All Sizes</h3>
<div style="display: flex; align-items: center; gap: 1.5rem; margin-bottom: 2rem;">
<div style="text-align: center;">
<lv-loading type="spinner" size="xs"></lv-loading>
<p style="font-size: 0.75rem; margin-top: 0.25rem; opacity: 0.5;">xs</p>
</div>
<div style="text-align: center;">
<lv-loading type="spinner" size="sm"></lv-loading>
<p style="font-size: 0.75rem; margin-top: 0.25rem; opacity: 0.5;">sm</p>
</div>
<div style="text-align: center;">
<lv-loading type="spinner"></lv-loading>
<p style="font-size: 0.75rem; margin-top: 0.25rem; opacity: 0.5;">md</p>
</div>
<div style="text-align: center;">
<lv-loading type="spinner" size="lg"></lv-loading>
<p style="font-size: 0.75rem; margin-top: 0.25rem; opacity: 0.5;">lg</p>
</div>
</div>
<!-- With Colors -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">With Colors</h3>
<div style="display: flex; gap: 1.5rem; margin-bottom: 2rem;">
<lv-loading type="spinner" size="lg" color="text-primary"></lv-loading>
<lv-loading type="dots" size="lg" color="text-secondary"></lv-loading>
<lv-loading type="ring" size="lg" color="text-accent"></lv-loading>
<lv-loading type="ball" size="lg" color="text-success"></lv-loading>
<lv-loading type="bars" size="lg" color="text-warning"></lv-loading>
<lv-loading type="infinity" size="lg" color="text-error"></lv-loading>
</div>
</div>
</div>