0.0.3 • Published 5 years ago

svelte-fontawesome v0.0.3

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

svelte-fontawesome

FontAwesome icons for Svelte.

Based on fa-svelte with a few added options. If you only need to show an icon, that library may be a simpler and better choice.

Getting Started

The use of the yarn package manager is strongly recommended, as opposed to using npm.

Add svelte-fontawesome, along with the FontAwesome icon set(s) that you need:

yarn add -D svelte-fontawesome
yarn add -D @fortawesome/free-solid-svg-icons

Usage

<script>
  import { Icon } from 'svelte-fontawesome';
  import { faEnvelope } from '@fortawesome/free-solid-svg-icons/faEnvelope';
</script>

<Icon icon={faEnvelope}/>

Properties

proptypeabout
classstringAdd extra classes to the icon
fwboolSet the icon to a fixed width
sizestringSet the icon's size to lg, sm or xs
stackstringSet the icon's stack size (see below)
inverseboolSet the icon's color to white

Stacks

To stack multiple icons, place them within an IconStack. Set the stack property to 1x for the regularly sized icon and 2x for the larger icon. The inverse property can be used to show the smaller icon against the larger one (or vice-versa).

<script>
  import { IconStack, Icon } from 'svelte-fontawesome';
  import { faCircle } from '@fortawesome/free-solid-svg-icons/faCircle';
  import { faEnvelope } from '@fortawesome/free-solid-svg-icons/faEnvelope';
</script>

<IconStack>
  <Icon icon={faCircle} stack="2x" />
  <Icon icon={faEnvelope} stack="1x" inverse />
</IconStack>

Classes

Classes for icon components must be global:

<style>
  :global(.class1) {
    color: blue;
    font-size: 2em;  /* 2em = 2x, 3em = 3x, etc */
  }
</style>

<Icon icon={faSearch} class="class1" />

Transforms

You can use CSS transforms to rotate and flip icons:

<style>
  :global(.rotate) {
    transform: rotate(90deg);
  }

  :global(.flip-v) {
    transform: scale(1,-1);
  }

  :global(.flip-h) {
    transform: scale(-1,1);
  }

  :global(.flip-both) {
    transform: scale(-1,-1);
  }
</style>