⚠️ After March 18, 2024, the FastStore documentation will be migrated to the Developer Portal. For more information, access the official release note.

Accordion

Accordions display an expandable/collapsible list of items. The final Accordion component is a compound of the following:

  • Accordion: wraps a series of AccordionItems in a single component.
  • AccordionItem: wraps an AccordionButton and an AccordionPanel.
  • AccordionButton: contains the top-level items of the Accordion list. It is a clickable button that shows or hides the child items of a given AccordionItem.
  • AccordionPanel: contains the child items of a given AccordionItem.

Import

Import the component from @faststore/ui

import {
  Accordion,
  AccordionItem,
  AccordionButton,
  AccordionPanel,
} from '@faststore/ui'

Import Styles into your FastStore project

To apply the styles of this component in your FastStore project, import the following into your stylesheet:

@import '@faststore/ui/src/components/atoms/Button/styles.scss';
@import '@faststore/ui/src/components/molecules/Accordion/styles.scss';

Follow the instructions in the Importing FastStore UI component styles tutorial.


Usage


Props

All accordion-related components support all attributes also supported by the <div> tag, except for the AccordionButton, which renders the <button> tag and inherits Button props.

Besides those attributes, the following props are also supported:

Accordion

NameTypeDescriptionDefault
testIdstringID to find this component in testing tools (e.g.: cypress, testing-library, and jest).fs-accordion
indices*Iterable<number>Indices that indicate which accordion items are opened.
onChange*(index: number) => voidFunction that is triggered when an accordion item is opened/closed.

Accordion Item

NameTypeDescriptionDefault
testIdstringID to find this component in testing tools (e.g.: cypress, testing library, and jest).fs-accordion-item
indexnumberIndex of the current accordion item within the accordion.
prefixIdstringNamespace ID prefix for the current Accordion item's panel and button to avoid ID duplication when multiple instances are on the same page.

Accordion Button

NameTypeDescriptionDefault
testIdstringID to find this component in testing tools (e.g.: cypress, testing library, and jest).fs-accordion-button
expandedIconstring | number | false | true | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortalA React component is rendered as an icon when the accordion is expanded.<Icon name="MinusCircle" data-icon="expanded" />
collapsedIconstring | number | false | true | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortalA React component is rendered as an icon when the accordion is collapsed.<Icon name="PlusCircle" data-icon="collapsed" />
variant"primary" | "secondary" | "tertiary"Specifies the component color variant.
size"small" | "regular"Specifies the size variant.
inversefalse | trueDefines the use of inverted colors.
disabledfalse | trueSpecifies that this button should be disabled.
iconstring | number | false | true | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortalA React component that will be rendered as an icon.
loadingfalse | trueBoolean that represents a loading state.
loadingLabelstringSpecifies a label for loading state.
iconPosition"left" | "right"Specifies where the icon should be positioned

Accordion Panel

NameTypeDescriptionDefault
testIdstringID to find this component in testing tools (e.g.: cypress, testing library, and jest).fs-accordion-panel

Design Tokens

Nested Elements

Item

Local tokenDefault value/Global token linked
--fs-accordion-item-border-bottom-widthvar(--fs-border-width)
--fs-accordion-item-border-bottom-color
var(--fs-border-color-light)

Button

Local tokenDefault value/Global token linked
--fs-accordion-button-paddingvar(--fs-spacing-3) 0
--fs-accordion-button-font-sizevar(--fs-text-size-3)
--fs-accordion-button-font-weightvar(--fs-text-weight-bold)
--fs-accordion-button-line-height1.2
--fs-accordion-button-color
var(--fs-color-text)
--fs-accordion-button-bkg-color
transparent

Panel

Local tokenDefault value/Global token linked
--fs-accordion-panel-padding-bottomvar(--fs-spacing-4)

Customization

data-fs-accordion

data-fs-accordion-item

data-fs-accordion-button

data-fs-accordion-panel

The AccordionButton component inherits Button CSS selectors.


Examples

Multiple and Collapsible

One Collapsible at a Time