npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ntag/react-fontawesome

v1.8.0

Published

Font Awesome 5 React component, improved, splitting icons in individual pieces that can be colored

Downloads

16

Readme

This package allows you to color individual pieces of Font Awesome icons, using React.

It is basically the same as @fortawesome/react-fontawesome, except <FontAwesomeIcon> accepts a new prop fill={['color1', 'color2', 'color3']} to specify the colors of the different parts of the icon.

Installation

Install React FontAwesome as usual, except @fortawesome/react-fontawesome you replace by @ntag/react-fontawesome:

$ npm i --save @fortawesome/fontawesome-svg-core \
  npm i --save @fortawesome/free-solid-svg-icons \
  npm i --save @ntag/react-fontawesome

Usage

In your main file (index.js, App.js):

import { library } from '@fortawesome/fontawesome-svg-core';
import { faCloudSun } from '@fortawesome/free-solid-svg-icons';

library.add(faCloudSun);

In your component:

import FontAwesomeIcon from '@ntag/react-fontawesome';

export const Weather = () => (
  <div>
    <h1>Weather</h1>
    <FontAwesomeIcon icon="cloud-sun" fill={['#3C6997', '#EDFF71', '#F1DB4B']} />
  </div>
);

fill accepts an array of CSS colors. Use currentColor to use the text color. The text color will also be used if the fill array is smaller than the number of pieces in the icon.

Finally, if you don't pass the fill property, <FontAwesomeIcon> will work exactly the same as the original one from @fortawesome/react-fontawesome.

Also, instead of using an array, you can also use multiple props: fill0, fill1, fill2, fill3 to colors the parts 1, 2, 3 and 4 for example.

How does it work?

Font Awesome icons are composed by a single <path> SVG element.

First, the path is split on m or M letters, indicating a movement of the pencil, to get multiple pieces.

We have multiple pieces but two problems: the paths are not correctly positionned, and the subtraction of shapes doesn't work anymore. We start by recomputing the correct position of each piece.

It looks better. However, the second piece should be subtracted to the first one, to create a hole. Even if the two paths are drawn in opposite directions, the subtraction doesn't work because they are now in two different <path>. We need to merge elements which work together.

To do that, the algorithm takes each path, computes if it intersects the previous one, and if that's the case, merge the two <path> together, so the subtraction works. If that's not the case, it doesn't merge them and process the next path.