ListGroup

The list group component can be used to show a list of items inside of an unordered list. It can be used for navigation, to show a simple aside, to display a list of items in a menu...

Start using the list group component by first importing it from Pol-ui:

import { ListGroup } from "pol-ui";

Default list group

Use the default example to create a simple list of items inside of a menu by using the ListGroup component with ListGroupItem child components inside of it.

Default ListGroup

import { ListGroup } from "pol-ui";
const ListGroupComponent = () => {
  return (
    <ListGroup>
      <ListItem>Profile</ListItem>
      <ListItem>Settings</ListItem>
      <ListItem>Messages</ListItem>
      <ListItem>Download</ListItem>
    </ListGroup>
  );
};
export default ListGroupComponent;

Props

ListGroup

The ListGroup component has the following props:

Prop nameTypeDefaultDescription
themeListGroupThemeThe theme to be applied to the component.
💡

You can also provide any prop comming from the HTML ul tag.

ListItem

Prop nameTypeDefaultDescription
activebooleanfalseWhether the item is active or not.
disabledbooleanfalseWhether the item is disabled or not.
hrefstringThe URL to link to.
iconFC<ComponentProps<'svg'>>The icon to display next to the item.
onClick(event) => voidThe function to call when the item is clicked.
themeListGroupThemeThe theme to be applied to the component.
colorColorsThe color to apply to the item.
💡

You can also provide any prop comming from the HTML a tag as well as the HTML button tag.

Examples

With icons

To display icons next to the items, you can use the ListGroupItem component with the icon prop.

With icons

import { ListGroup } from "pol-ui";
const ListGroupComponent = () => {
  return (
    <ListGroup>
      <ListItem active icon={TbUser}>
        Profile
      </ListItem>
      <ListItem icon={TbSettings}>Settings</ListItem>
      <ListItem icon={TbAt}>Messages</ListItem>
      <ListItem icon={TbDownload}>Download</ListItem>
    </ListGroup>
  );
};
export default ListGroupComponent;

With the use of the href prop, you can render the children as links.

With links

import { ListGroup } from "pol-ui";
const ListGroupComponent = () => {
  return (
    <ListGroup>
      <ListItem active href="#">
        Profile
      </ListItem>
      <ListItem href="#">Settings</ListItem>
      <ListItem href="#">Messages</ListItem>
      <ListItem href="#">Download</ListItem>
    </ListGroup>
  );
};
export default ListGroupComponent;

Attach actions to items

You can attach actions to the items by using the onClick prop.

With buttons

import { ListGroup } from "pol-ui";
const ListGroupComponent = () => {
  return (
    <ListGroup>
      <ListItem active onClick={() => alert("Profile clicked!")}>
        Profile
      </ListItem>
      <ListItem onClick={() => alert("Settings clicked!")}>Settings</ListItem>
      <ListItem onClick={() => alert("Messages clicked!")}>Messages</ListItem>
      <ListItem onClick={() => alert("Download clicked!")}>Download</ListItem>
    </ListGroup>
  );
};
export default ListGroupComponent;

Theme

To learn more about how to customize the appearance of components, please see the Theme docs.

interface ListGroupTheme {
  root: {
    base: string;
  };
  item: {
    base: string;
    link: {
      base: string;
      active: IBoolean;
      disabled: IBoolean;
      href: IBoolean;
      icon: string;
    };
  };
}

Since February 21, 2024

Proudly Open Source
  • Npm

  • Github

  • Creator

  • Made with love and Pol-ui by Pol Gubau Amores