@molecule/app-collapsible-section-svelte
Feature · collapsible-section · App (browser) · v2.0.3 · Apache-2.0
Expandable section with optional "show more / show less" and count
npm install @molecule/app-collapsible-section-svelteHow it works
@molecule/app-collapsible-section-svelte is a ready-made collapsible-section feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { CollapsibleSection, ShowMore } from '@molecule/app-collapsible-section-svelte'
</script>
<CollapsibleSection title="Key concepts" defaultExpanded={true}>
<p>Content revealed when expanded.</p>
</CollapsibleSection>
<ShowMore {items} initialCount={3}>
{#snippet children(item)}<div>{item.label}</div>{/snippet}
</ShowMore>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte collapsible-section and show-more.
Exports:
<CollapsibleSection>— expandable section with a clickable heading.<ShowMore>— "Show N more" / "Show less" toggle for long lists.
It is the Svelte counterpart of @molecule/app-collapsible-section-react:
the same props (React names), the same ClassMap tokens, the same i18n keys,
and the same DOM for the same input. Node props are snippets (or plain
strings).
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { CollapsibleSection, ShowMore } from '@molecule/app-collapsible-section-svelte'
</script>
<CollapsibleSection title="Key concepts" defaultExpanded={true}>
<p>Content revealed when expanded.</p>
</CollapsibleSection>
<ShowMore {items} initialCount={3}>
{#snippet children(item)}<div>{item.label}</div>{/snippet}
</ShowMore>
Type
feature
Installation
npm install @molecule/app-collapsible-section-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
CollapsibleSectionProps
Props accepted by the CollapsibleSection component.
interface CollapsibleSectionProps {
/** Section heading — a snippet, or a plain string. */
title?: Snippet | string
/** Body to show when expanded — the `children` snippet. */
children?: Snippet
/** Controlled expansion — if omitted, the component owns state. */
expanded?: boolean
/** Initial expanded state when uncontrolled. Defaults to false. */
defaultExpanded?: boolean
/** Called when expansion state changes. */
onExpandedChange?: (expanded: boolean) => void
/** Optional badge / count shown in the header — a snippet, or a plain string. */
badge?: Snippet | string
/** Optional right-side actions — a snippet, or a plain string. */
actions?: Snippet | string
/** Heading level — affects rendered tag, defaults to 3. */
level?: 2 | 3 | 4 | 5 | 6
/** Extra classes. */
className?: string
}
ShowMoreProps
Props accepted by the ShowMore component.
interface ShowMoreProps<T = unknown> {
/** The items before truncation, one entry each (React's `children` array). */
items?: T[]
/** Renders one entry of `items`. */
children?: Snippet<[item: T, index: number]>
/** Number to show initially. Defaults to 3. */
initialCount?: number
/** i18n key for the "Show more" label — receives `{ remaining }`. */
moreKey?: string
/** i18n key for the "Show less" label. */
lessKey?: string
/** Extra classes. */
className?: string
}
Constants
CollapsibleSection
const CollapsibleSection: LegacyComponentType
ShowMore
const ShowMore: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.13.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
<CollapsibleSection> is uncontrolled by default (defaultExpanded);
passing expanded makes it fully controlled — then you must update it from
onExpandedChange. The header renders as a single <button>, so anything
passed to actions must NOT contain buttons/links (nested interactive
elements are invalid HTML) — put row actions outside the section instead.
<ShowMore>'s labels use the i18n keys showMore.more / showMore.less
with English defaultValues; no companion locale bond ships these keys —
add them to your app's locale resources (or pass custom moreKey/lessKey).
A snippet has no length, so <ShowMore> takes the list as data (items)
and renders each entry through its children snippet; the initial slice is
items.slice(0, initialCount).