lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
486 lines (450 loc) • 23.5 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: 'Stats' }
]
});
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">Stats</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;">
Stats display numeric information with optional icons and descriptions.
Perfect for dashboards and analytics.
</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;">Dashboard stats with icons</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: 120,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/stats.js');
const { tags, $ } = Lightview;
const { Stats } = tags;
const stats = Stats({ style: 'box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);' },
Stats.Stat({},
Stats.Title({}, 'Total Users'),
Stats.Value({}, '89,400'),
Stats.Desc({}, '↗︎ 21% from last month')
),
Stats.Stat({},
Stats.Title({}, 'Page Views'),
Stats.Value({ style: 'color: oklch(var(--p));' }, '2.6M'),
Stats.Desc({}, '↗︎ 14% from last month')
),
Stats.Stat({},
Stats.Title({}, 'Conversion'),
Stats.Value({ style: 'color: oklch(var(--s));' }, '4.2%'),
Stats.Desc({}, '↘︎ 2% from last month')
)
);
$('#example').content(stats);</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: 120
});
</script><code contenteditable="true">await import('/components/data-display/stats.js');
const { $, tags } = Lightview;
const { Stats } = tags;
const stats = {
tag: Stats,
attributes: { style: 'box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);' },
children: [
{
tag: Stats.Stat,
children: [
{ tag: Stats.Title, children: ['Total Users'] },
{ tag: Stats.Value, children: ['89,400'] },
{ tag: Stats.Desc, children: ['↗︎ 21% from last month'] }
]
},
{
tag: Stats.Stat,
children: [
{ tag: Stats.Title, children: ['Page Views'] },
{ tag: Stats.Value, attributes: { style: 'color: oklch(var(--p));' }, children: ['2.6M'] },
{ tag: Stats.Desc, children: ['↗︎ 14% from last month'] }
]
},
{
tag: Stats.Stat,
children: [
{ tag: Stats.Title, children: ['Conversion'] },
{ tag: Stats.Value, attributes: { style: 'color: oklch(var(--s));' }, children: ['4.2%'] },
{ tag: Stats.Desc, children: ['↘︎ 2% from last month'] }
]
}
]
};
$('#example').content(stats);</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: 120
});
</script><code contenteditable="true">await import('/components/data-display/stats.js');
const { $ } = Lightview;
const stats = {
Stats: {
style: 'box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);',
children: [
{
'Stats.Stat': {
children: [
{ 'Stats.Title': { children: ['Total Users'] } },
{ 'Stats.Value': { children: ['89,400'] } },
{ 'Stats.Desc': { children: ['↗︎ 21% from last month'] } }
]
}
},
{
'Stats.Stat': {
children: [
{ 'Stats.Title': { children: ['Page Views'] } },
{ 'Stats.Value': { style: 'color: oklch(var(--p));', children: ['2.6M'] } },
{ 'Stats.Desc': { children: ['↗︎ 14% from last month'] } }
]
}
},
{
'Stats.Stat': {
children: [
{ 'Stats.Title': { children: ['Conversion'] } },
{ 'Stats.Value': { style: 'color: oklch(var(--s));', children: ['4.2%'] } },
{ 'Stats.Desc': { children: ['↘︎ 2% from last month'] } }
]
}
}
]
}
};
$('#example').content(stats);</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">Live Analytics</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Stats with reactive values</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/data-display/stats.js');
const { signal, tags, $ } = Lightview;
const { Stats } = tags;
const visitors = signal(1234);
const sessions = signal(567);
// Simulate live updates
setInterval(() => {
visitors.value += Math.floor(Math.random() * 10);
sessions.value += Math.floor(Math.random() * 3);
}, 2000);
const stats = Stats({ style: 'box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);' },
Stats.Stat({},
Stats.Title({}, '🟢 Live Visitors'),
Stats.Value({ style: 'color: oklch(var(--su));' }, () => visitors.value.toLocaleString()),
Stats.Desc({}, 'Currently online')
),
Stats.Stat({},
Stats.Title({}, '📊 Active Sessions'),
Stats.Value({}, () => sessions.value.toLocaleString()),
Stats.Desc({}, 'Last 5 minutes')
)
);
$('#example').content(stats);</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/data-display/stats.js');
const { signal, $, tags } = Lightview;
const { Stats } = tags;
const visitors = signal(1234);
const sessions = signal(567);
// Simulate live updates
setInterval(() => {
visitors.value += Math.floor(Math.random() * 10);
sessions.value += Math.floor(Math.random() * 3);
}, 2000);
const stats = {
tag: Stats,
attributes: { style: 'box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);' },
children: [
{
tag: Stats.Stat,
children: [
{ tag: Stats.Title, children: ['🟢 Live Visitors'] },
{ tag: Stats.Value, attributes: { style: 'color: oklch(var(--su));' }, children: [() => visitors.value.toLocaleString()] },
{ tag: Stats.Desc, children: ['Currently online'] }
]
},
{
tag: Stats.Stat,
children: [
{ tag: Stats.Title, children: ['📊 Active Sessions'] },
{ tag: Stats.Value, children: [() => sessions.value.toLocaleString()] },
{ tag: Stats.Desc, children: ['Last 5 minutes'] }
]
}
]
};
$('#example').content(stats);</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/data-display/stats.js');
const { signal, $ } = Lightview;
const visitors = signal(1234);
const sessions = signal(567);
// Simulate live updates
setInterval(() => {
visitors.value += Math.floor(Math.random() * 10);
sessions.value += Math.floor(Math.random() * 3);
}, 2000);
const stats = {
Stats: {
style: 'box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);',
children: [
{
'Stats.Stat': {
children: [
{ 'Stats.Title': { children: ['🟢 Live Visitors'] } },
{ 'Stats.Value': { style: 'color: oklch(var(--su));', children: [() => visitors.value.toLocaleString()] } },
{ 'Stats.Desc': { children: ['Currently online'] } }
]
}
},
{
'Stats.Stat': {
children: [
{ 'Stats.Title': { children: ['📊 Active Sessions'] } },
{ 'Stats.Value': { children: [() => sessions.value.toLocaleString()] } },
{ 'Stats.Desc': { children: ['Last 5 minutes'] } }
]
}
}
]
}
};
$('#example').content(stats);</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>vertical</code></td>
<td>boolean</td>
<td>false</td>
<td>Stack stats vertically</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>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Stats.Stat</code></td>
<td>Individual stat container</td>
</tr>
<tr>
<td><code>Stats.Title</code></td>
<td>Stat label</td>
</tr>
<tr>
<td><code>Stats.Value</code></td>
<td>Large numeric value</td>
</tr>
<tr>
<td><code>Stats.Desc</code></td>
<td>Description/change indicator</td>
</tr>
<tr>
<td><code>Stats.Figure</code></td>
<td>Icon/image container</td>
</tr>
</tbody>
</table>
</div>
<!-- Vertical -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Vertical Layout</h2>
<div class="stats stats-vertical"
style="box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); margin-bottom: 2rem;">
<div class="stat">
<div class="stat-title">Downloads</div>
<div class="stat-value">31K</div>
<div class="stat-desc">Jan 1st - Feb 1st</div>
</div>
<div class="stat">
<div class="stat-title">New Users</div>
<div class="stat-value">4,200</div>
<div class="stat-desc">↗︎ 400 (22%)</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>