lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
661 lines (617 loc) • 32.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: 'Checkbox' }
]
});
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">Checkbox</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;">
Checkbox allows the user to select one or multiple items from a set.
Supports labels, descriptions, validation, and reactive state binding.
</p>
<!-- Basic Examples -->
<div class="card bg-base-200" style="margin-bottom: 2rem;">
<div class="card-body">
<h2 class="card-title">Basic Examples</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Simple checkboxes with various
configurations</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-input/checkbox.js');
const { tags, $ } = Lightview;
const { div, Checkbox } = tags;
// 1. Basic checkbox
const basic = Checkbox({
label: 'Remember me'
});
// 2. Checkbox with description
const withDesc = Checkbox({
label: 'Subscribe to newsletter',
description: 'Get weekly updates on new features',
color: 'primary'
});
// 3. Required checkbox
const required = Checkbox({
label: 'I agree to the terms and conditions',
required: true
});
// 4. Pre-checked disabled checkbox
const disabled = Checkbox({
label: 'This option is locked',
defaultChecked: true,
disabled: true
});
// Insert all examples
$('#example').content(
div({ style: 'display: flex; flex-direction: column; gap: 1rem;' }, basic, withDesc, required, disabled)
);</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-input/checkbox.js');
const { $, tags } = Lightview;
const { Checkbox, div } = tags;
const basic = {
tag: Checkbox,
attributes: { label: 'Remember me' }
};
const withDesc = {
tag: Checkbox,
attributes: {
label: 'Subscribe to newsletter',
description: 'Get weekly updates on new features',
color: 'primary'
}
};
const required = {
tag: Checkbox,
attributes: {
label: 'I agree to the terms and conditions',
required: true
}
};
const disabled = {
tag: Checkbox,
attributes: {
label: 'This option is locked',
defaultChecked: true,
disabled: true
}
};
$('#example').content({
tag: div,
attributes: { style: 'display: flex; flex-direction: column; gap: 1rem;' },
children: [basic, withDesc, required, disabled]
});</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-input/checkbox.js');
const { tags, $ } = Lightview;
$('#example').content({
div: {
style: 'display: flex; flex-direction: column; gap: 1rem;',
children: [
{ Checkbox: { label: 'Remember me' } },
{
Checkbox: {
label: 'Subscribe to newsletter',
description: 'Get weekly updates on new features',
color: 'primary'
}
},
{
Checkbox: {
label: 'I agree to the terms and conditions',
required: true
}
},
{
Checkbox: {
label: 'This option is locked',
defaultChecked: true,
disabled: true
}
}
]
}
});</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-checkbox) -->
<script type="module" src="/components/data-input/checkbox.js"></script>
<div style="display: flex; flex-direction: column; gap: 1rem;">
<lv-checkbox label="Remember me"></lv-checkbox>
<lv-checkbox label="Subscribe to newsletter" description="Get weekly updates on new features" color="primary"></lv-checkbox>
<lv-checkbox label="I agree to the terms and conditions" required></lv-checkbox>
<lv-checkbox label="This option is locked" default-checked disabled></lv-checkbox>
</div></code></pre>
</div>
</div>
</div>
<!-- Reactive Example -->
<div
style="background-color: oklch(var(--b2)); border-radius: var(--rounded-box, 1rem); box-shadow: var(--shadow-2, 0 25px 50px -12px rgba(0,0,0,0.25)); margin-bottom: 2rem;">
<div style="padding: var(--padding-card, 2rem);">
<h2 style="font-size: 1.5rem; font-weight: 600; line-height: 2rem; margin-bottom: 0.5rem;">
Reactive Example</h2>
<p style="font-size: 0.875rem; opacity: 0.7; margin-bottom: 1rem;">Two-way binding with
signals
and live
validation</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: 320
});
</script><code contenteditable="true">await import('/components/data-input/checkbox.js');
const { signal, tags, $ } = Lightview;
const { div, p, span, button, Checkbox } = tags;
// Signals for checkboxes
const notifications = signal(true);
const marketing = signal(false);
const termsAccepted = signal(false);
// Reactive demo
const reactiveDemo = div({ style: 'display: flex; flex-direction: column; gap: 1rem; max-width: 28rem;' },
Checkbox({
label: 'Email Notifications',
description: 'Receive important updates via email',
checked: notifications,
color: 'primary'
}),
Checkbox({
label: 'Marketing Emails',
description: 'Promotional content and offers',
checked: marketing,
color: 'secondary'
}),
Checkbox({
label: 'Accept Terms & Conditions',
checked: termsAccepted,
required: true,
color: 'accent',
validate: (checked) => !checked ? 'You must accept the terms' : null
}),
div({ style: 'padding-top: 1rem; border-top: 1px solid oklch(var(--b3));' },
p({ style: 'font-size: 0.875rem; font-family: monospace;' },
() => `Notifications: ${notifications.value}, Marketing: ${marketing.value}`
),
button({
class: 'btn btn-primary',
style: () => `margin-top: 0.5rem; ${termsAccepted.value ? '' : 'opacity: 0.5; pointer-events: none;'}`,
disabled: () => !termsAccepted.value
}, 'Submit')
)
);
$('#example').content(reactiveDemo);</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: 320
});
</script><code contenteditable="true">await import('/components/data-input/checkbox.js');
const { signal, $, tags } = Lightview;
const { Checkbox, div, p, button } = tags;
const notifications = signal(true);
const marketing = signal(false);
const termsAccepted = signal(false);
const reactiveDemo = {
tag: div,
attributes: { style: 'display: flex; flex-direction: column; gap: 1rem; max-width: 28rem;' },
children: [
{
tag: Checkbox,
attributes: {
label: 'Email Notifications',
description: 'Receive important updates via email',
checked: notifications,
color: 'primary'
}
},
{
tag: Checkbox,
attributes: {
label: 'Marketing Emails',
description: 'Promotional content and offers',
checked: marketing,
color: 'secondary'
}
},
{
tag: Checkbox,
attributes: {
label: 'Accept Terms & Conditions',
checked: termsAccepted,
required: true,
color: 'accent',
validate: (checked) => !checked ? 'You must accept the terms' : null
}
},
{
tag: div,
attributes: { style: 'padding-top: 1rem; border-top: 1px solid oklch(var(--b3));' },
children: [
{
tag: p,
attributes: { style: 'font-size: 0.875rem; font-family: monospace;' },
children: [
() => `Notifications: ${notifications.value}, Marketing: ${marketing.value}`
]
},
{
tag: button,
attributes: {
class: 'btn btn-primary',
style: () => `margin-top: 0.5rem; ${termsAccepted.value ? '' : 'opacity: 0.5; pointer-events: none;'}`,
disabled: () => !termsAccepted.value
},
children: ['Submit']
}
]
}
]
};
$('#example').content(reactiveDemo);</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: 320
});
</script><code contenteditable="true">await import('/components/data-input/checkbox.js');
const { signal, tags, $ } = Lightview;
const notifications = signal(true);
const marketing = signal(false);
const termsAccepted = signal(false);
const reactiveDemo = {
div: {
style: 'display: flex; flex-direction: column; gap: 1rem; max-width: 28rem;',
children: [
{
Checkbox: {
label: 'Email Notifications',
description: 'Receive important updates via email',
checked: notifications,
color: 'primary'
}
},
{
Checkbox: {
label: 'Marketing Emails',
description: 'Promotional content and offers',
checked: marketing,
color: 'secondary'
}
},
{
Checkbox: {
label: 'Accept Terms & Conditions',
checked: termsAccepted,
required: true,
color: 'accent',
validate: (checked) => !checked ? 'You must accept the terms' : null
}
},
{
div: {
style: 'padding-top: 1rem; border-top: 1px solid oklch(var(--b3));',
children: [
{
p: {
style: 'font-size: 0.875rem; font-family: monospace;',
children: [() => `Notifications: ${notifications.value}, Marketing: ${marketing.value}`]
}
},
{
button: {
class: 'btn btn-primary',
style: () => `margin-top: 0.5rem; ${termsAccepted.value ? '' : 'opacity: 0.5; pointer-events: none;'}`,
disabled: () => !termsAccepted.value,
children: ['Submit']
}
}
]
}
}
]
}
};
$('#example').content(reactiveDemo);</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>checked</code></td>
<td>boolean | signal</td>
<td>-</td>
<td>Checked state (reactive with signals)</td>
</tr>
<tr>
<td><code>defaultChecked</code></td>
<td>boolean</td>
<td>false</td>
<td>Default checked state for uncontrolled mode</td>
</tr>
<tr>
<td><code>indeterminate</code></td>
<td>boolean</td>
<td>false</td>
<td>Indeterminate (partial) state</td>
</tr>
<tr>
<td><code>label</code></td>
<td>string</td>
<td>-</td>
<td>Label text displayed next to checkbox</td>
</tr>
<tr>
<td><code>description</code></td>
<td>string</td>
<td>-</td>
<td>Description text below the label</td>
</tr>
<tr>
<td><code>error</code></td>
<td>string | function</td>
<td>-</td>
<td>Error message or reactive error function</td>
</tr>
<tr>
<td><code>validate</code></td>
<td>function</td>
<td>-</td>
<td>Validation function: <code>(checked) => errorMessage | null</code></td>
</tr>
<tr>
<td><code>color</code></td>
<td>string</td>
<td>-</td>
<td>'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error'
</td>
</tr>
<tr>
<td><code>size</code></td>
<td>string</td>
<td>'md'</td>
<td>'xs' | 'sm' | 'md' | 'lg'</td>
</tr>
<tr>
<td><code>disabled</code></td>
<td>boolean</td>
<td>false</td>
<td>Disable the checkbox</td>
</tr>
<tr>
<td><code>required</code></td>
<td>boolean</td>
<td>false</td>
<td>Mark as required field (shows asterisk)</td>
</tr>
<tr>
<td><code>onChange</code></td>
<td>function</td>
<td>-</td>
<td>Callback when value changes: <code>(checked, event) => void</code></td>
</tr>
<tr>
<td><code>useShadow</code></td>
<td>boolean</td>
<td>*</td>
<td>Render in Shadow DOM. *Follows global <code>initComponents()</code> setting</td>
</tr>
</tbody>
</table>
</div>
<!-- Custom Element Gallery -->
<h2 class="text-xl font-bold" style="margin-top: 2rem; margin-bottom: 1rem;">Checkbox Gallery</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1.5rem;">
Live examples using <code><lv-checkbox></code> custom elements.
</p>
<script type="module" src="/components/data-input/checkbox.js"></script>
<!-- Colors -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">Colors</h3>
<div style="display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 2rem;">
<lv-checkbox label="Default" checked></lv-checkbox>
<lv-checkbox label="Primary" color="primary" checked></lv-checkbox>
<lv-checkbox label="Secondary" color="secondary" checked></lv-checkbox>
<lv-checkbox label="Accent" color="accent" checked></lv-checkbox>
<lv-checkbox label="Info" color="info" checked></lv-checkbox>
<lv-checkbox label="Success" color="success" checked></lv-checkbox>
<lv-checkbox label="Warning" color="warning" checked></lv-checkbox>
<lv-checkbox label="Error" color="error" checked></lv-checkbox>
</div>
<!-- Sizes -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">Sizes</h3>
<div style="display: flex; align-items: center; flex-wrap: wrap; gap: 1.5rem; margin-bottom: 2rem;">
<lv-checkbox size="xs" label="Extra Small" checked></lv-checkbox>
<lv-checkbox size="sm" label="Small" checked></lv-checkbox>
<lv-checkbox size="md" label="Medium" checked></lv-checkbox>
<lv-checkbox size="lg" label="Large" checked></lv-checkbox>
</div>
<!-- States -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">States</h3>
<div
style="display: flex; flex-direction: column; gap: 1rem; margin-bottom: 2rem; max-width: 20rem;">
<lv-checkbox label="Disabled Unchecked" disabled></lv-checkbox>
<lv-checkbox label="Disabled Checked" checked disabled></lv-checkbox>
<lv-checkbox label="Required Field" required></lv-checkbox>
<lv-checkbox label="Indeterminate" indeterminate="true"></lv-checkbox>
</div>
<!-- Descriptions -->
<h3 class="text-lg font-semibold" style="margin-bottom: 0.75rem;">With Descriptions</h3>
<div
style="display: flex; flex-direction: column; gap: 1.5rem; margin-bottom: 2rem; max-width: 28rem;">
<lv-checkbox label="Email Notifications"
description="Receive updates about your account activity." color="primary" checked>
</lv-checkbox>
<lv-checkbox label="Marketing" description="We'll send you occasional promotions and news."
color="secondary">
</lv-checkbox>
</div>
</div>
</div>
</div>
</div>