Accordion

function

Accordion(props): ReactNode

Accordion component that provides a collapsible content container.

This component uses a forward ref to expose the Accordion API to parent components. It leverages the useWidgetWithConfig hook to create the accordion widget and useImperativeHandle to bind the widget API to the ref.

Parameters

props: Partial<AccordionProps> & object & RefAttributes<AccordionApi>

The properties for the Accordion component.

Returns

ReactNode

The rendered Accordion component.


AccordionApi

interface

Interface representing the API for an accordion component.

Methods
collapse

collapse(itemId): void

Given the itemId, will collapse the corresponding accordion-item.

If the itemId is not valid, nothing will happen.

Parameters

itemId: string

Returns

void


collapseAll

collapseAll(): void

It will collapse all the accordion-items in the accordion.

Returns

void


expand

expand(itemId): void

Given the itemId, will expand the corresponding accordion-item.

If the itemId is not valid, nothing will happen.

Parameters

itemId: string

Returns

void


expandAll

expandAll(): void

It will expand all the items in the accordion.

If closeOthers is true it will expand only the last accordion-item.

Returns

void


registerItem

registerItem(itemConfig?): AccordionItemWidget

Creates a new accordionItem.

Parameters

itemConfig?: PropsConfig<AccordionItemProps>

Returns

AccordionItemWidget


toggle

toggle(itemId): void

Given the itemId, will toggle the corresponding accordion-item.

If the itemId is not valid, nothing will happen.

Parameters

itemId: string

Returns

void


AccordionDirectives

interface

Interface representing the directives used in the Accordion component.

Properties
accordionDirective

accordionDirective: Directive

Directive to put on the accordion DOM element


AccordionItem

function

AccordionItem(props): ReactNode

AccordionItem component is a part of the Accordion component suite.

Parameters

props: Partial<AccordionItemProps> & RefAttributes<AccordionItemApi>

The properties for the AccordionItem component.

Returns

ReactNode

The rendered AccordionItem component.

Remarks

This component uses several hooks:

  • useContext to get the registerItem function from AccordionDIContext.
  • useWidgetWithConfig to initialize the widget context.
  • useImperativeHandle to expose the api to the parent component.
  • useEffect to call api.initDone() after the component mounts.

The component also uses useDirectives to apply directives to the rendered div element.

See

AccordionItemApi

interface

Interface representing the API for an accordion item.

Methods
collapse

collapse(): void

It will collapse the accordion-item.

Returns

void


expand

expand(): void

It will expand the accordion-item.

Returns

void


initDone

initDone(): void

Method to be called after the initialization to allow animations.

Returns

void


toggle

toggle(): void

It will toggle the accordion-item.

Returns

void


AccordionItemContext

interface

Represents the context for an accordion item within the accordion component.

Properties
api

api: AccordionItemApi

all the api functions to interact with the widget


directives

directives: AccordionItemDirectives

directives to be used on html elements in the template of the widget or in the slots


state

state: AccordionItemState

the state of the widget


AccordionItemDefaultSlotStructure

function

AccordionItemDefaultSlotStructure(slotContext): Element

Renders the default slot structure for an accordion item.

Parameters

slotContext: AccordionItemContext

The context containing state and directives for the accordion item.

Returns

Element

The JSX element representing the accordion item's default slot structure.


AccordionItemDirectives

interface

Interface representing the directives used in an accordion item.

Properties
bodyContainerAttrsDirective

bodyContainerAttrsDirective: Directive

Directive to apply aria attributes to the expanded body panel


bodyContainerDirective

bodyContainerDirective: Directive

Directive to be put on the accordion-item body container. It will handle the animation.


bodyDirective

bodyDirective: Directive

Directive to put on the accordion-item body.


buttonDirective

buttonDirective: Directive

Directive to put on the button element that will control the collapsing of the accordion-item.


headerDirective

headerDirective: Directive

Directive to put on the accordion-item header that will contain the button element.


itemDirective

itemDirective: Directive

Directive to be put on the accordion-item. It will handle adding the accordion-item to the accordion.


toggleDirective

toggleDirective: Directive

Directive to use in special cases, if the accordion header does not use a button element to control the collapsing.


transitionDirective

transitionDirective: Directive

Directive to apply the itemTransition


AccordionItemProps

interface

Represents the properties for an Accordion item component.

Properties
animated

animated: boolean

If true, accordion-item will be animated.


bodyClassName

bodyClassName: string

CSS classes to add on the accordion-item body DOM element.


bodyContainerClassName

bodyContainerClassName: string

CSS classes to add on the accordion-item body container DOM element. The accordion-item body container is the DOM element on what the itemTransition is applied.


buttonClassName

buttonClassName: string

CSS classes to add on the accordion-item collapse DOM element.


children

children: SlotContent<AccordionItemContext>

Content present in the accordion body.

It is a prop of the accordion-item.


className

className: string

CSS classes to be applied on the widget main container

Default Value

''


destroyOnHide

destroyOnHide: boolean

If true, the accordion-item body container will be removed from the DOM when the accordion-item is collapsed. It will be just hidden otherwise.


disabled

disabled: boolean

If true, the accordion-item will be disabled. It will not react to user's clicks, but still will be possible to toggle programmatically.


header

header: SlotContent<AccordionItemContext>

Content present in the accordion button inside the accordion header.

It is a prop of the accordion-item.


headerClassName

headerClassName: string

CSS classes to add on the accordion-item header DOM element.


headingTag

headingTag: string

The html tag to use for the accordion-item-header.


id

id: string

The id of the accordion-item. It can be used for controlling the accordion-item via the accordion api.


onHidden

onHidden: () => void

An event fired when an item is hidden.

Returns

void


onShown

onShown: () => void

An event fired when an item is shown.

Returns

void


onVisibleChange

onVisibleChange: (visible) => void

An event fired when the visible value changes.

Event payload is the new value of visible.

Parameters

visible: boolean

Returns

void


structure

structure: SlotContent<AccordionItemContext>

Structure of the accordion-item. The default item structure is: accordion-item contains accordion header and accordion-item body container; the accordion header contains the accordion button (that contains header), while the accordion-item body container contains the accordion body (that contains children). The itemTransition is applied on this element.

It is a prop of the accordion-item.


transition

transition: TransitionFn

The transition to use for the accordion-item body-container when the accordion-item is toggled.


visible

visible: boolean

If true, the accordion-item will be visible (expanded). Otherwise, it will be hidden (collapsed).


AccordionItemState

interface

Represents the state of an accordion item, extending the core item state and additional properties specific to the accordion item.

Properties
bodyClassName

bodyClassName: string

CSS classes to add on the accordion-item body DOM element.


bodyContainerClassName

bodyContainerClassName: string

CSS classes to add on the accordion-item body container DOM element. The accordion-item body container is the DOM element on what the itemTransition is applied.


buttonClassName

buttonClassName: string

CSS classes to add on the accordion-item collapse DOM element.


children

children: SlotContent<AccordionItemContext>

Content present in the accordion body.

It is a prop of the accordion-item.


className

className: string

CSS classes to be applied on the widget main container

Default Value

''


disabled

disabled: boolean

If true, the accordion-item will be disabled. It will not react to user's clicks, but still will be possible to toggle programmatically.


header

header: SlotContent<AccordionItemContext>

Content present in the accordion button inside the accordion header.

It is a prop of the accordion-item.


headerClassName

headerClassName: string

CSS classes to add on the accordion-item header DOM element.


headingTag

headingTag: string

The html tag to use for the accordion-item-header.


id

id: string

The id of the accordion-item. It can be used for controlling the accordion-item via the accordion api.


shouldBeInDOM

shouldBeInDOM: boolean

If true the content of the accordion-item collapse should be in DOM. Its value depends on the value of the visible and destroyOnHide.


structure

structure: SlotContent<AccordionItemContext>

Structure of the accordion-item. The default item structure is: accordion-item contains accordion header and accordion-item body container; the accordion header contains the accordion button (that contains header), while the accordion-item body container contains the accordion body (that contains children). The itemTransition is applied on this element.

It is a prop of the accordion-item.


visible

visible: boolean

If true, the accordion-item will be visible (expanded). Otherwise, it will be hidden (collapsed).


AccordionItemWidget

type alias

AccordionItemWidget: Widget<AccordionItemProps, AccordionItemState, AccordionItemApi, AccordionItemDirectives>

Represents a widget for an accordion item.


AccordionProps

interface

Represents the state of an AccordionItem component.

Properties
className

className: string

CSS classes to be applied on the widget main container

Default Value

''


closeOthers

closeOthers: boolean

If true, only one accordion-item at the time can stay open.

Default Value

false


itemAnimated

itemAnimated: boolean

If true, accordion-item will be animated.

Default Value

true


itemBodyClassName

itemBodyClassName: string

CSS classes to add on the accordion-item body DOM element.

Default Value

''


itemBodyContainerClassName

itemBodyContainerClassName: string

CSS classes to add on the accordion-item body container DOM element. The accordion-item body container is the DOM element on what the itemTransition is applied.

Default Value

''


itemButtonClassName

itemButtonClassName: string

CSS classes to add on the accordion-item toggle button DOM element.

Default Value

''


itemClassName

itemClassName: string

CSS classes to add on the accordion-item DOM element.

Default Value

''


itemDestroyOnHide

itemDestroyOnHide: boolean

If true, the accordion-item body container will be removed from the DOM when the accordion-item is collapsed. It will be just hidden otherwise.

Default Value

true


itemHeaderClassName

itemHeaderClassName: string

CSS classes to add on the accordion-item header DOM element.

Default Value

''


itemHeadingTag

itemHeadingTag: string

The html tag to use for the accordion-item-header.

Default Value

''


itemStructure

itemStructure: SlotContent<AccordionItemContext>

Structure of the accordion-item. The default item structure is: accordion-item contains accordion header and accordion-item body container; the accordion header contains the accordion button (that contains header), while the accordion-item body container contains the accordion body (that contains children). The itemTransition is applied on this element.

It is a prop of the accordion-item.


itemTransition

itemTransition: TransitionFn

The transition to use for the accordion-item body-container when the accordion-item is toggled.

Default Value
collapseVerticalTransition

onItemHidden

onItemHidden: (itemId) => void

An event fired when an item is hidden.

Event payload is the id of the item.

Parameters

itemId: string

Returns

void

Default Value
() => {}

onItemShown

onItemShown: (itemId) => void

An event fired when an item is shown.

Event payload is the id of the item.

Parameters

itemId: string

Returns

void

Default Value
() => {}

AccordionState

interface

Represents the state of an Accordion component.

Properties
className

className: string

CSS classes to be applied on the widget main container

Default Value

''


itemStructure

itemStructure: SlotContent<AccordionItemContext>

Structure of the accordion-item. The default item structure is: accordion-item contains accordion header and accordion-item body container; the accordion header contains the accordion button (that contains header), while the accordion-item body container contains the accordion body (that contains children). The itemTransition is applied on this element.

It is a prop of the accordion-item.


itemWidgets

itemWidgets: AccordionItemWidget[]

Array containing all the accordion-items contained in the accordion.


AccordionWidget

type alias

AccordionWidget: Widget<AccordionProps, AccordionState, AccordionApi, AccordionDirectives>

Represents an Accordion widget type.


createAccordion

function

createAccordion(props?): AccordionWidget

Create an AccordionWidget with given config props

Parameters

props?: PropsConfig<AccordionProps>

Returns

AccordionWidget

an AccordionWidget


createAccordionItem

function

createAccordionItem(props?): AccordionItemWidget

Create an AccordionItemWidget with given config props

Parameters

props?: PropsConfig<AccordionItemProps>

Returns

AccordionItemWidget

an AccordionItemWidget


factoryCreateAccordion

function

factoryCreateAccordion(itemFactory?, accordionItemProps?, accordionConfig?, accordionValidator?): WidgetFactory<AccordionWidget>

Create an accordion WidgetFactory based on a item factory and the list of item props that should inherit from the parent accordion

Parameters

itemFactory?: WidgetFactory<AccordionItemWidget>

the item factory

accordionItemProps?: string[]

the list of item props

accordionConfig?: AccordionProps

the default accordion config

accordionValidator?: ConfigValidator<AccordionProps>

the validator of props

Returns

WidgetFactory<AccordionWidget>

the accordion widget factory


getAccordionDefaultConfig

function

getAccordionDefaultConfig(): AccordionProps

Retrieve a shallow copy of the default accordion config

Returns

AccordionProps

the default accordion config