Skip to content

List

You can use the list component to show multiple types of list items. Each Elistitem can contain an image, text, symbol, or HTML content. List items can also be grouped by EListGroup or EListRecursive in a more advanced way. Demo Here

Import

jsx
import EListItem from "@components/Elements/EList/EListItem";
import EListGroup from "@components/Elements/EList/EListGroup";
import EListRecursive from "@components/Elements/EList/EListRecursive";

Usage

EListItem

This element typically used to represent a single item within a list.

jsx
<EListItem> Lorem ipsum dolor sit amet. </EListItem>

EListGroup

This is a collection of multiple EListItem components grouped together.

jsx
<EListGroup>
    <EListItem> 1 </EListItem>
    <EListItem> 2 </EListItem>
    <EListGroup title="3" expandable>
        <EListItem> 3.1 </EListItem>
        <EListItem> 3.2 </EListItem>
        <EListGroup title="3.3" expandable>
            <EListItem> 3.3.1 </EListItem>
            <EListItem> 3.3.2 </EListItem>
            <EListItem> 3.3.3 </EListItem>
        </EListGroup>
    </EListGroup>
</EListGroup>

EListRecursive

EListRecursive allows you to create expandable and collapsible lists that adapt to any level of nesting.

It iterates through your list data, recursively rendering each EListItem or EListGroup while preserving the hierarchical structure. This feature is especially useful for menus, category trees, or any scenario involving items with sub-items.

jsx
const ListRecursiveExample = () => {
   const listItems = [
       {title: "1"},
       {
           title: "2",
           children: [
               {title: "2.1"},
               {title: "2.2"},
               {
                   title: "2.3",
                   children: [
                       {title: "2.3.1"},
                       {title: "2.3.2"},
                       {
                           title: "2.3.3",
                           to: '/user',
                           icon: {
                               name: 'User',
                               iconPack: 'iconsax'
                           }
                       }
                   ]
               }
           ]
       }
   ]

   return listItems.map((item, index) => (
       <EListRecursive key={index}>{item}</EListRecursive>
   ));
};

export default ListRecursiveExample;

Each object in the array of list items can have the following properties:

  • title:String
  • icon:String
  • to:String
  • href:String
  • target:String
  • variant:String
  • children:Array

Note

To display an icon, add your desired icon name from iconsax or tabler icons. More info about icons here

Props

  • For EListGroup component, the following props are available:
PropTypeDefaultNote
activeState[String, Number]-List's active prop.
width[String, Number]-Sets the list's width. Default unit is px.
height[String, Number]-Sets the list's height. Default unit is px.
wrapperTagString"li"Define list group wrapper tag
focusableBooleanfalseMake list items focusable.
borderBooleanfalseCreates list items with borders.
roundedBooleanfalseIt creates a circular list items.
squareBooleanfalseSquares the corners of the list item.
compactBooleanfalseSpecifies that the list items should render in smaller size than normal. It moves the list content as it expands and collapses controlled by mouse hover. Typically used for creating a sidebar.
compactHoverBooleanfalseOpen compact list on hover, only works with compact prop Typically used for creating a sidebar.
titleString-Adds a title to the EListGroup element.
classNameString-Overrides or extends the component's styles.
clearableActiveBooleantrueToggles the active state of item on another click on the same item.
sizeString"md"The list element has three predefined sizes: sm, md, lg.
expandableBooleanfalseIt shows items in a vertically scrolling multi-level list.
translateBooleanfalseEnables list item's Translation. (see more info about translation on the localization page)
colorString"primary"The given color is applied to the list - utility colors are supported (e.g primary or danger). you'll find a list of built-in classes on the src/styles/_vars.scsspage.
variantString"fill"The list element can be represented in two ways: fill and line. When a list item is active or hovered over, fill displays a background and line displays an underlining.
iconObject-By using icon prop the EListGroup element will be visualized with an Icon. More Info about icons here.
  • For EListItem component, the following props are available:
PropTypeDefaultNote
valueString-Each list item can have a unique value that identifies the active item within the group. (if not defined the EListGroup uses the index of each EListItem to specify the selected item)
roundedBooleanfalseIt creates a circular list items.
squareBooleanfalseSquares the corners of the list item.
buttonClassNameString-Overrides or extends the btn styles.
toString-This attribute creates a linked list item.
hrefString-This attribute creates a linked list item.
targetString"_self"It specifies where to open the linked document. _self opens the linked document in the same frame as it was clicked.
classNameString-Overrides or extends the component's styles.(wrapper)
sizeString"md"The list element has three predefined sizes: sm, md, lg.
translateBooleanfalseEnables list item's Translation. (see more info about translation on the localization page)
colorString"primary"The given color is applied to the list - utility colors are supported (e.g primary or danger). you'll find a list of built-in classes on the src/styles/_vars.scsspage.
iconObject-By using icon prop the EListItem element will be visualized with an Icon. More Info about icons here.
variantString"fill"The list element can be represented in two ways: fill and line. When a list item is active or hovered over, fill displays a background and line displays an underlining.
  • For EListRecursive component, the following props are available:
PropTypeDefaultNote
compactBooleanfalseSpecifies that the list items should render in smaller size than normal. It moves the list content as it expands and collapses controlled by mouse hover. Typically used for creating a sidebar.
compactHoverBooleanfalseOpen compact list on hover, only works with compact prop Typically used for creating a sidebar.
translateBooleanfalseEnables list item's Translation. (see more info about translation on the localization page)
roundedBooleanfalseIt creates a circular list items.
squareBooleanfalseSquares the corners of the list item.
classNameString-Overrides or extends the component's styles.
sizeString"md"The list element has three predefined sizes: sm, md, lg.
colorString"primary"The given color is applied to the list - utility colors are supported (e.g primary or danger). you'll find a list of built-in classes on the src/styles/_vars.scsspage.
variantString"fill"The list element can be represented in two ways: fill and line. When a list item is active or hovered over, fill displays a background and line displays an underlining.

Note

  • In EListRecursive, the variant prop can be used in two ways. You can either set the variant property individually on each object within the listItems array to give each item a unique variant, or you can set the variant prop on the EListRecursive component itself, which will apply that variant to all list items by default.

  • As you can see, the EListGroup and EListItem components share a few properties (variant, rounded, square, color) which can be used in two ways:

jsx
<EListGroup title="Group" color="danger" expandable>
    {/* color:danger */}
    <EListItem> Item 1 </EListItem> {/* color:danger */}
    <EListItem> Item 2 </EListItem> {/* color:danger */}
</EListGroup>
jsx
<EListGroup title="Group" color="danger" expandable>
    {/* color:danger */}
    <EListItem color="warning"> Item 1 </EListItem> {/* color:warning */}
    <EListItem> Item 2 </EListItem> {/* color:danger */}
</EListGroup>
Styling Active Router Link

It is critical to visually indicate the current active page when showing list items in the navigation bar. to achieve this you can add href or to prop to each EListItem and when the current route matched the prop value, the list item will be activated.

WARNING

if you want to show the active list with EListRecursive, make sure to add href or to properties to the listItems object

Active List Items
  • Use the focusable prop to apply an active style to list items when they are clicked. In this approach, you won’t have control over the active list item, as the functionality is built-in.
  • Use the onChange and activeState props if you wish to maintain control over the active list item.
  • You can assign each EListItem a unique value , or the EListGroup will use the index of each item to identify the active list item.
jsx
export const FocusableList = () => {
    const [value, setValue] = useState(0); // Zero-based, The first list item is focused.
    // you can also add a unique value to each list item to be used instead of the index.

    return (
        <EListGroup
            focusable
            // or
            onChange={(event, value) => setValue(value)}
            activeState={value}
        >
            <EListItem>
                List Item 1
            </EListItem>
            <EListItem>
                List Item 2
            </EListItem>
        </EListGroup>
    );
};

Callback Functions

The EListGroup component contains following callback functions.

FunctionDescription
onChangeComponent's onChange event fired when active value state is changed. function(event: React.SyntheticEvent, activeItem: [String, Number]) => void 👇

event: The event source of the callback.
activeItem: Active item value

Children

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

ChildrenDescription
EListItemComponent’s items.

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

ChildrenDescription
✔️Item's content.

COPYRIGHT