Aller au contenu principal

List Component

Description

The List component provides a structured way to display lists of items, supporting:

  • Customizable list density and padding
  • Selectable, disabled, and clickable items
  • Icons and text combinations
  • Collapsible sub-menus for hierarchical navigation

Props

List

PropTypeDefaultDescription
densebooleanfalseReduces padding between items.
paddingbooleantrueEnables padding inside the list.

ListItem

PropTypeDefaultDescription
selectedbooleanfalseHighlights the selected item.
disabledbooleanfalseDisables interaction with the item.
onClick() => void-Callback for when item is clicked.

ListItemButton

PropTypeDefaultDescription
variant"contained" , "outlined" , "text""text"Defines the button style.
fullWidthbooleanfalseExpands button to full width.
disabledbooleanfalseDisables button interaction.
selectedbooleanfalseHighlights the selected button.
startIconReactNode-Icon before the text.
endIconReactNode-Icon after the text.

Collapse

PropTypeDefaultDescription
inbooleanfalseControls visibility of child components.

Example Usage

import {
List,
ListItem,
ListItemButton,
ListItemIcon,
ListItemText,
Collapse
} from "@nomana-it/liberty-core"
import { LYReactIcon } from "@ly_styles/icons";
import { LYHomeIcon, LYSettingsIcon, LYMenusExpandMoreIcon, LYMenusExpandLessIcon } from "@ly_styles/icons";
import { useState, Fragment } from "react";

export const ListExample = () => {
const [open, setOpen] = useState(false);

return (
<List>
<Fragment>
<ListItem>
<ListItemButton
variant="text"
fullWidth
onClick={() => setOpen(!open)}
startIcon={LYHomeIcon}
endIcon={open ? LYMenusExpandLessIcon : LYMenusExpandMoreIcon}
>
<ListItemText primary="Home" />
</ListItemButton>
</ListItem>

<Collapse in={open}>
<List padding={false}>
<ListItem>
<ListItemButton variant="text" fullWidth startIcon={LYSettingsIcon}>
<ListItemText primary="Settings" />
</ListItemButton>
</ListItem>
</List>
</Collapse>
</Fragment>
</List>
);
};

🔗 GitHub Repository (Core): Liberty Core
🔗 GitHub Repository (Test Project): Liberty Test
📖 Live Documentation: Liberty Core Docs
💖 Sponsor & Support: Sponsor Liberty Core