233 lines
14 KiB
Plaintext
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><Accordion
|
|
size="default"
|
|
color="primary"
|
|
variant="default"
|
|
id="accordion"
|
|
items="[]"
|
|
/></code></pre><p>Legacy mount name: <code>data-component="Accordion"</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>"default"</code></td></tr><tr><td><code>color</code></td><td><code>string</code></td><td>Optional</td><td><code>"primary"</code></td></tr><tr><td><code>variant</code></td><td><code>string</code></td><td>Optional</td><td><code>"default"</code></td></tr><tr><td><code>class</code></td><td><code>string</code></td><td>Optional</td><td><code>""</code></td></tr><tr><td><code>id</code></td><td><code>string</code></td><td>Optional</td><td><code>"accordion"</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>"plus"</code></td></tr><tr><td><code>indicatorPosition</code></td><td><code>string</code></td><td>Optional</td><td><code>"start"</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 {
|
|
props {
|
|
size = "default"
|
|
color = "primary"
|
|
variant = "default"
|
|
class = ""
|
|
|
|
id = "accordion"
|
|
items = []
|
|
defaultOpen = []
|
|
multiple = false
|
|
alwaysOpen = false
|
|
disabled = false
|
|
|
|
indicator = "plus"
|
|
indicatorPosition = "start"
|
|
showIndicator = true
|
|
bordered = false
|
|
separated = false
|
|
flush = false
|
|
contentItalic = false
|
|
|
|
@event change = function
|
|
@event open = function
|
|
@event close = function
|
|
}
|
|
|
|
state openValues = defaultOpen
|
|
|
|
functions {
|
|
function itemValue(item, index) {
|
|
return item.value !== undefined && item.value !== ""
|
|
? String(item.value)
|
|
: String(index)
|
|
}
|
|
|
|
function nestedValue(parent, parentIndex, item, index) {
|
|
return itemValue(parent, parentIndex) + "." + itemValue(item, index)
|
|
}
|
|
|
|
function isOpen(value) {
|
|
return openValues.includes(value)
|
|
}
|
|
|
|
function allowsMultiple() {
|
|
return multiple || alwaysOpen
|
|
}
|
|
|
|
function dispatchAccordionEvent(sourceEvent, eventName, value, item, root, customEvent) {
|
|
root = sourceEvent.currentTarget.closest("[data-wrn-accordion]")
|
|
|
|
if (!root) {
|
|
return
|
|
}
|
|
|
|
customEvent = document.createEvent("CustomEvent")
|
|
customEvent.initCustomEvent(eventName, true, false, {
|
|
component: "Accordion",
|
|
value: value,
|
|
item: item,
|
|
open: isOpen(value),
|
|
openValues: openValues
|
|
})
|
|
root.dispatchEvent(customEvent)
|
|
}
|
|
|
|
function toggleItem(sourceEvent, value, item, wasOpen) {
|
|
if (disabled || item.disabled) {
|
|
return
|
|
}
|
|
|
|
wasOpen = isOpen(value)
|
|
|
|
if (wasOpen) {
|
|
openValues = openValues.filter((entry) => entry !== value)
|
|
} else if (allowsMultiple()) {
|
|
openValues = openValues.concat([value])
|
|
} else {
|
|
openValues = [value]
|
|
}
|
|
|
|
dispatchAccordionEvent(
|
|
sourceEvent,
|
|
wasOpen ? "close" : "open",
|
|
value,
|
|
item
|
|
)
|
|
dispatchAccordionEvent(sourceEvent, "change", value, item)
|
|
}
|
|
|
|
}
|
|
|
|
view {
|
|
<div
|
|
{...attrs}
|
|
id="{id}"
|
|
data-wrn-accordion
|
|
data-variant="{variant}"
|
|
data-indicator="{indicator}"
|
|
data-multiple="{allowsMultiple() ? 'true' : 'false'}"
|
|
class="wire-next wire-next--color-{color} wire-next--size-{size} wire-next--accordion wire-next--accordion-{variant} {bordered ? 'wire-next--accordion-bordered' : ''} {separated ? 'wire-next--accordion-separated' : ''} {flush ? 'wire-next--accordion-flush' : ''} {disabled ? 'wire-next--disabled' : ''} {class}"
|
|
>
|
|
{#each items as item, index}
|
|
<section
|
|
class="wire-next__accordion-item"
|
|
data-open="{isOpen(itemValue(item, index)) ? 'true' : 'false'}"
|
|
data-disabled="{disabled || item.disabled ? 'true' : 'false'}"
|
|
>
|
|
<h3 class="wire-next__accordion-heading">
|
|
<button
|
|
type="button"
|
|
id="{id}-trigger-{index}"
|
|
aria-expanded="{isOpen(itemValue(item, index)) ? 'true' : 'false'}"
|
|
aria-controls="{id}-panel-{index}"
|
|
disabled="{disabled || item.disabled}"
|
|
@click="toggleItem(event, itemValue(item, index), item)"
|
|
>
|
|
{#if showIndicator && indicatorPosition === "start"}
|
|
<span class="wire-next__accordion-indicator" aria-hidden="true">
|
|
{#if indicator === "chevron"}
|
|
<span class="icon-[lucide--chevron-down]">
|
|
</span>
|
|
{:else}
|
|
<span>+</span>
|
|
{/if}
|
|
</span>
|
|
{/if}
|
|
<span>{item.label || item.title}</span>
|
|
{#if showIndicator && indicatorPosition === "end"}
|
|
<span class="wire-next__accordion-indicator" aria-hidden="true">
|
|
{#if indicator === "chevron"}
|
|
<span class="icon-[lucide--chevron-down]">
|
|
</span>
|
|
{:else}
|
|
<span>+</span>
|
|
{/if}
|
|
</span>
|
|
{/if}
|
|
</button>
|
|
</h3>
|
|
<div
|
|
id="{id}-panel-{index}"
|
|
class="wire-next__accordion-panel"
|
|
role="region"
|
|
aria-labelledby="{id}-trigger-{index}"
|
|
aria-hidden="{isOpen(itemValue(item, index)) ? 'false' : 'true'}"
|
|
>
|
|
<div>
|
|
<div class="wire-next__accordion-content {contentItalic ? 'wire-next__accordion-content-italic' : ''}">
|
|
{#if item.content}<p>{item.content}</p>{/if}
|
|
|
|
{#if item.children && item.children.length > 0}
|
|
<div class="wire-next__accordion-nested">
|
|
{#each item.children as child, childIndex}
|
|
<section
|
|
class="wire-next__accordion-item"
|
|
data-open="{isOpen(nestedValue(item, index, child, childIndex)) ? 'true' : 'false'}"
|
|
>
|
|
<h4 class="wire-next__accordion-heading">
|
|
<button
|
|
type="button"
|
|
id="{id}-trigger-{index}-{childIndex}"
|
|
aria-expanded="{isOpen(nestedValue(item, index, child, childIndex)) ? 'true' : 'false'}"
|
|
aria-controls="{id}-panel-{index}-{childIndex}"
|
|
disabled="{disabled || child.disabled}"
|
|
@click="toggleItem(event, nestedValue(item, index, child, childIndex), child)"
|
|
>
|
|
{#if showIndicator}
|
|
<span class="wire-next__accordion-indicator" aria-hidden="true">
|
|
{#if indicator === "chevron"}
|
|
<span class="icon-[lucide--chevron-down]">
|
|
</span>
|
|
{:else}
|
|
<span>+</span>
|
|
{/if}
|
|
</span>
|
|
{/if}
|
|
<span>{child.label || child.title}</span>
|
|
</button>
|
|
</h4>
|
|
<div
|
|
id="{id}-panel-{index}-{childIndex}"
|
|
class="wire-next__accordion-panel"
|
|
role="region"
|
|
aria-labelledby="{id}-trigger-{index}-{childIndex}"
|
|
aria-hidden="{isOpen(nestedValue(item, index, child, childIndex)) ? 'false' : 'true'}"
|
|
>
|
|
<div>
|
|
<div class="wire-next__accordion-content {contentItalic ? 'wire-next__accordion-content-italic' : ''}">
|
|
<p>{child.content}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
{/each}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
{/each}
|
|
</div>
|
|
}
|
|
}
|
|
</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>
|
|
}
|
|
}
|