Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@iconify/vue
Advanced tools
@iconify/vue is a Vue component for Iconify, which provides a unified framework for using a wide range of icon sets. It allows you to easily integrate icons from various icon libraries into your Vue.js applications.
Basic Icon Usage
This feature allows you to use icons from different icon sets by specifying the icon name. In this example, the 'mdi:home' icon from the Material Design Icons set is used.
<template>
<Icon icon="mdi:home" />
</template>
<script>
import { Icon } from '@iconify/vue';
export default {
components: {
Icon
}
};
</script>
Customizing Icon Size
You can customize the size of the icons by setting the width and height properties. This example sets the icon size to 48x48 pixels.
<template>
<Icon icon="mdi:home" width="48" height="48" />
</template>
<script>
import { Icon } from '@iconify/vue';
export default {
components: {
Icon
}
};
</script>
Inline Icon
The inline property allows the icon to be aligned with the text, making it useful for inline text elements.
<template>
<Icon icon="mdi:home" inline />
</template>
<script>
import { Icon } from '@iconify/vue';
export default {
components: {
Icon
}
};
</script>
Customizing Icon Color
You can change the color of the icon by setting the color property. This example sets the icon color to red.
<template>
<Icon icon="mdi:home" color="red" />
</template>
<script>
import { Icon } from '@iconify/vue';
export default {
components: {
Icon
}
};
</script>
vue-awesome is a Vue component for Font Awesome icons. It provides a simple way to use Font Awesome icons in your Vue.js applications. Unlike @iconify/vue, which supports multiple icon sets, vue-awesome is limited to Font Awesome icons.
vue-fontawesome is another Vue component for Font Awesome icons. It offers more advanced features like dynamic icon loading and custom SVG icons. However, it is also limited to Font Awesome icons, whereas @iconify/vue supports a wide range of icon sets.
vue-material-design-icons is a Vue component for Material Design Icons. It allows you to easily integrate Material Design Icons into your Vue.js applications. Similar to vue-awesome and vue-fontawesome, it is limited to a single icon set.
Iconify for Vue is not yet another icon component! There are many of them already.
What you get with other components:
Iconify icon component is nothing like that. Component does not include any icon data, it is not tied to any specific icon set. Instead, all data is retrieved from public API on demand.
That means:
For more information about Iconify project visit https://iconify.design/.
For extended documentation visit Iconify for Vue documentation.
If you are using NPM:
npm install --save-dev @iconify/vue
If you are using Yarn:
yarn add --dev @iconify/vue
This component is not backwards compatible with Vue 2.
If you are using Vue 2, you need to install @iconify/vue2
component. It is almost identical to this component, but for Vue 2.
See Iconify for Vue 2 documentation.
Install @iconify/vue
and import Icon
from it:
import { Icon } from '@iconify/vue';
Then use Icon
component in template with icon name or data as "icon" parameter:
<Icon icon="mdi-light:home" />
Component will automatically retrieve data for "mdi-light:home" from Iconify API and render it. There are over 200,000 icons available on Iconify API from various free and open source icon sets, including all the most popular icon sets.
This icon component is designed to be used with Iconify API, loading icon data on demand instead of bundling it.
If you want to use icons without Iconify API, there are many other options available.
If you are experiencing issues with SSR hydration, there is an alternative solution available: Iconify Icon web component.
Web component is preferred to this component if:
Icon name is a string. Few examples:
@api-provider:icon-set-prefix:icon-name
mdi-light:home
(in this example API provider is empty, so it is skipped)It has 3 parts, separated by ":":
See Iconify for Vue icon names documentation for more detailed explanation.
Instead of icon name, you can pass icon data to component:
<template>
<Icon :icon="icons.chart" height="24" />
</template>
<script lang="ts">
import { Icon } from '@iconify/vue';
import areaChartOutlined from '@iconify-icons/ant-design/area-chart-outlined';
export default {
components: {
Icon,
},
data() {
return {
// Assign icon data to icons.chart
icons: {
chart: areaChartOutlined,
},
};
},
};
</script>
See icon packages documentation for more details.
Example above might currently fail with some use cases. Package @iconify-icons/mdi-light
uses ES modules that some software might not support yet. But do not worry, there is a simple solution: switch to CommonJS icon packages.
To switch to CommonJS package, replace this line in example above:
import home from '@iconify-icons/mdi-light/home';
with
import home from '@iconify/icons-mdi-light/home';
All icons are available as ES modules for modern bundler and as CommonJS modules for outdated bundlers. ES modules use format @iconify-icons/{prefix}
, CommonJS modules use @iconify/icons-{prefix}
.
For more details, see icon packages documentation.
Icons have 2 modes: inline and block. Difference between modes is vertical-align
that is added to inline icons.
Inline icons are aligned slightly below baseline, so they look centred compared to text, like glyph fonts.
Block icons do not have alignment, like images, which aligns them to baseline by default.
Alignment option was added to make icons look like continuation of text, behaving like glyph fonts. This should make migration from glyph fonts easier.
To toggle between block and inline modes, you can use boolean inline
property:
<template>
<div>
<p>
Block:
<Icon icon="line-md:image-twotone" />
<Icon icon="mdi:account-box-outline" />
</p>
<p>
Inline:
<Icon icon="line-md:image-twotone" :inline="true" />
<Icon icon="mdi:account-box-outline" :inline="true" />
</p>
</div>
</template>
<script>
import { Icon } from '@iconify/vue';
export default {
components: {
Icon,
},
};
</script>
Visual example to show the difference between inline and block modes:
icon
property is mandatory. It tells component what icon to render. If the property value is invalid, the component will render an empty icon. The value can be a string containing the icon name (icon must be registered before use by calling addIcon
or addCollection
, see instructions above) or an object containing the icon data.
The icon component has the following optional properties:
inline
. Changes icon behaviour to match icon fonts. See "Inline icon" section below.width
and height
. Icon dimensions. The default values are "1em" for both. See "Dimensions" section below.color
. Icon colour. This is the same as setting colour in style. See "Icon colour" section below.flip
, horizontalFlip
, verticalFlip
. Flip icon horizontally and/or vertically. See "Transformations" section below.rotate
. Rotate icon by 90, 180 or 270 degrees. See "Transformations" section below.align
, verticalAlign
, horizontalAlign
, slice
. Icon alignment. See "Alignment" section below.onLoad
. Callback function that is called when icon data has been loaded. See "onLoad" section below.Note: in templates you can use "camelCase" properties as "kebab-case". For example, horizontalFlip
can be used as horizontal-flip
.
In addition to the properties mentioned above, the icon component accepts any other properties and events. All other properties and events will be passed to generated SVG
element, so you can do stuff like assigning click event, setting the inline style, add title and so on.
By default, icon height is "1em". With is dynamic, calculated using the icon's width to height ratio.
There are several ways to change icon dimensions:
font-size
in style.width
and/or height
property.Values for width
and height
can be numbers or strings.
If you set only one dimension, another dimension will be calculated using the icon's width to height ratio. For example, if the icon size is 16 x 24, you set the height to 48, the width will be set to 32. Calculations work not only with numbers, but also with string values.
You can use numbers for width
and height
.
<Icon icon="mdi-light:home" :height="24" />
<Icon icon="mdi-light:home" :width="16" :height="16" />
Note ":" before attribute - in Vue it changes the value to expression, so "20" is a number, not a string.
Number values are treated as pixels. That means in examples above, values are identical to "24px" and "16px".
If you use strings without units, they are treated the same as numbers in an example above.
<Icon icon="mdi-light:home" height="24" />
<Icon icon="mdi-light:home" width="16" height="16" />
You can use units in width and height values:
<Icon icon="mdi-light:home" height="2em" />
Be careful when using calc
, view port based units or percentages. In SVG element they might not behave the way you expect them to behave and when using such units, you should consider settings both width and height.
Keyword "auto" sets dimensions to the icon's viewBox
dimensions. For example, for 24 x 24 icon using height="auto"
sets height to 24 pixels.
<Icon icon="mdi-light:home" height="auto" />
There are two types of icons: icons that do not have a palette and icons that do have a palette.
Icons that do have a palette, such as emojis, cannot be customised. Setting colour to such icons will not change anything.
Icons that do not have a palette can be customised. By default, colour is set to "currentColor", which means the icon's colour matches text colour. To change the colour you can:
color
style or use stylesheet to target icon. If you are using the stylesheet, target svg
element.color
property.Examples:
Using color
property:
<Icon icon="eva:alert-triangle-fill" color="red" />
<Icon icon="eva:alert-triangle-fill" color="#f00" />
Using inline style:
<Icon icon="eva:alert-triangle-fill" style="color: red;" />
<Icon icon="eva:alert-triangle-fill" :style="{color: 'red'}" />
<Icon icon="eva:alert-triangle-fill" :style="{color: '#f00'}" />
Using stylesheet:
<template>
<Icon icon="eva:alert-triangle-fill" class="red-icon" />
</template>
<style>
.red-icon {
color: red;
}
</style>
You can rotate and flip the icon.
This might seem redundant because icon can also be rotated and flipped using CSS transformations. So why do transformation properties exist? Because it is a different type of transformation.
If you have a square icon, this makes no difference. However, if you have an icon that has different width and height values, it makes a huge difference.
Rotating 16x24 icon by 90 degrees results in:
See icon transformations documentation for more details.
There are several properties available to flip an icon:
horizontal-flip
or h-flip
: boolean property, flips icon horizontally.vertical-flip
or v-flip
: boolean property, flips icon vertically.flip
: shorthand string property, can flip icon horizontally and/or vertically.Examples:
Flip an icon horizontally:
<Icon icon="eva:alert-triangle-fill" :h-flip="true" />
<Icon icon="eva:alert-triangle-fill" :horizontal-flip="true" />
<Icon icon="eva:alert-triangle-fill" flip="horizontal" />
Flip an icon vertically:
<Icon icon="eva:alert-triangle-fill" :v-flip="true" />
<Icon icon="eva:alert-triangle-fill" :vertical-flip="true" />
<Icon icon="eva:alert-triangle-fill" flip="vertical" />
Flip an icon horizontally and vertically (the same as 180 degrees rotation):
<Icon icon="eva:alert-triangle-fill" :h-flip="true" :v-flip="true" />
<Icon
icon="eva:alert-triangle-fill"
:horizontal-flip="true"
:vertical-flip="true"
/>
<Icon icon="eva:alert-triangle-fill" flip="horizontal,vertical" />
Why are there multiple boolean properties for flipping an icon?
In components for other frameworks, properties for flipping an icon are hFlip
and vFlip
. Vue has special treatment for properties that start with v-, so vFlip
(same applies to vAlign
attribute) attribute is not available without using tricky syntax.
Because of that, Vue component uses longer property names: verticalFlip
instead of vFlip
and horizontalFlip
instead of hFlip
for consistency.
An icon can be rotated by 90, 180 and 270 degrees. Only contents of the icon are rotated.
To rotate an icon, use rotate
property. Value can be a string (degrees or percentages) or a number.
Number values are 1 for 90 degrees, 2 for 180 degrees, 3 for 270 degrees.
Examples of 90 degrees rotation:
<Icon icon="eva:alert-triangle-fill" :rotate="1" />
<Icon icon="eva:alert-triangle-fill" rotate="90deg" />
<Icon icon="eva:alert-triangle-fill" rotate="25%" />
onLoad
property is an optional callback function. It is called when icon data has been loaded.
It is not an event, such as onClick
event for links, it is a simple callback function.
When onLoad
is called:
onLoad
is not called.onLoad
is called on first render.onLoad
is called on first re-render after icon data is retrieved from API.What is the purpose of onLoad
? To let you know when Icon component renders an icon and when it does not render anything. This allows you to do things like adding class name for parent element, such as "container--with-icon" that modify layout if icon is being displayed.
For extended documentation visit Iconify for Vue documentation.
Vue component is released with MIT license.
© 2020-PRESENT Vjacheslav Trushkin
See Iconify icon sets page for list of collections and their licenses.
FAQs
Iconify icon component for Vue 3.
The npm package @iconify/vue receives a total of 156,611 weekly downloads. As such, @iconify/vue popularity was classified as popular.
We found that @iconify/vue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.