Accordion

Accordion

Displays collapsible content panels.


Installation

./gradlew lumo --add Accordion

Usage

Basic Example

Accordion(
    headerContent = { Text("Header") },
    bodyContent = { Text("Body Content") }
)

Group Example

val groupState = rememberAccordionGroupState(count = 3, allowMultipleOpen = false)
 
Column {
    repeat(3) { index ->
        Accordion(
            state = groupState.getState(index),
            headerContent = { Text("Header $index") },
            bodyContent = { Text("Body Content $index") }
        )
    }
}

API Documentation

Accordion

The Accordion composable creates a collapsible section for content with a header and body that expand or collapse with user interaction.


Parameters

ParameterTypeDescription
modifierModifierStyles and layouts the root container.
headerModifierModifierStyles the header container.
stateAccordionStateControls the expanded/collapsed state of the accordion.
animateBooleanEnables or disables expand/collapse animations.
interactionSourceMutableInteractionSourceHandles user interactions such as clicks.
headerContent@Composable () -> UnitContent composable for the header section (clickable by default).
bodyContent@Composable () -> UnitContent composable for the body section (visible only when expanded).

Accordion State

Manages the state of a single accordion instance.

// Create a standalone accordion state
val state = rememberAccordionState(
    initiallyExpanded = false,
    onExpandedChange = { isExpanded ->
        // Handle state changes
    }
)

Properties

PropertyTypeDescription
expandedBooleanIndicates whether the accordion is expanded.
enabledBooleanControls whether the accordion is interactable.
clickableBooleanDetermines if the accordion header is clickable.
onExpandedChange(Boolean) -> UnitCallback triggered whenever the accordion’s expanded state changes.
animationProgressFloatCurrent progress of the expand/collapse animation.

Methods

MethodDescription
toggle()Toggles the accordion between expanded and collapsed states.
updateProgress()Updates the animation progress (internal use).
collapse()Collapses the accordion.

Accordion Group State

Coordinates multiple accordions working together.

// Create a group state
val groupState = rememberAccordionGroupState(
    count = 3,
    allowMultipleOpen = false
)
 
// Access individual accordion states
val firstAccordionState = groupState.getState(0)

Properties

PropertyTypeDefaultDescription
countInt-Number of accordions in the group.
allowMultipleOpenBooleanfalseDetermines if multiple accordions can be open at the same time.

Methods

MethodDescription
getState(index)Returns the AccordionState for a given index.
collapseAll()Collapses all accordions in the group.
expand(index)Expands the accordion at the given index.