Skip to content

Commit 22a05a9

Browse files
LBMarcy SuttonAisha BlakeGatsbyJS Bot
authored
chore(recipe):Add a recipe for using FontAwesome (#21275)
* Recipe for using fontawesome * Update docs/docs/recipes/styling-css.md Co-Authored-By: Marcy Sutton <[email protected]> * Update docs/docs/recipes/styling-css.md Co-Authored-By: Marcy Sutton <[email protected]> * Update docs/docs/recipes/styling-css.md Co-Authored-By: Marcy Sutton <[email protected]> * Update docs/docs/recipes/styling-css.md Co-Authored-By: Marcy Sutton <[email protected]> * Update docs/docs/recipes/styling-css.md Co-Authored-By: Marcy Sutton <[email protected]> * Address review comments * Break FontAwesome into two words Co-authored-by: Marcy Sutton <[email protected]> Co-authored-by: Aisha Blake <[email protected]> Co-authored-by: GatsbyJS Bot <[email protected]>
1 parent 4f7424a commit 22a05a9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

docs/docs/recipes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ There are so many ways to add styles to your website; Gatsby supports almost eve
5353
- [Adding a Local Font](/docs/recipes/styling-css#adding-a-local-font)
5454
- [Using Emotion](/docs/recipes/styling-css#using-emotion)
5555
- [Using Google Fonts](/docs/recipes/styling-css#using-google-fonts)
56+
- [Using Font Awesome](/docs/recipes/styling-css#using-fontawesome)
5657

5758
## [3. Working with starters](/docs/recipes/working-with-starters)
5859

docs/docs/recipes/styling-css.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,44 @@ _NOTE: So for the above example, the relevant CSS declaration would be `font-fam
416416
- [Typography.js](/docs/typography-js/) - Another option for using Google fonts on a Gatsby site
417417
- [The Typefaces Project Docs](https://github.com/KyleAMathews/typefaces/blob/master/README.md)
418418
- [Live example on Kyle Mathews' blog](https://www.bricolage.io/typefaces-easiest-way-to-self-host-fonts/)
419+
420+
## Using Font Awesome
421+
422+
Using [Font Awesome](https://fontawesome.com/) gives you access to thousands of icons for use on your site. Since Gatsby sites are React sites, it's recommended to use the [react-fontawesome](https://github.com/FortAwesome/react-fontawesome) SVG library.
423+
424+
### Prerequisites
425+
426+
- The [Gatsby CLI](/docs/gatsby-cli/) installed
427+
- A [Gatsby site](/docs/quick-start)
428+
429+
### Directions
430+
431+
1. Install the `react-fontawesome` dependencies.
432+
433+
```shell
434+
npm install @fortawesome/fontawesome-svg-core @fortawesome/free-brands-svg-icons @fortawesome/react-fontawesome
435+
```
436+
437+
> Note that there are multiple icon libraries within `react-fontawesome`. You may also be interested in `free-regular-svg-icons` and `free-solid-svg-icons` which you would install the same way.
438+
439+
2. Import the `FontAwesomeIcon` component and the icon you want to use. Then use the icon as a component directly in your JSX files:
440+
441+
```jsx:title=index.js
442+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
443+
import { faReact } from "@fortawesome/free-brands-svg-icons"
444+
445+
const IndexPage = () => (
446+
<Layout>
447+
<FontAwesomeIcon icon={faReact} /> //highlight-line
448+
</Layout>
449+
)
450+
451+
export default IndexPage
452+
```
453+
454+
> This example imports a single, specific icon and uses it for improved performance. As an alternative, you can [import the icons and build a library](https://github.com/FortAwesome/react-fontawesome#build-a-library-to-reference-icons-throughout-your-app-more-conveniently).
455+
456+
### Additional resources
457+
458+
- [Font Awesome](https://fontawesome.com/)
459+
- [react-fontawesome](https://github.com/FortAwesome/react-fontawesome)

0 commit comments

Comments
 (0)