GithubHelp home page GithubHelp logo

victoragung / vue-fontawesome Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fortawesome/vue-fontawesome

0.0 1.0 0.0 300 KB

Font Awesome 5 Vue component

Home Page: https://fontawesome.com

License: MIT License

Shell 0.52% HTML 5.56% JavaScript 81.60% Vue 12.31%

vue-fontawesome's Introduction

vue-fontawesome

npm

Font Awesome 5 Vue component

Installation

$ npm i --save @fortawesome/fontawesome
$ npm i --save @fortawesome/fontawesome-free-solid
$ npm i --save @fortawesome/vue-fontawesome

or

$ yarn add @fortawesome/fontawesome
$ yarn add @fortawesome/fontawesome-free-solid
$ yarn add @fortawesome/vue-fontawesome

Usage

The basics

The icon property of the FontAwesomeIcon component can be used in the following way:

Shorthand that assumes a prefix of fas:

<font-awesome-icon icon="spinner" />

Explicit prefix (note the Vue bind shorthand because this uses an array):

<font-awesome-icon :icon="['far', 'spinner']" />

Explicit icon definition (this is pseudo-code, see examples below for more detail):

import faCoffee from '@fortawesome/fontawesome-free-solid/faCoffee'

<font-awesome-icon :icon="getIcon" />

function getIcon () {
  return faCoffee
}

Using it with Vue

Using an explicit icon offers the advantage of only bundling the icons that you use in your final bundled file. This allows us to subset Font Awesome's thousands of icons to just the small number that are normally used.

Import the specific icons that you need:

<template>
  <div id="app">
    <font-awesome-icon :icon="icon" />
  </div>
</template>

<script>
import FontAwesomeIcon from '@fortawesome/vue-fontawesome'
import faCoffee from '@fortawesome/fontawesome-free-solid/faCoffee'

export default {
  name: 'FAExample',

  computed: {
    icon () {
      return faCoffee
    }
  },

  components: {
    FontAwesomeIcon
  }
}
</script>

It can be tedious to always import the icons individually so a library can be configured and shorthand can be used when rendering the icon.

Define a library that can be used without explicit imports:

App.js

import Vue from 'vue'
import Main from './Main.vue'
import FontAwesomeIcon from '@fortawesome/vue-fontawesome'
import fontawesome from '@fortawesome/fontawesome'
import brands from '@fortawesome/fontawesome-free-brands'
import faSpinner from '@fortawesome/fontawesome-free-solid/faSpinner'

fontawesome.library.add(brands, faSpinner)

new Vue({
  el: '#app',
  render: h => h(Main)
})

FAExample.vue

<template>
  <div id="app">
    <!-- If you are using the "Solid" style you can simply use the icon name -->
    <font-awesome-icon icon="spinner" />
    <!-- Using another style needs a prefix in the following array format -->
    <font-awesome-icon :icon="['fab', 'font-awesome']" />
  </div>
</template>

<script>
export default {
  name: 'FAExample',

  components: {
    FontAwesomeIcon
  }
}
</script>

Features

Basic

Spin and pulse animation:

<font-awesome-icon icon="spinner" spin />
<font-awesome-icon icon="spinner" pulse />

Fixed width:

<font-awesome-icon icon="spinner" fixed-width />

Border:

<font-awesome-icon icon="spinner" border />

List items:

<font-awesome-icon icon="spinner" list-item />

Flip horizontally, vertically, or both:

<font-awesome-icon icon="spinner" flip="horizontal" />
<font-awesome-icon icon="spinner" flip="vertical" />
<font-awesome-icon icon="spinner" flip="both" />

Size:

<font-awesome-icon icon="spinner" size="xs" />
<font-awesome-icon icon="spinner" size="lg" />
<font-awesome-icon icon="spinner" size="6x" />

Rotate:

<font-awesome-icon icon="spinner" rotate="90" />
<font-awesome-icon icon="spinner" rotate="180" />
<font-awesome-icon icon="spinner" rotate="270" />

Pull left or right:

<font-awesome-icon icon="spinner" pull="left" />
<font-awesome-icon icon="spinner" pull="right" />

Advanced

Power Transforms:

<font-awesome-icon icon="spinner" transform="shrink-6 left-4" />
<font-awesome-icon icon="spinner" :transform="{ rotate: 42 }" />

Masking:

<font-awesome-icon icon="coffee" :mask="['far', 'circle']" />

Symbols:

<font-awesome-icon icon="edit" symbol />
<font-awesome-icon icon="edit" symbol="edit-icon" />

Layers:

For this you should import FontAwesomeLayers as well:

import { FontAwesomeIcon, FontAwesomeLayers } from '@fortawesome/vue-fontawesome'

export default {
  ...
  components: {
    FontAwesomeIcon,
    FontAwesomeLayers
  }
  ...
}

You can then simply layer up your icons:

<font-awesome-layers class="fa-lg">
  <font-awesome-icon icon="circle" />
  <font-awesome-icon icon="check" transform="shrink-6" style="color: white;" />
</font-awesome-layers>

vue-fontawesome's People

Contributors

aidurber avatar originalexe avatar plindelauf avatar robmadole avatar silverbackdan avatar supercodepoet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.