component Accordion { outputs { change(payload: { value?: string | number | boolean | null; values?: Array; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null) open(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object }) close(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object }) } props { size: string = "default" color: string = "primary" variant: string = "default" class: string = "" id: string = "accordion" items: unknown[] = [] defaultOpen: unknown[] = [] multiple: boolean = false alwaysOpen: boolean = false disabled: boolean = false indicator: string = "plus" indicatorPosition: string = "start" showIndicator: boolean = true bordered: boolean = false separated: boolean = false flush: boolean = false contentItalic: boolean = false } state openValues = defaultOpen functions { shared function itemValue(item, index) { return item.value !== undefined && item.value !== "" ? String(item.value) : String(index) } shared function nestedValue(parent, parentIndex, item, index) { return itemValue(parent, parentIndex) + "." + itemValue(item, index) } shared function isOpen(value) { return openValues.includes(value) } shared function allowsMultiple() { return multiple || alwaysOpen } client 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) } client 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 {
{#each items as item, index}

{#if item.content}

{item.content}

{/if} {#if item.children && item.children.length > 0}
{#each item.children as child, childIndex}

{child.content}

{/each}
{/if}
{/each}
} }