Skip to content

Accordion

The EAccordion component is a useful tool for managing and displaying large amounts of data on a webpage. Demo Here

It enables users to hide and display sections of content at a time. Nevertheless, when a multiple prop is used, multiple items can expand until explicitly closed.

Import

jsx
import EAccordion from "@components/Elements/EAccordion";
import EAccordionGroup from "@components/Elements/EAccordion/EAccordionGroup";

Usage

The EAccordion and EAccordionGroup components are used together as below:

jsx
const AccordionExample = () => {
    return (
        <EAccordionGroup>
            <EAccordion title="Title 1">Accordion 1</EAccordion>
            <EAccordion title="Title 2">Accordion 2</EAccordion>
        </EAccordionGroup>
    );
};

export default AccordionExample;
controlled EAccordion

You can control accordion active state by using value and onChange props.

The type of value is Array. Here's an example:

jsx
const AccordionExample = () => {
    const [value, setValue] = useState(0); // Zero based - first accordion is open

    const onClickHandler = (event, value) => {
        setValue(value);
    };

    return (
        <EAccordionGroup value={value} onChange={onClickHandler}>
            <EAccordion title="Title">content 1</EAccordion>
            <EAccordion title="Title">content 2</EAccordion>
        </EAccordionGroup>
    );
};

export default AccordionExample;

Props

For AccordionGroup component, the following props are available:

PropTypeDefaultNote
value[Number, Array]falseAccordion's active prop
multipleBooleanfalseThe multiple property allows more than one item to expand at the same time.
disabledBooleanfalseDisables the the accordion elements.
classNameString-Overrides or extends the component's styles.
variantString"fill"The EAccordion elements can be represented in two ways: fill and outline.
colorString"dark_theme-100"The given color is applied to the element - utility colors are supported (e.g primary or danger). you'll find a list of built-in classes on the src/styles/_vars.scsspage.
squareBooleanfalseRemoves rounded corners of the element.

For EAccordion component, the following props are available:

PropTypeDefaultNote
variantString"fill"The EAccordion elements can be represented in two ways: fill and outline.
prependIconObject-Inserts a custom EIcon element to the accordion item(s) that is located before the title. More Info here
appendIconObject-Inserts a custom EIcon element to the accordion item(s) that is located after the title. More Info here
disabledBooleanfalseDisables the EAccordion element.
colorString"dark_theme-100"The given color is applied to the element - utility colors are supported (e.g primary or danger). you'll find a list of built-in classes on the src/styles/_vars scsspage.
squareBooleanfalseRemoves rounded corners of the element.
title[String, node]-Adds a title to the EAccordion element.
classNameString-Overrides or extends the component's styles.

Note

As you can see, the AccordionGroup and EAccordion components share a few properties (disabled, color, outline) which can be used in two ways:

jsx
<EAccordionGroup color="danger">
    <EAccordion title="Title">
        {/* color:danger */}
        content 1
    </EAccordion>
    <EAccordion title="Title">
        {/* color:danger */}
        content 2
    </EAccordion>
</EAccordionGroup>
jsx
<EAccordionGroup color="danger">
    <EAccordion title="Title" color="success">
        {/* color:success */}
        content 1
    </EAccordion>
    <EAccordion title="Title">
        {/* color:danger */}
        content 2
    </EAccordion>
</EAccordionGroup>

Callback Functions

The AccordionGroup component contains following callback functions.

FunctionDescription
onChangeCallback fired when the expand/collapse state is changed. function(event: React.SyntheticEvent, activeItem: [Number,Array]) => void 👇

event: The event source of the callback.
activeItem: active accordion(s) value.

Children

The EAccordion component provides a children props that enable you to customize the content.

ChildrenDescription
✔️Component’s content.

COPYRIGHT