Vue-Awesome
Awesome SVG icon component for Vue.js, with built-in Font Awesome icons.
Vue-Awesome an SVG icon component for Vue.js, with built-in icons courtesy of Font Awesome.
Installation
npm (Recommended)
bower
Manual
Just download dist/vue-awesome.js
and include it in your HTML file:
Usage
Font Awesome 5 has separated all icons into several packs. Vue-Awesome is built upon its all free icons, which includes all free icons from 3 icon packs: regular
, solid
and brands
. Since the solid
pack has the most number of icons, we organize all Vue-Awesome icons as follows:
-
All icons from
solid
pack are located invue-awesome/icons
directory and have unprefixedname
prop values. -
Icons from
regular
andbrands
are located invue-awesome/icons/regular
andvue-awesome/icons/brands
, which have prefixedname
prop values likeregular/flag
orbrands/reddit
.
You can find all available name
values from Font Awesome's website like beer
, file
and camera
.
ES Modules with NPM & vue-loader (Recommended)
⚠️ Heads up
Importing the souce version
If you are using official Vue CLI to create your project and you want to use the untranspiled component (import vue-awesome/components/Icon
rather than import vue-awesome
directly, to optimize bundle size, which is recommended), you'll encounter the problem that the default configuration will exclude node_modules
from files to be transpiled by Babel.
For Vue CLI 3+, add vue-awesome
into transpileDependencies
in vue.config.js
like this:
For Vue CLI 2 with the webpack
template, modify build/webpack.base.conf.js
like this:
If you are using bare webpack config, just do similar modifications make it work.
Using with Nuxt.js
When using Vue-Awesome on the server side with Nuxt.js, it may prompt Unexpected token import
because Nuxt.js has configured an external
option by default, which prevent files under node_modules
from being bundled into the server bundle with only a few exceptions. We need to whitelist vue-awesome
in nuxt.config.js
as follows:
For Nuxt.js 2:
For Nuxt.js 1:
Unit Testing with Jest
Make sure to whitelist vue-awesome
from the transformIgnorePattern
. Add following configuation in test/unit/jest.conf.js
:
Don't import all icons if you don't want to make unit testing slow because this will transform all icons from ES module and thus slow down the test process.
CommonJS with NPM without ES Next support
AMD
Global variable
The component class is exposed as window.VueAwesome
.
Props
-
name: string
The name of the icon. It's necessary if the component isn't used as the wrapper of an icon stack. All valid names correspond to the file path relative to the
icons
directory. Notice that you may have to check the name of the icon pack after you search on FontAwesome's website. For example, you'll see a URL argument ofstyle=brands
on the detail page for500px
and the icon name will bebrands/500px
.Only free icons for FontAwesome are available by default and because the
solid
style has the most icons, we've made it the default pack so the path prefixes can be omitted.If you pass
null
to this prop, the whole component will not be rendered. -
scale: number|string
Used to adjust the size of the icon. Default to
1
. -
spin: boolean
Used to specify whether the icon is spining. Default to
false
. -
inverse: boolean
If set to
true
, the color of the icon will become#fff
. Default tofalse
. -
pulse: boolean
Set the pulse effect to the icon. Default to
false
. -
flip: 'vertical'|'horizontal'|null
Used to flip the icon.
-
label: string
Set the
aria-label
for the icon if provided. Otherwise the icon will haverole="presentation"
thus not accessible.
Misc
If you are using vue-awesome/components/Icon
(instead of the whole bundled version), Vue-Awesome won't import a single icon by default. Do not forget to import icons you want to use.
If these caveats don't help and there are no proper workarounds in earlier issues, please feel free to file a new one.
Styling
Dynamic sizing
You can make the icons scale dynamically according to your font-size
by adding the following CSS:
Colors
The icon color is inherited from the font color of the parent element by default. You can easily change it to any other color by specifying the color
property.
Local development
Open http://localhost:8080/demo
to see the demo.
Updating icons
Don't touch files in src/icons
but update assets/svg/*
instead and run npm run icons
to re-generate icon module files.
Registering custom icons
Simple case
You can register custom icons like this:
More advanced cases
If your SVG file has more than one path or polygon, and/or you want to have a predefined style, you can register like this:
Paths
Polygons
Raw SVG
You need to include innersvg-polyfill before you use this feature.