UNPKG

3.88 kBMarkdownView Raw
1# react-fontawesome
2
3[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
4[![Travis CI build status](https://img.shields.io/travis/danawoodman/react-fontawesome.svg)](https://travis-ci.org/danawoodman/react-fontawesome)
5[![Dependency Status](https://img.shields.io/david/danawoodman/react-fontawesome.svg)](https://david-dm.org/danawoodman/react-fontawesome)
6[![View on npm](https://img.shields.io/npm/dm/react-fontawesome.svg)](https://www.npmjs.com/package/react-fontawesome)
7[![View on npm](https://img.shields.io/npm/v/react-fontawesome.svg)](https://www.npmjs.com/package/react-fontawesome)
8
9> A React component for the font-awesome icon library.
10
11**If you are using Font Awesome v5+, please use [the official React component!](https://github.com/FortAwesome/react-fontawesome). `react-fontawesome` does not support FontAwesome v5!**
12
13## Install
14
15```bash
16npm install --save react-fontawesome
17```
18
19_**Note:** This component does not include any of the Font Awesome CSS or fonts, so you'll need to make sure to include those on your end somehow, either by adding them to your build process or linking to [CDN versions](https://www.bootstrapcdn.com/fontawesome/)._
20
21
22### Using CDN version
23
24The fastest way to get started is to import FontAwesome with a link tag in your page's `<head>`:
25
26```html
27<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
28```
29
30You can change the version number to use whatever version of FontAwesome you'd like.
31
32### Using with Webpack
33
34If you're using WebPack, you will need to install FontAwesome, import the FontAwesome Sass/Less, and configure the font path. Please see this [blog post](https://medium.com/@chanonroy/webpack-2-and-font-awesome-icon-importing-59df3364f35c) on how to get Webpack and FontAwesome working together.
35
36## Usage
37
38```js
39var React = require('react')
40var FA = require('react-fontawesome')
41
42React.render(<FA name="rocket" />, document.body)
43```
44
45## Features
46
47* No dependencies (other than React)
48* Simple API that mirrors Font Awesome's class names.
49* Supports all Font Awesome modifiers (see [API](#API) below).
50* Make use of Css Modules
51* Add your own `className`s, styles and other props (all additional props are passed directly to the component).
52
53## Examples
54
55**Regular usage**
56
57```js
58var React = require('react')
59var FontAwesome = require('react-fontawesome')
60
61var MyComponent = React.createClass({
62 render: function() {
63 return (
64 <FontAwesome
65 className="super-crazy-colors"
66 name="rocket"
67 size="2x"
68 spin
69 style={{ textShadow: '0 1px 0 rgba(0, 0, 0, 0.1)' }}
70 />
71 )
72 },
73})
74```
75
76**With the use of CSS Modules**
77
78```js
79import React from 'react'
80import FontAwesome from 'react-fontawesome'
81import faStyles from 'font-awesome/css/font-awesome.css'
82
83var MyComponent = React.createClass({
84 render: function() {
85 return (
86 <FontAwesome
87 className="super-crazy-colors"
88 name="rocket"
89 cssModule={faStyles}
90 size="2x"
91 spin
92 style={{ textShadow: '0 1px 0 rgba(0, 0, 0, 0.1)' }}
93 />
94 )
95 },
96})
97```
98
99The above will create output like this:
100
101```
102<span class="font-awesome__fa___2otTb font-awesome__fa-rocket___lfSov font-awesome__super-crazy-colors___3k583"></span>
103```
104
105## API
106
107See [the API docs](api.md) for full documentation.
108
109## Contributing
110
111Pull requests welcome!
112
113Run the test suite with `npm test` and format your code with `npm run format`. Make sure tests are passing and that you write tests for new features and document changes to the API with updates to the JSDocs.
114
115Before you submit your pull request, run `npm run dist` to build the project and commit the changes.
116
117## License
118
119[MIT](license) &copy; [Dana Woodman][author]
120
121[author]: https://github.com/danawoodman