lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
528 lines (492 loc) • 28.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: 'Alert' }
]
});
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">Alert</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;">
Alert informs users about important events or status messages.
Supports multiple colors, variants, and optional icons.
</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;">Alerts with different colors
and icons.
</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: 280,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-display/alert.js');
const { tags, $ } = Lightview;
const { div, span, Alert } = tags;
const alerts = div({ style: 'display: flex; flex-direction: column; gap: 1rem;' },
Alert({ color: 'info', icon: 'info' },
span({}, 'New update available! Click to learn more.')
),
Alert({ color: 'success', icon: 'success' },
span({}, 'Your order has been placed successfully!')
),
Alert({ color: 'warning', icon: 'warning' },
span({}, 'Please review your information before proceeding.')
),
Alert({ color: 'error', icon: 'error' },
span({}, 'Unable to connect to server. Please try again.')
)
);
$('#example').content(alerts);</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: 280
});
</script><code contenteditable="true">await import('/components/data-display/alert.js');
const { $, tags } = Lightview;
const { Alert, div, span } = tags;
const alerts = {
tag: div,
attributes: { style: 'display: flex; flex-direction: column; gap: 1rem;' },
children: [
{
tag: Alert,
attributes: { color: 'info', icon: 'info' },
children: [{ tag: span, children: ['New update available! Click to learn more.'] }]
},
{
tag: Alert,
attributes: { color: 'success', icon: 'success' },
children: [{ tag: span, children: ['Your order has been placed successfully!'] }]
},
{
tag: Alert,
attributes: { color: 'warning', icon: 'warning' },
children: [{ tag: span, children: ['Please review your information before proceeding.'] }]
},
{
tag: Alert,
attributes: { color: 'error', icon: 'error' },
children: [{ tag: span, children: ['Unable to connect to server. Please try again.'] }]
}
]
};
$('#example').content(alerts);</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: 280
});
</script><code contenteditable="true">await import('/components/data-display/alert.js');
const { $ } = Lightview;
const alerts = {
div: {
style: 'display: flex; flex-direction: column; gap: 1rem;',
children: [
{ Alert: { color: 'info', icon: 'info', children: ['New update available! Click to learn more.'] } },
{ Alert: { color: 'success', icon: 'success', children: ['Your order has been placed successfully!'] } },
{ Alert: { color: 'warning', icon: 'warning', children: ['Please review your information before proceeding.'] } },
{ Alert: { color: 'error', icon: 'error', children: ['Unable to connect to server. Please try again.'] } }
]
}
};
$('#example').content(alerts);</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: 280
});
</script><code contenteditable="true" class="language-html"><!-- Import the component (registers lv-alert) -->
<script type="module" src="/components/data-display/alert.js"></script>
<div style="display: flex; flex-direction: column; gap: 1rem;">
<lv-alert color="info" icon="info">New update available!</lv-alert>
<lv-alert color="success" icon="success">Your order has been placed!</lv-alert>
<lv-alert color="warning" icon="warning">Please review before proceeding.</lv-alert>
<lv-alert color="error" icon="error">Connection failed.</lv-alert>
</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">Dismissible Alert</h2>
<p class="text-sm" style="opacity: 0.7; margin-bottom: 1rem;">Alert with close button using
signals.</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: 100
});
</script><code contenteditable="true">await import('/components/data-display/alert.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, span, Alert, Button } = tags;
const visible = signal(true);
const demo = div({},
() => visible.value
? Alert({ color: 'success', icon: 'success' },
span({}, 'Message sent successfully!'),
Button({
size: 'sm',
color: 'ghost',
onclick: () => { visible.value = false; }
}, '✕')
)
: div({ style: 'display: flex; gap: 0.5rem;' },
span({ style: 'font-size: 0.875rem; opacity: 0.5;' }, 'Alert dismissed'),
Button({
size: 'sm',
color: 'primary',
onclick: () => { visible.value = true; }
}, 'Show again')
)
);
$('#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: 100
});
</script><code contenteditable="true">await import('/components/data-display/alert.js');
await import('/components/actions/button.js');
const { signal, $, tags } = Lightview;
const { div, span, Alert, Button } = tags;
const visible = signal(true);
const demo = {
tag: div,
children: [
() => visible.value
? {
tag: Alert,
attributes: { color: 'success', icon: 'success' },
children: [
{ tag: span, children: ['Message sent successfully!'] },
{
tag: Button,
attributes: { size: 'sm', color: 'ghost', onclick: () => { visible.value = false; } },
children: ['✕']
}
]
}
: {
tag: div,
attributes: { style: 'display: flex; gap: 0.5rem;' },
children: [
{ tag: span, attributes: { style: 'font-size: 0.875rem; opacity: 0.5;' }, children: ['Alert dismissed'] },
{
tag: Button,
attributes: { size: 'sm', color: 'primary', onclick: () => { visible.value = true; } },
children: ['Show again']
}
]
}
]
};
$('#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: 100
});
</script><code contenteditable="true">await import('/components/data-display/alert.js');
await import('/components/actions/button.js');
const { signal, $ } = Lightview;
const visible = signal(true);
const demo = {
div: {
children: [
() => visible.value
? {
Alert: {
color: 'success',
icon: 'success',
children: [
'Message sent successfully!',
{ Button: { size: 'sm', color: 'ghost', onclick: () => { visible.value = false; }, children: ['✕'] } }
]
}
}
: {
div: {
style: 'display: flex; gap: 0.5rem;',
children: [
{ span: { style: 'font-size: 0.875rem; opacity: 0.5;', children: ['Alert dismissed'] } },
{ Button: { size: 'sm', color: 'primary', onclick: () => { visible.value = true; }, children: ['Show again'] } }
]
}
}
]
}
};
$('#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>'info' | 'success' | 'warning' | 'error'</td>
</tr>
<tr>
<td><code>icon</code></td>
<td>string</td>
<td>-</td>
<td>Auto-icon: 'info' | 'success' | 'warning' | 'error'</td>
</tr>
<tr>
<td><code>soft</code></td>
<td>boolean</td>
<td>false</td>
<td>Use soft/light background variant</td>
</tr>
<tr>
<td><code>outline</code></td>
<td>boolean</td>
<td>false</td>
<td>Use outlined border style</td>
</tr>
<tr>
<td><code>dash</code></td>
<td>boolean</td>
<td>false</td>
<td>Use dashed border style</td>
</tr>
</tbody>
</table>
</div>
<!-- Colors -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Colors</h2>
<div style="display: flex; flex-direction: column; gap: 1rem; margin-bottom: 2rem;">
<div role="alert" class="alert">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
style="width: 1.25rem; height: 1.25rem; stroke: oklch(var(--in));">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span>Default alert — neutral information message.</span>
</div>
<div role="alert" class="alert alert-info">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
style="width: 1.25rem; height: 1.25rem; stroke: currentColor;">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span>Info alert — informational message.</span>
</div>
<div role="alert" class="alert alert-success">
<svg xmlns="http://www.w3.org/2000/svg"
style="width: 1.25rem; height: 1.25rem; stroke: currentColor;" fill="none"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span>Success alert — operation completed successfully.</span>
</div>
<div role="alert" class="alert alert-warning">
<svg xmlns="http://www.w3.org/2000/svg"
style="width: 1.25rem; height: 1.25rem; stroke: currentColor;" fill="none"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
<span>Warning alert — caution is advised.</span>
</div>
<div role="alert" class="alert alert-error">
<svg xmlns="http://www.w3.org/2000/svg"
style="width: 1.25rem; height: 1.25rem; stroke: currentColor;" fill="none"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<span>Error alert — something went wrong!</span>
</div>
</div>
<!-- Variants -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Variants</h2>
<div style="display: flex; flex-direction: column; gap: 1rem; margin-bottom: 2rem;">
<div role="alert" class="alert alert-soft alert-info">
<span>Soft variant — lighter background.</span>
</div>
<div role="alert" class="alert alert-outline alert-success">
<span>Outline variant — bordered style.</span>
</div>
<div role="alert" class="alert alert-dash alert-warning">
<span>Dash variant — dashed border.</span>
</div>
</div>
<!-- With Actions -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">With Actions</h2>
<div role="alert" class="alert" style="margin-bottom: 2rem;">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
class="stroke-info icon-sm">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span>We have sent an email with a confirmation link.</span>
<div>
<button class="btn btn-sm">Dismiss</button>
<button class="btn btn-sm btn-primary">See</button>
</div>
</div>
</div>
</div>
</div>
</div>