Search documentation v0.8.1

Grid with Icons

Organize content into a grid layout with icons

Source ↗️ Report Issue ↗️

Use the GridWithIcons component to organize content into a grid layout, pairing each item with an icon to enhance clarity and visual appeal. They improve visual hierarchy, and can help structure information. Use them to showcase product features, services, or categories.

Preview
  • Grid with Icons
    Use the GridWithIcons block to organize your list into a grid with icons to enhance clarity and visual appeal.
  • Configurable
    You can create as many items as necessary with icons and an optional title. You can also configure the number of columns.
  • Supports formatting
    The text prop also supports formatting through HTML tags to help you customize the appearance of the element.
How to use the GridWithIcons component in Astro
---
const items = [{
icon: 'components',
title: 'Grid with Icons',
text: 'Use the <code>GridWithIcons</code> block...'
}, { ... }, { ... }]
---
<GridWithIcons items={items} />

The GridWithIcons component expects an items prop that defines the grid items as an array of objects in the following format:

Columns

By default, the GridWithIcons component will use a three column layout. This can be changed by specifying the number of columns using the columns prop:

  • Grid with Icons
    Use the GridWithIcons block to organize your list into a grid with icons to enhance clarity and visual appeal.
  • Configurable
    You can create as many items as necessary with icons and an optional title. You can also configure the number of columns.
  • Supports formatting
    The text prop also supports formatting through HTML tags to help you customize the appearance of the element.
  • Graceful degradation
    If the items prop is not defined, nothing will be rendered. Grid items can be rendered without icons or titles too.
<GridWithIcons
columns={4}
items={[ ... ]}
/>

Column can go up to a maximum of 4. If you need to have more columns, you can add the following css rules to your grid-with-icons.module.scss file:

@use 'webcoreui/config' as *;
@include media(sm) {
// For a six column layout, add the following:
.sm-6 {
grid-template-columns: repeat(6, minmax(0, 1fr));
}
}

You’ll also need to update your type definitions in gridWithIcons.ts to avoid type errors:

export type GridWithIconsProps = {
items: {
icon?: IconProps['type'] | string
title?: string
text: string
}[]
columns?: 1 | 2 | 3 | 4 | null
columns?: 1 | 2 | 3 | 4 | 6 | null
alignment?: 'center' | 'right' | null
iconWithBackground?: boolean
secondary?: boolean
className?: string
}

Alignments

The component also supports center and right alignments. To change the alignment, set the alignment prop to center or right:

Center aligned
  • Grid with Icons
    Use the GridWithIcons block to organize your list into a grid with icons to enhance clarity and visual appeal.
Right aligned
  • Grid with Icons
    Use the GridWithIcons block to organize your list into a grid with icons to enhance clarity and visual appeal.
<GridWithIcons
items={items}
alignment="center"
/>
<GridWithIcons
items={items}
alignment="right"
/>

Types

You can further customize the appearance of your GridWithIcons component using two additional props:

Icon with background
  • Grid with Icons
    Use the GridWithIcons block to organize your list into a grid with icons to enhance clarity and visual appeal.
Secondary
  • Grid with Icons
    Use the GridWithIcons block to organize your list into a grid with icons to enhance clarity and visual appeal.
<GridWithIcons
items={items}
iconWithBackground={true}
/>
<GridWithIcons
items={items}
secondary={true}
/>

API

type GridWithIconsProps = {
items: {
icon?: string
title?: string
text: string
}[]
columns?: 1 | 2 | 3 | 4
alignment?: 'center' | 'right'
iconWithBackground?: boolean
secondary?: boolean
className?: string
}
PropPurpose
items Sets the items for the grid.
items.icon Sets an optional icon for the grid item.
items.title Sets an optional title for the grid item.
items.text Sets the text for the grid item. Supports HTML tags.
columns Sets the number of columns for the grid.
alignment Sets the alignment of the grid items.
iconWithBackground Adds a solid background to the icons.
secondary Displays icons next to titles.
className Pass additional CSS classes for your component.

Request improvement for this page