Skip to content

Instantly share code, notes, and snippets.

@sergey-shpak
Last active March 26, 2019 09:38
Show Gist options
  • Save sergey-shpak/dd44afd391b4b912da084f19ba6a971e to your computer and use it in GitHub Desktop.
Save sergey-shpak/dd44afd391b4b912da084f19ba6a971e to your computer and use it in GitHub Desktop.
@hyperapp font-awesome Icon component

@hyperapp font-awesome Icon component

As you may know font-awesome 5 package now distributed as several packages:

Furthermore there are shakable hooks for each content package to build only used icons content (tree shaking).

And it is awesome!

More info about FA5: https://fontawesome.com/how-to-use/use-with-node-js

Anyway, @fortawesome/fontawesome (without icons content) usage increases your bundle up to 100kb (+30kb minified). Yikes!

We are going to be minimal, and will use only icons' content and hyperapp:

import { h } from 'hyperapp';
export default (props) => {
const {
src: {
icon: [
iconWidth,
iconHeight,
, ,
iconPath,
],
iconName,
prefix: iconPrefix,
},
name = iconName,
className = 'icon',
viewBox = `0 0 ${iconWidth} ${iconHeight}`,
prefix = iconPrefix,
path = iconPath,
} = props;
return <svg
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
role="img"
data-icon={ name }
data-prefix={ prefix }
class={ className }
viewBox={ viewBox }
>
<path fill="currentColor" d={path}></path>
</svg>;
};
import Icon from './Icon';
// To use shakable hook from icons content package
// import { faAnchor } from '@fortawesome/fontawesome-free-solid/shakable.es';
import faAnchor from '@fortawesome/fontawesome-free-solid/faAnchor';
export default props => <div>
<Icon src={faAnchor} className="someClassName" />
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment