MazSvg
MazSvg renders an SVG (illustration, logo, flag) at its own size and with its own colors, from a name, a Vue component, a URL or a raw SVG string.
Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started
MazSvg or MazIcon
Both accept the same formats: a name, a Vue component, a URL, a data: URI or a raw SVG string.
| MazIcon | MazSvg | |
|---|---|---|
| Size | 1em (the size of the text), or size | The size of the SVG, or width / height |
| Use it for | Interface icons | Illustrations, logos, flags |
Usage
<template>
<MazSvg icon="flag-fr" width="64" />
<MazSvg icon="logo-vue" height="48" />
</template>Names need MazUi() of @maz-ui/vite-plugin (included in @maz-ui/nuxt), like MazIcon. The SVG files of your project are available by name too: src/icons/hero.svg is <MazSvg icon="hero" />.
Size
- Without
widthnorheight: the size of the SVG, never wider than its container. - With
widthonly: the height follows the ratio of the SVG. - With
height, or both: the given size.
width and height take a number of pixels (64) or a CSS length ('12rem').
Other formats
<script setup lang="ts">
import Hero from './hero.svg?component'
</script>
<template>
<MazSvg :icon="Hero" />
<MazSvg icon="/illustrations/empty.svg" width="200" />
</template>?component imports an SVG file as a Vue component, with @maz-ui/vite-svg-loader. A URL is fetched and cached, like in MazIcon.
Fallback
When icon is an unknown name or a URL that fails, an error event is emitted and fallback (same formats as icon) is rendered.
<MazSvg :icon="user.avatarUrl" fallback="no-image" @error="onError" />Accessibility
MazSvg is decorative by default (aria-hidden="true"). Set a title (or an aria-label) to describe it: role="img" is set and aria-hidden is dropped.
<MazSvg icon="app:hero" title="A team working together" />Props
| Name | Description | Type | Required | Default | Possible values |
|---|---|---|---|---|---|
| icon | The SVG to render, in the formats of MazIcon: - A name ('flag-fr', 'logo-vue', 'app:hero'), registered by MazUi() of @maz-ui/vite-plugin or @maz-ui/nuxt - A Vue component, a URL, a data: URI or a raw SVG string Unlike MazIcon, it keeps the size and the colors of the SVG. | MazIconValue | No | - | - |
| fallback | Rendered when icon is not provided or fails to load, same formats as icon | MazIconValue | No | - | - |
| width | Width of the SVG (200, '12rem'). By default, the width of the SVG | string | number | No | - | - |
| height | Height of the SVG. By default, computed from the width and the ratio of the SVG | string | number | No | - | - |
| title | Sets a <title> element inside the SVG for screen-reader accessibility. | string | No | - | - |
| svg-attributes | Extra attributes to merge onto the rendered <svg> root. | Record<string, string | number> | No | - | - |
Events
| Event name | Payload | Description |
|---|---|---|
| error | Error | Emitted when the SVG fails to load: an unknown name, or a URL that fails or returns invalid SVG |