lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
586 lines (541 loc) • 30.1 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: 'Badge' }
]
});
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">Badge</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;">
Badges are used to inform the user of the status of specific data.
Perfect for notifications, labels, and status indicators.
</p>
<!-- Basic Usage -->
<div class="card bg-base-200" style="margin-bottom: 2rem;">
<div class="card-body">
<h2 class="card-title">Basic Usage</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Badges with different colors
and variants.
</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/badge.js');
const { tags, $ } = Lightview;
const { div, Badge } = tags;
const badges = div({ style: 'display: flex; flex-direction: column; gap: 1rem;' },
// Colors
div({ style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
Badge({}, 'Default'),
Badge({ color: 'primary' }, 'Primary'),
Badge({ color: 'secondary' }, 'Secondary'),
Badge({ color: 'accent' }, 'Accent'),
Badge({ color: 'info' }, 'Info'),
Badge({ color: 'success' }, 'Success'),
Badge({ color: 'warning' }, 'Warning'),
Badge({ color: 'error' }, 'Error')
),
// Variants
div({ style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
Badge({ variant: 'outline' }, 'Outline'),
Badge({ variant: 'soft', color: 'primary' }, 'Soft'),
Badge({ variant: 'dash', color: 'secondary' }, 'Dash')
)
);
$('#example').content(badges);</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/badge.js');
const { $, tags } = Lightview;
const { Badge, div } = tags;
const badges = {
tag: div,
attributes: { style: 'display: flex; flex-direction: column; gap: 0.5rem;' },
children: [
{
tag: div,
attributes: { style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
children: [
{ tag: Badge, children: ['Default'] },
{ tag: Badge, attributes: { color: 'primary' }, children: ['Primary'] },
{ tag: Badge, attributes: { color: 'secondary' }, children: ['Secondary'] },
{ tag: Badge, attributes: { color: 'accent' }, children: ['Accent'] },
{ tag: Badge, attributes: { color: 'info' }, children: ['Info'] },
{ tag: Badge, attributes: { color: 'success' }, children: ['Success'] },
{ tag: Badge, attributes: { color: 'warning' }, children: ['Warning'] },
{ tag: Badge, attributes: { color: 'error' }, children: ['Error'] }
]
},
{
tag: div,
attributes: { style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
children: [
{ tag: Badge, attributes: { variant: 'outline' }, children: ['Outline'] },
{ tag: Badge, attributes: { variant: 'soft', color: 'primary' }, children: ['Soft'] },
{ tag: Badge, attributes: { variant: 'dash', color: 'secondary' }, children: ['Dash'] }
]
}
]
};
$('#example').content(badges);</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/badge.js');
const { $ } = Lightview;
const badges = {
div: {
style: 'display: flex; flex-direction: column; gap: 0.5rem;',
children: [
{
div: {
style: 'display: flex; flex-direction: row; gap: 0.5rem;',
children: [
{ Badge: { children: ['Default'] } },
{ Badge: { color: 'primary', children: ['Primary'] } },
{ Badge: { color: 'secondary', children: ['Secondary'] } },
{ Badge: { color: 'accent', children: ['Accent'] } },
{ Badge: { color: 'info', children: ['Info'] } },
{ Badge: { color: 'success', children: ['Success'] } },
{ Badge: { color: 'warning', children: ['Warning'] } },
{ Badge: { color: 'error', children: ['Error'] } }
]
}
},
{
div: {
style: 'display: flex; flex-direction: row; gap: 0.5rem;',
children: [
{ Badge: { variant: 'outline', children: ['Outline'] } },
{ Badge: { variant: 'soft', color: 'primary', children: ['Soft'] } },
{ Badge: { variant: 'dash', color: 'secondary', children: ['Dash'] } }
]
}
}
]
}
};
$('#example').content(badges);</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-badge) -->
<script type="module" src="/components/data-display/badge.js"></script>
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
<div style="display: flex; gap: 0.5rem;">
<lv-badge>Default</lv-badge>
<lv-badge color="primary">Primary</lv-badge>
<lv-badge color="secondary">Secondary</lv-badge>
<lv-badge color="accent">Accent</lv-badge>
</div>
<div style="display: flex; gap: 0.5rem;">
<lv-badge variant="outline">Outline</lv-badge>
<lv-badge variant="soft" color="primary">Soft</lv-badge>
</div>
</div></code></pre>
</div>
</div>
</div>
<!-- Reactive Example -->
<div class="card bg-base-200" style="margin-bottom: 2rem;">
<div class="card-body">
<h2 class="card-title">Notification Counter</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Reactive badge showing
notification count.
</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
});
</script><code contenteditable="true">await import('/components/data-display/badge.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, Badge, Button } = tags;
const count = signal(5);
const demo = div({ style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
Button({
size: 'sm',
color: 'primary',
onclick: () => { count.value++; }
}, '+ Add Message'),
Button({},
'Inbox',
Badge({
color: 'secondary',
style: 'margin-left: 0.5rem;'
}, () => count.value > 99 ? '99+' : count.value)
),
Button({
size: 'sm',
onclick: () => { count.value = 0; }
}, 'Clear')
);
$('#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
});
</script><code contenteditable="true">await import('/components/data-display/badge.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, Badge, Button } = tags;
const count = signal(5);
const demo = {
tag: div,
attributes: { style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
children: [
{
tag: Button,
attributes: { size: 'sm', color: 'primary', onclick: () => { count.value++; } },
children: ['+ Add Message']
},
{
tag: Button,
children: [
'Inbox',
{
tag: Badge,
attributes: { color: 'secondary', style: 'margin-left: 0.5rem;' },
children: [() => count.value > 99 ? '99+' : count.value]
}
]
},
{
tag: Button,
attributes: { size: 'sm', onclick: () => { count.value = 0; } },
children: ['Clear']
}
]
};
$('#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
});
</script><code contenteditable="true">await import('/components/data-display/badge.js');
await import('/components/actions/button.js');
const { signal, $ } = Lightview;
const count = signal(5);
const demo = {
div: {
style: 'display: flex; flex-direction: row; gap: 0.5rem;',
children: [
{
Button: {
size: 'sm',
color: 'primary',
onclick: () => { count.value++; },
children: ['+ Add Message']
}
},
{
Button: {
children: [
'Inbox',
{
Badge: {
color: 'secondary',
style: 'margin-left: 0.5rem;',
children: [() => count.value > 99 ? '99+' : count.value]
}
}
]
}
},
{
Button: {
size: 'sm',
onclick: () => { count.value = 0; },
children: ['Clear']
}
}
]
}
};
$('#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>color</code></td>
<td>string</td>
<td>-</td>
<td>'primary' | 'secondary' | 'accent' | 'success' | 'warning' | 'info' | 'error' |
'ghost' |
'neutral'</td>
</tr>
<tr>
<td><code>size</code></td>
<td>string</td>
<td>'md'</td>
<td>'xs' | 'sm' | 'md' | 'lg'</td>
</tr>
<tr>
<td><code>variant</code></td>
<td>string</td>
<td>-</td>
<td>'outline' | 'soft' | 'dash'</td>
</tr>
</tbody>
</table>
</div>
<!-- Colors -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Colors</h2>
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 2rem;">
<span class="badge">Default</span>
<span class="badge badge-neutral">Neutral</span>
<span class="badge badge-primary">Primary</span>
<span class="badge badge-secondary">Secondary</span>
<span class="badge badge-accent">Accent</span>
<span class="badge badge-ghost">Ghost</span>
<span class="badge badge-info">Info</span>
<span class="badge badge-success">Success</span>
<span class="badge badge-warning">Warning</span>
<span class="badge badge-error">Error</span>
</div>
<!-- Variants -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Variants</h2>
<div style="display: flex; gap: 0.5rem; margin-bottom: 2rem;">
<span class="badge badge-outline">Outline</span>
<span class="badge badge-soft badge-primary">Soft</span>
<span class="badge badge-dash badge-secondary">Dash</span>
</div>
<!-- Sizes -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Sizes</h2>
<div style="display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem;">
<span class="badge badge-xs">xs</span>
<span class="badge badge-sm">sm</span>
<span class="badge badge-md">md</span>
<span class="badge badge-lg">lg</span>
</div>
<!-- In Button -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">In Button</h2>
<div style="display: flex; gap: 0.5rem; margin-bottom: 2rem;">
<button class="btn">
Inbox
<div class="badge">99+</div>
</button>
<button class="btn">
Notifications
<div class="badge badge-secondary">+99</div>
</button>
</div>
<!-- Custom Element Gallery -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Custom Element Gallery</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">
Live examples using <code><lv-badge></code> custom elements with various options.
</p>
<script type="module" src="/components/data-display/badge.js"></script>
<!-- All Colors -->
<h3 class="text-lg font-semibold" style="margin-top: 1.5rem; margin-bottom: 0.75rem;">All Colors
</h3>
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem;">
<lv-badge>Default</lv-badge>
<lv-badge color="neutral">Neutral</lv-badge>
<lv-badge color="primary">Primary</lv-badge>
<lv-badge color="secondary">Secondary</lv-badge>
<lv-badge color="accent">Accent</lv-badge>
<lv-badge color="ghost">Ghost</lv-badge>
<lv-badge color="info">Info</lv-badge>
<lv-badge color="success">Success</lv-badge>
<lv-badge color="warning">Warning</lv-badge>
<lv-badge color="error">Error</lv-badge>
</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: 1rem; margin-bottom: 1.5rem;">
<lv-badge size="xs" color="primary">Extra Small</lv-badge>
<lv-badge size="sm" color="primary">Small</lv-badge>
<lv-badge size="md" color="primary">Medium</lv-badge>
<lv-badge size="lg" color="primary">Large</lv-badge>
</div>
<!-- All Variants -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">All Variants</h3>
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem;">
<lv-badge color="primary">Solid</lv-badge>
<lv-badge variant="outline" color="primary">Outline</lv-badge>
<lv-badge variant="soft" color="primary">Soft</lv-badge>
<lv-badge variant="dash" color="primary">Dash</lv-badge>
</div>
<!-- Mixed Combinations -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">Mixed Combinations</h3>
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 2rem;">
<lv-badge size="xs" color="success">New</lv-badge>
<lv-badge size="sm" variant="outline" color="info">Beta</lv-badge>
<lv-badge variant="soft" color="warning">Hot</lv-badge>
<lv-badge size="lg" variant="dash" color="error">Sale</lv-badge>
<lv-badge color="secondary">v2.0</lv-badge>
<lv-badge size="xs" variant="outline" color="accent">Pro</lv-badge>
<lv-badge size="sm" variant="soft" color="success">Updated</lv-badge>
<lv-badge variant="dash" color="neutral">Draft</lv-badge>
</div>
</div>
</div>
</div>
</div>
</div>