lightview
Version:
A reactive UI library with features of Bau, Juris, and HTMX plus safe LLM UI generation
603 lines (563 loc) • 29 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: 'Textarea' }
]
});
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">Textarea</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;">
Textarea allows users to enter multi-line text.
Supports labels, validation, character count, 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 textareas with various
configurations</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: 380,
autoRun: true
});
</script><code contenteditable="true">await import('/components/data-input/textarea.js');
const { tags, $ } = Lightview;
const { div, Textarea } = tags;
// 1. Basic textarea
const basic = Textarea({
placeholder: 'Enter your message...',
rows: 3
});
// 2. Textarea with label and helper
const withLabel = Textarea({
label: 'Bio',
placeholder: 'Tell us about yourself...',
helper: 'Max 500 characters',
rows: 4
});
// 3. Textarea with character count
const withCount = Textarea({
label: 'Description',
placeholder: 'Product description...',
maxLength: 200,
showCount: true,
rows: 3
});
// Insert all examples
$('#example').content(
div({ style: 'display: flex; flex-direction: column; gap: 1rem' }, basic, withLabel, withCount)
);</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: 380
});
</script><code contenteditable="true">await import('/components/data-input/textarea.js');
const { $, tags } = Lightview;
const { Textarea, div } = tags;
const basic = {
tag: Textarea,
attributes: {
placeholder: 'Enter your message...',
rows: 3
}
};
const withLabel = {
tag: Textarea,
attributes: {
label: 'Bio',
placeholder: 'Tell us about yourself...',
helper: 'Max 500 characters',
rows: 4
}
};
const withCount = {
tag: Textarea,
attributes: {
label: 'Description',
placeholder: 'Product description...',
maxLength: 200,
showCount: true,
rows: 3
}
};
$('#example').content({
tag: div,
attributes: { style: 'display: flex; flex-direction: column; gap: 1rem' },
children: [basic, withLabel, withCount]
});</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: 380
});
</script><code contenteditable="true">await import('/components/data-input/textarea.js');
const { $ } = Lightview;
$('#example').content({
div: {
style: 'display: flex; flex-direction: column; gap: 1rem',
children: [
{
Textarea: {
placeholder: 'Enter your message...',
rows: 3
}
},
{
Textarea: {
label: 'Bio',
placeholder: 'Tell us about yourself...',
helper: 'Max 500 characters',
rows: 4
}
},
{
Textarea: {
label: 'Description',
placeholder: 'Product description...',
maxLength: 200,
showCount: true,
rows: 3
}
}
]
}
});</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">Reactive Example</h2>
<p class="text-sm" style="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: 220
});
</script><code contenteditable="true">await import('/components/data-input/textarea.js');
const { signal, tags, $ } = Lightview;
const { div, p, span, Textarea } = tags;
// Signal for two-way binding
const feedback = signal('');
// Validation function
const validateFeedback = (val) => {
if (!val || val.trim().length === 0) return 'Feedback is required';
if (val.length < 20) return 'Please provide more detail (at least 20 characters)';
if (val.length > 500) return 'Feedback is too long (max 500 characters)';
return null;
};
// Reactive textarea with validation
const reactiveDemo = div({ style: 'display: flex; flex-direction: column; gap: 1rem' },
Textarea({
label: 'Your Feedback',
placeholder: 'Share your thoughts with us...',
value: feedback,
validate: validateFeedback,
showCount: true,
maxLength: 500,
required: true,
rows: 4
}),
p({ class: 'text-sm' },
() => {
const error = validateFeedback(feedback.value);
return error
? span({ class: 'text-error' }, '✗ ' + error)
: span({ class: 'text-success' }, '✓ Feedback is valid!');
}
)
);
$('#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: 220
});
</script><code contenteditable="true">await import('/components/data-input/textarea.js');
const { signal, $, tags } = Lightview;
const { Textarea, div, p, span } = tags;
const feedback = signal('');
const validateFeedback = (val) => {
if (!val || val.trim().length === 0) return 'Feedback is required';
if (val.length < 20) return 'Please provide more detail (at least 20 characters)';
if (val.length > 500) return 'Feedback is too long (max 500 characters)';
return null;
};
const reactiveDemo = {
tag: div,
attributes: { style: 'display: flex; flex-direction: column; gap: 1rem' },
children: [
{
tag: Textarea,
attributes: {
label: 'Your Feedback',
placeholder: 'Share your thoughts with us...',
value: feedback,
validate: validateFeedback,
showCount: true,
maxLength: 500,
required: true,
rows: 4
}
},
{
tag: p,
attributes: { class: 'text-sm' },
children: [
() => {
const error = validateFeedback(feedback.value);
return error
? { tag: span, attributes: { class: 'text-error' }, children: ['✗ ' + error] }
: { tag: span, attributes: { class: 'text-success' }, children: ['✓ Feedback is valid!'] };
}
]
}
]
};
$('#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: 220
});
</script><code contenteditable="true">await import('/components/data-input/textarea.js');
const { signal, $ } = Lightview;
const feedback = signal('');
const validateFeedback = (val) => {
if (!val || val.trim().length === 0) return 'Feedback is required';
if (val.length < 20) return 'Please provide more detail (at least 20 characters)';
if (val.length > 500) return 'Feedback is too long (max 500 characters)';
return null;
};
const reactiveDemo = {
div: {
style: 'display: flex; flex-direction: column; gap: 1rem',
children: [
{
Textarea: {
label: 'Your Feedback',
placeholder: 'Share your thoughts with us...',
value: feedback,
validate: validateFeedback,
showCount: true,
maxLength: 500,
required: true,
rows: 4
}
},
{
p: {
class: 'text-sm',
children: [
() => {
const error = validateFeedback(feedback.value);
return error
? { span: { class: 'text-error', children: ['✗ ' + error] } }
: { span: { class: 'text-success', children: ['✓ Feedback is valid!'] } };
}
]
}
}
]
}
};
$('#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>value</code></td>
<td>string | signal</td>
<td>-</td>
<td>Textarea value (reactive with signals)</td>
</tr>
<tr>
<td><code>defaultValue</code></td>
<td>string</td>
<td>''</td>
<td>Default value for uncontrolled mode</td>
</tr>
<tr>
<td><code>placeholder</code></td>
<td>string</td>
<td>-</td>
<td>Placeholder text</td>
</tr>
<tr>
<td><code>label</code></td>
<td>string</td>
<td>-</td>
<td>Label text displayed above textarea</td>
</tr>
<tr>
<td><code>helper</code></td>
<td>string</td>
<td>-</td>
<td>Helper text displayed below the textarea</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>(value) => errorMessage | null</code></td>
</tr>
<tr>
<td><code>rows</code></td>
<td>number</td>
<td>3</td>
<td>Number of visible text lines</td>
</tr>
<tr>
<td><code>maxLength</code></td>
<td>number</td>
<td>-</td>
<td>Maximum character length</td>
</tr>
<tr>
<td><code>showCount</code></td>
<td>boolean</td>
<td>false</td>
<td>Show character count</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>ghost</code></td>
<td>boolean</td>
<td>false</td>
<td>Ghost style (no background)</td>
</tr>
<tr>
<td><code>disabled</code></td>
<td>boolean</td>
<td>false</td>
<td>Disable the textarea</td>
</tr>
<tr>
<td><code>readOnly</code></td>
<td>boolean</td>
<td>false</td>
<td>Make textarea read-only</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>(value, 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>
<!-- Sizes Example -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Sizes</h2>
<div class="example-stack" style="margin-bottom: 2rem; max-width: 28rem;">
<textarea class="textarea textarea-xs" placeholder="Extra small"></textarea>
<textarea class="textarea textarea-sm" placeholder="Small"></textarea>
<textarea class="textarea" placeholder="Medium"></textarea>
<textarea class="textarea textarea-lg" placeholder="Large"></textarea>
</div>
<!-- Colors Example -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">Colors</h2>
<div class="grid grid-cols-1 md:grid-cols-2"
style="margin-bottom: 2rem; max-width: 42rem; gap: 1rem">
<textarea class="textarea textarea-primary" placeholder="Primary"></textarea>
<textarea class="textarea textarea-secondary" placeholder="Secondary"></textarea>
<textarea class="textarea textarea-accent" placeholder="Accent"></textarea>
<textarea class="textarea textarea-info" placeholder="Info"></textarea>
<textarea class="textarea textarea-success" placeholder="Success"></textarea>
<textarea class="textarea textarea-warning" placeholder="Warning"></textarea>
<textarea class="textarea textarea-error" placeholder="Error"></textarea>
<textarea class="textarea textarea-ghost" placeholder="Ghost"></textarea>
</div>
<!-- With Fieldset -->
<h2 class="text-xl font-bold" style="margin-bottom: 1rem;">With Label (Fieldset Pattern)</h2>
<div class="max-w-md" style="margin-bottom: 2rem;">
<fieldset class="fieldset">
<legend class="fieldset-legend">Bio</legend>
<textarea class="textarea w-full" rows="4"
placeholder="Tell us about yourself..."></textarea>
<p class="label">Max 500 characters.</p>
</fieldset>
</div>
</div>
</div>
</div>
</div>