Files
WRNexusJSDoc/app/pages/components/accordion.wrn
T

233 lines
14 KiB
Plaintext

page Accordioncomponent {
seo {
title = "Accordion component"
description = "Theme-aware, responsive accordion component."
}
view {
<div class="docs-shell">
<SkipLink label="Skip to content" href="#main" class="docs-skip-link" />
<header class="topbar">
<a class="brand" href="/"><span>W</span> WRNexusJS</a>
<nav aria-label="Primary"><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/components">Components</a><a href="/language">Language</a><a href="/architecture">Architecture</a></nav>
<div class="topbar-actions"><a class="preview-pill" href="/access">Private preview · v0.5.0</a><button data-wire-theme-toggle class="theme-button" aria-label="Toggle color theme" title="Toggle color theme">◐</button></div>
</header>
<div class="mobile-doc-nav"><details><summary>Browse documentation</summary><nav><a href="/getting-started">Get started</a><a href="/packages">Packages</a><a href="/components">Components</a><a href="/language">Language</a><a href="/architecture">Architecture</a><a href="/tutorial">Tutorial</a><a href="/guides/project-structure">Guides</a><a href="/examples">Examples</a><a href="/search">Search</a></nav></details></div>
<main class="portal-main docs-layout component-detail-page"><article id="main" class="documentation prose standalone"><nav class="breadcrumbs" aria-label="Breadcrumb"><a href="/">Home</a><span>/</span><a href="/components">Components</a><span>/</span><span aria-current="page">Accordion</span></nav><section class="doc-intro"><span class="eyebrow">base component</span><h1>Accordion</h1><p>Theme-aware, responsive accordion component.</p><div class="doc-meta"><span>@wrnexus/ui 0.5.0</span><span>17 props</span><span>0 slots</span><span>3 events</span></div></section><section id="usage"><h2>Usage</h2><p>Components are auto-discovered. Use the component directly in any <code>.wrn</code> view:</p><pre data-language="wrn"><code>&lt;Accordion
size=&quot;default&quot;
color=&quot;primary&quot;
variant=&quot;default&quot;
id=&quot;accordion&quot;
items=&quot;[]&quot;
/&gt;</code></pre><p>Legacy mount name: <code>data-component=&quot;Accordion&quot;</code>.</p></section><section id="props"><h2>Props and attributes</h2><div class="table-wrap"><table><thead><tr><th>Prop</th><th>Type</th><th>Requirement</th><th>Default</th></tr></thead><tbody><tr><td><code>size</code></td><td><code>string</code></td><td>Optional</td><td><code>&quot;default&quot;</code></td></tr><tr><td><code>color</code></td><td><code>string</code></td><td>Optional</td><td><code>&quot;primary&quot;</code></td></tr><tr><td><code>variant</code></td><td><code>string</code></td><td>Optional</td><td><code>&quot;default&quot;</code></td></tr><tr><td><code>class</code></td><td><code>string</code></td><td>Optional</td><td><code>&quot;&quot;</code></td></tr><tr><td><code>id</code></td><td><code>string</code></td><td>Optional</td><td><code>&quot;accordion&quot;</code></td></tr><tr><td><code>items</code></td><td><code>string</code></td><td>Optional</td><td><code>[]</code></td></tr><tr><td><code>defaultOpen</code></td><td><code>string</code></td><td>Optional</td><td><code>[]</code></td></tr><tr><td><code>multiple</code></td><td><code>boolean</code></td><td>Optional</td><td><code>false</code></td></tr><tr><td><code>alwaysOpen</code></td><td><code>boolean</code></td><td>Optional</td><td><code>false</code></td></tr><tr><td><code>disabled</code></td><td><code>boolean</code></td><td>Optional</td><td><code>false</code></td></tr><tr><td><code>indicator</code></td><td><code>string</code></td><td>Optional</td><td><code>&quot;plus&quot;</code></td></tr><tr><td><code>indicatorPosition</code></td><td><code>string</code></td><td>Optional</td><td><code>&quot;start&quot;</code></td></tr><tr><td><code>showIndicator</code></td><td><code>boolean</code></td><td>Optional</td><td><code>true</code></td></tr><tr><td><code>bordered</code></td><td><code>boolean</code></td><td>Optional</td><td><code>false</code></td></tr><tr><td><code>separated</code></td><td><code>boolean</code></td><td>Optional</td><td><code>false</code></td></tr><tr><td><code>flush</code></td><td><code>boolean</code></td><td>Optional</td><td><code>false</code></td></tr><tr><td><code>contentItalic</code></td><td><code>boolean</code></td><td>Optional</td><td><code>false</code></td></tr></tbody></table></div></section><section id="slots"><h2>Slots</h2><p>This component does not declare a slot.</p></section><section id="events"><h2>Events</h2><ul><li><code>change</code></li><li><code>open</code></li><li><code>close</code></li></ul></section><section id="source"><h2>Source contract</h2><p>Installed source: <code>components/Accordion.wrn</code></p><pre data-language="wrn"><code>component Accordion &#123;
props &#123;
size = &quot;default&quot;
color = &quot;primary&quot;
variant = &quot;default&quot;
class = &quot;&quot;
id = &quot;accordion&quot;
items = []
defaultOpen = []
multiple = false
alwaysOpen = false
disabled = false
indicator = &quot;plus&quot;
indicatorPosition = &quot;start&quot;
showIndicator = true
bordered = false
separated = false
flush = false
contentItalic = false
@event change = function
@event open = function
@event close = function
&#125;
state openValues = defaultOpen
functions &#123;
function itemValue(item, index) &#123;
return item.value !== undefined &amp;&amp; item.value !== &quot;&quot;
? String(item.value)
: String(index)
&#125;
function nestedValue(parent, parentIndex, item, index) &#123;
return itemValue(parent, parentIndex) + &quot;.&quot; + itemValue(item, index)
&#125;
function isOpen(value) &#123;
return openValues.includes(value)
&#125;
function allowsMultiple() &#123;
return multiple || alwaysOpen
&#125;
function dispatchAccordionEvent(sourceEvent, eventName, value, item, root, customEvent) &#123;
root = sourceEvent.currentTarget.closest(&quot;[data-wrn-accordion]&quot;)
if (!root) &#123;
return
&#125;
customEvent = document.createEvent(&quot;CustomEvent&quot;)
customEvent.initCustomEvent(eventName, true, false, &#123;
component: &quot;Accordion&quot;,
value: value,
item: item,
open: isOpen(value),
openValues: openValues
&#125;)
root.dispatchEvent(customEvent)
&#125;
function toggleItem(sourceEvent, value, item, wasOpen) &#123;
if (disabled || item.disabled) &#123;
return
&#125;
wasOpen = isOpen(value)
if (wasOpen) &#123;
openValues = openValues.filter((entry) =&gt; entry !== value)
&#125; else if (allowsMultiple()) &#123;
openValues = openValues.concat([value])
&#125; else &#123;
openValues = [value]
&#125;
dispatchAccordionEvent(
sourceEvent,
wasOpen ? &quot;close&quot; : &quot;open&quot;,
value,
item
)
dispatchAccordionEvent(sourceEvent, &quot;change&quot;, value, item)
&#125;
&#125;
view &#123;
&lt;div
&#123;...attrs&#125;
id=&quot;&#123;id&#125;&quot;
data-wrn-accordion
data-variant=&quot;&#123;variant&#125;&quot;
data-indicator=&quot;&#123;indicator&#125;&quot;
data-multiple=&quot;&#123;allowsMultiple() ? 'true' : 'false'&#125;&quot;
class=&quot;wire-next wire-next--color-&#123;color&#125; wire-next--size-&#123;size&#125; wire-next--accordion wire-next--accordion-&#123;variant&#125; &#123;bordered ? 'wire-next--accordion-bordered' : ''&#125; &#123;separated ? 'wire-next--accordion-separated' : ''&#125; &#123;flush ? 'wire-next--accordion-flush' : ''&#125; &#123;disabled ? 'wire-next--disabled' : ''&#125; &#123;class&#125;&quot;
&gt;
&#123;#each items as item, index&#125;
&lt;section
class=&quot;wire-next__accordion-item&quot;
data-open=&quot;&#123;isOpen(itemValue(item, index)) ? 'true' : 'false'&#125;&quot;
data-disabled=&quot;&#123;disabled || item.disabled ? 'true' : 'false'&#125;&quot;
&gt;
&lt;h3 class=&quot;wire-next__accordion-heading&quot;&gt;
&lt;button
type=&quot;button&quot;
id=&quot;&#123;id&#125;-trigger-&#123;index&#125;&quot;
aria-expanded=&quot;&#123;isOpen(itemValue(item, index)) ? 'true' : 'false'&#125;&quot;
aria-controls=&quot;&#123;id&#125;-panel-&#123;index&#125;&quot;
disabled=&quot;&#123;disabled || item.disabled&#125;&quot;
@click=&quot;toggleItem(event, itemValue(item, index), item)&quot;
&gt;
&#123;#if showIndicator &amp;&amp; indicatorPosition === &quot;start&quot;&#125;
&lt;span class=&quot;wire-next__accordion-indicator&quot; aria-hidden=&quot;true&quot;&gt;
&#123;#if indicator === &quot;chevron&quot;&#125;
&lt;span class=&quot;icon-[lucide--chevron-down]&quot;&gt;
&lt;/span&gt;
&#123;:else&#125;
&lt;span&gt;+&lt;/span&gt;
&#123;/if&#125;
&lt;/span&gt;
&#123;/if&#125;
&lt;span&gt;&#123;item.label || item.title&#125;&lt;/span&gt;
&#123;#if showIndicator &amp;&amp; indicatorPosition === &quot;end&quot;&#125;
&lt;span class=&quot;wire-next__accordion-indicator&quot; aria-hidden=&quot;true&quot;&gt;
&#123;#if indicator === &quot;chevron&quot;&#125;
&lt;span class=&quot;icon-[lucide--chevron-down]&quot;&gt;
&lt;/span&gt;
&#123;:else&#125;
&lt;span&gt;+&lt;/span&gt;
&#123;/if&#125;
&lt;/span&gt;
&#123;/if&#125;
&lt;/button&gt;
&lt;/h3&gt;
&lt;div
id=&quot;&#123;id&#125;-panel-&#123;index&#125;&quot;
class=&quot;wire-next__accordion-panel&quot;
role=&quot;region&quot;
aria-labelledby=&quot;&#123;id&#125;-trigger-&#123;index&#125;&quot;
aria-hidden=&quot;&#123;isOpen(itemValue(item, index)) ? 'false' : 'true'&#125;&quot;
&gt;
&lt;div&gt;
&lt;div class=&quot;wire-next__accordion-content &#123;contentItalic ? 'wire-next__accordion-content-italic' : ''&#125;&quot;&gt;
&#123;#if item.content&#125;&lt;p&gt;&#123;item.content&#125;&lt;/p&gt;&#123;/if&#125;
&#123;#if item.children &amp;&amp; item.children.length &gt; 0&#125;
&lt;div class=&quot;wire-next__accordion-nested&quot;&gt;
&#123;#each item.children as child, childIndex&#125;
&lt;section
class=&quot;wire-next__accordion-item&quot;
data-open=&quot;&#123;isOpen(nestedValue(item, index, child, childIndex)) ? 'true' : 'false'&#125;&quot;
&gt;
&lt;h4 class=&quot;wire-next__accordion-heading&quot;&gt;
&lt;button
type=&quot;button&quot;
id=&quot;&#123;id&#125;-trigger-&#123;index&#125;-&#123;childIndex&#125;&quot;
aria-expanded=&quot;&#123;isOpen(nestedValue(item, index, child, childIndex)) ? 'true' : 'false'&#125;&quot;
aria-controls=&quot;&#123;id&#125;-panel-&#123;index&#125;-&#123;childIndex&#125;&quot;
disabled=&quot;&#123;disabled || child.disabled&#125;&quot;
@click=&quot;toggleItem(event, nestedValue(item, index, child, childIndex), child)&quot;
&gt;
&#123;#if showIndicator&#125;
&lt;span class=&quot;wire-next__accordion-indicator&quot; aria-hidden=&quot;true&quot;&gt;
&#123;#if indicator === &quot;chevron&quot;&#125;
&lt;span class=&quot;icon-[lucide--chevron-down]&quot;&gt;
&lt;/span&gt;
&#123;:else&#125;
&lt;span&gt;+&lt;/span&gt;
&#123;/if&#125;
&lt;/span&gt;
&#123;/if&#125;
&lt;span&gt;&#123;child.label || child.title&#125;&lt;/span&gt;
&lt;/button&gt;
&lt;/h4&gt;
&lt;div
id=&quot;&#123;id&#125;-panel-&#123;index&#125;-&#123;childIndex&#125;&quot;
class=&quot;wire-next__accordion-panel&quot;
role=&quot;region&quot;
aria-labelledby=&quot;&#123;id&#125;-trigger-&#123;index&#125;-&#123;childIndex&#125;&quot;
aria-hidden=&quot;&#123;isOpen(nestedValue(item, index, child, childIndex)) ? 'false' : 'true'&#125;&quot;
&gt;
&lt;div&gt;
&lt;div class=&quot;wire-next__accordion-content &#123;contentItalic ? 'wire-next__accordion-content-italic' : ''&#125;&quot;&gt;
&lt;p&gt;&#123;child.content&#125;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&#123;/each&#125;
&lt;/div&gt;
&#123;/if&#125;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&#123;/each&#125;
&lt;/div&gt;
&#125;
&#125;
</code></pre></section></article><aside class="on-this-page"><h2>On this page</h2><nav><a href="#usage">Usage</a><a href="#props">Props and attributes</a><a href="#slots">Slots</a><a href="#events">Events</a><a href="#source">Source contract</a></nav></aside></main>
<footer><div class="footer-brand"><span class="footer-mark" aria-hidden="true">W</span><p><strong>WRNexusJS 0.5.0</strong><span>Complete API documentation generated from installed package declarations.</span></p></div><nav aria-label="Footer"><a href="/packages">All packages</a><a href="/getting-started">Get started</a><a href="/security">Security</a><a href="/support">Support</a><a href="/llms.txt">AI guide</a></nav><p class="footer-meta">Private Developer Preview · Bun-native</p></footer>
<BackToTop />
</div>
}
}