Contained icon
A component for displaying icons inside a styled container with background and padding.
Component
Setup
The Icon component uses the Nuxt Icon module to render icons.
Please, make sure you have the Nuxt Icon module installed and configured in your Nuxt project.
In order to use icon collections, decide whether you want to use local setup or server-served icons.
Local setup
Install the desired icon collection:
npm install @iconify-json/collection-name
Server-served icons
Configure the server bundle to include the desired icon collections:
export default defineNuxtConfig({
icon: {
serverBundle: {
collections: ['mdi']
}
}
})
Props
| Props | Default | Type |
|---|---|---|
icon | mdi:help | string |
styleType | IconContainerStyleType.FLAT | IconContainerStyleType |
mode | IconMode.CSS | IconMode |
shape | IconContainerShape.CIRCLE | IconContainerShape |
color | ColorAccent.NEUTRAL | ColorAccent |
size | IconContainerSize.XL | IconContainerSize |
iconSize | — | IconSize |
Usage
icon
Sets the icon to be displayed.
<template>
<ContainedIcon icon="mdi:account" />
</template>
The Nuxt Icon module component is renamed to 'NuxtIcon' (original name: 'Icon') by the design system to avoid conflicts. So take this into account when reviewing the docs pages and if you are using it directly without the design system 'Icon' component.
Custom icon collections
To use custom icon collections, you need to configure them in your nuxt.config.ts file. Here's an example of how to add a custom icon collection:
export default defineNuxtConfig({
modules: [
'@nuxt/icon'
],
icon: {
customCollections: [
{
prefix: 'my-icon',
dir: './assets/my-icons',
// if you want to include all the icons in nested directories:
// recursive: true,
},
],
},
})
To ensure that the custom icons use the correct colors, make sure to set the `fill` and/or `stroke` attributes in your SVG files to `currentColor`.
For further information, please refer to the Nuxt Icon module documentation.
styleType
The styleType prop defines the contained icon appearance. It uses the IconContainerStyleType enum.
<template>
<ContainedIcon
:styleType="IconContainerStyleType.FLAT"
/>
</template>
Options
| Value | Description |
|---|---|
FLAT | Uses a borderless style with a subtle background |
FILLED | Applies a bold background |
mode
Sets the rendering mode of the icon. It uses the IconMode enum.
Only works when using IconType.COLLECTION.
<template>
<ContainedIcon
:mode="IconMode.CSS"
icon="mdi:account"
/>
</template>
Options
| Value | Description |
|---|---|
CSS | Renders the icon using CSS background-image |
SVG | Renders the icon as inline SVG |
shape
Defines the contained icon shape. It uses the IconContainerShape enum.
<template>
<ContainedIcon :shape="IconContainerShape.CIRCLE" />
</template>
Options
| Value | Description |
|---|---|
CIRCLE | Circle-shaped format |
SQUARE | Square-shaped format |
color
Defines the contained icon color. It uses the ColorAccent enum.
<template>
<ContainedIcon :color="ColorAccent.SUCCESS" />
</template>
Options
| Value | Description |
|---|---|
NEUTRAL | Neutral |
SUCCESS | Success |
WARNING | Warning |
DANGER | Danger |
INFO | Info |
PRIMARY_BRAND | Primary Brand |
SECONDARY_BRAND | Secondary Brand |
size
Defines the contained icon size. It uses the IconContainerSize enum.
<template>
<ContainedIcon :size="IconContainerSize.XL" />
</template>
Options
| Value | Description |
|---|---|
XXXL | xxxl |
XXL | XXL |
XL | XL |
LG | LG |
MD | MD |
SM | SM |
iconSize
Defines the contained icon size. It uses the IconSize enum.
<template>
<ContainedIcon :iconSize="IconSize.LG" />
</template>