Socket
Socket
Sign inDemoInstall

@fortawesome/react-fontawesome

Package Overview
Dependencies
1
Maintainers
3
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @fortawesome/react-fontawesome

Official React component for Font Awesome 5


Version published
Weekly downloads
1M
decreased by-4.41%
Maintainers
3
Install size
1.30 MB
Created
Weekly downloads
 

Readme

Source

react-fontawesome

Font Awesome 5 React component

This API is in early alpha stages and is likely to change

Installation

$ npm i --save @fortawesome/fontawesome
$ npm i --save @fortawesome/react-fontawesome

or

$ yarn add @fortawesome/fontawesome
$ yarn add @fortawesome/react-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:

<FontAwesomeIcon icon="spinner" />

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

<FontAwesomeIcon icon={['far', 'spinner']} />

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

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

<FontAwesomeIcon icon={faCoffee} />

Using it with React

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:

import ReactDOM from 'react-dom';
import FontAwesomeIcon from '@fortawesome/react-fontawesome'
import { faCoffee } from '@fortawesome/fontawesome-free-solid'

const element = (
  <FontAwesomeIcon icon={faCoffee} />
)

ReactDOM.render(element, document.body)

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 ReactDOM from 'react-dom';
import fontawesome from '@fortawesome/fontawesome'
import FontAwesomeIcon from '@fortawesome/react-fontawesome'
import brands from '@fortawesome/fontawesome-free-brands'
import { faSpinner } from '@fortawesome/fontawesome-free-solid'

fontawesome.library.add(brands, faSpinner)

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

Features

Basic

Spin and pulse animation:

<FontAwesomeIcon icon="spinner" spin />
<FontAwesomeIcon icon="spinner" pulse />

Fixed width:

<FontAwesomeIcon icon="spinner" fixed-width />

Border:

<FontAwesomeIcon icon="spinner" border />

List items:

<FontAwesomeIcon icon="spinner" list-item />

Flip horizontally, vertically, or both:

<FontAwesomeIcon icon="spinner" flip="horizontal" />
<FontAwesomeIcon icon="spinner" flip="vertical" />
<FontAwesomeIcon icon="spinner" flip="both" />

Size:

<FontAwesomeIcon icon="spinner" size="xs" />
<FontAwesomeIcon icon="spinner" size="lg" />
<FontAwesomeIcon icon="spinner" size="6x" />

Rotate:

<FontAwesomeIcon icon="spinner" rotate={90} />
<FontAwesomeIcon icon="spinner" rotate={180} />
<FontAwesomeIcon icon="spinner" rotate={270} />

Pull left or right:

<FontAwesomeIcon icon="spinner" pull="left" />
<FontAwesomeIcon icon="spinner" pull="right" />

Your own class names:

<FontAwesomeIcon icon="spinner" className="highlight" />

Advanced

Power Transforms:

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

Composition:

<FontAwesomeIcon icon="coffee" mask={['far', 'circle']} />

Symbols:

<FontAwesomeIcon icon="edit" symbol />
<FontAwesomeIcon icon="edit" symbol="edit-icon" />

FAQs

Last updated on 28 Nov 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc