Search documentation v0.8.1

List with Icons

Improve list readability with icons

Source ↗️ Report Issue ↗️

Use the IconList component to combine text with icons, improving readability and making informational content visually more engaging. You can use them to highlight features or benefits of a product, create pros and cons list, or organize information like contact details or services.

Preview
  • Advantages: ...
  • Disadvantages: ...
How to use list with icons in Astro
<IconList items={[
{ icon: 'circle-check', text: 'Advantages: ...', color: 'var(--w-color-success)' },
{ icon: 'circle-close', text: 'Disadvantages: ...', color: 'var(--w-color-alert)' }
]} />

The IconList component expects an array of items in the form of:

Columns

By default, the IconList component will create a simple ul with icons using a single column. This can be modified by setting the columns prop:

Two-column layout
  • Highlight 1
  • Highlight 2
  • Highlight 3
  • Downside 1
  • Downside 2
  • Downside 3
<IconList
columns={2}
items={[
{ icon: 'circle-check', text: 'Highlight 1', color: 'var(--w-color-success)' },
{ icon: 'circle-check', text: 'Highlight 2', color: 'var(--w-color-success)' },
{ icon: 'circle-check', text: 'Highlight 3', color: 'var(--w-color-success)' },
{ icon: 'circle-close', text: 'Downside 1', color: 'var(--w-color-alert)' },
{ icon: 'circle-close', text: 'Downside 2', color: 'var(--w-color-alert)' },
{ icon: 'circle-close', text: 'Downside 3', color: 'var(--w-color-alert)' }
]}
/>

The column prop will not take effect for small screen devices, instead, the element will be displayed using a single column. If you don’t want this behavior, you can remove the media query from your icon-list.module.scss file:

Remove the media rule inside your icon-list.module.scss
@include media(xs) {
.list {
columns: var(--w-icon-list-columns);
}
}

If you want to use X amount of columns by default, you can override the following CSS property, and omit the columns prop from the component:

Setting two-column layouts by default
body {
--w-icon-list-columns: 2;
}

Icon Colors

In the above examples, icons colors were specified on an individual basis. However, you can set a single color for every list item by defining the color prop on the component:

<IconList
color="var(--w-color-success)"
items={[
{ icon: 'circle-check', text: 'Highlight 1' },
{ icon: 'circle-check', text: 'Highlight 2' },
{ icon: 'circle-check', text: 'Highlight 3' }
]}
/>

Similar to the column count, you can set this color globally if you only need to use a single color for all components. Simply override the following CSS variable:

body {
--w-icon-list-color: var(--w-color-success);
}

API

type IconListProps = {
columns?: number
color?: string
items: {
icon: string
text: string
color?: string
}[]
className?: string
}
PropPurpose
columns Sets the number of columns for the list.
color Sets the color of the icons.
items.icon Sets an icon for the list item.
items.text Sets the text for the list item. Supports HTML content.
items.color Sets the color of the icon for the list item. Overwrites the color prop.
className Pass additional CSS classes for your element.

Request improvement for this page