Coder Social home page Coder Social logo

wc-fontawesome's Introduction

wc-fontawesome

Web component integration with Font Awesome (v5)

Installation

Libraries

yarn add wc-fontawesome-5 @fortawesome/fontawesome-svg-core

Icons

yarn add @fortawesome/free-regular-svg-icons @fortawesome/free-brands-svg-icons @fortawesome/free-solid-svg-icons

Usage

import 'wc-fontawesome'
import { library } from '@fortawesome/fontawesome-svg-core'
import { fas, faSpinner } from '@fortawesome/free-solid-svg-icons'

// add all solid icons...
library.add(fas)
// ... or individually
library.add(faSpinner)
<fa-icon icon="spinner"></fa-icon>

Examples

Look at the provided example: clone repository, install dependencies and run npm start script.

With shadow Dom

Font Awesome is implemented using global styles which do not work in web components that renders in shadow Dom.

To use wc-fontawesome-5 alongside shadow Dom is necessary to add the Font Awesome css in the component. See example below or check how can be done using LitElement styling system.

import { dom } from '@fortawesome/fontawesome-svg-core'

class ElementWithIcons extends HTMLElement {
  constructor() {
    super()
    const shadow = this.attachShadow({ mode: 'open' })
    shadow.innerHTML = `
      <style>
        ${dom.css()}
      </style>
      <fa-icon name="spinner"></fa-icon>
    `
  }
}

Alternatively, enable the usage of shadow Dom in fa-icon component. This will allow to use it in any web component with the drawback of breaking layers functionality:

import { configure } from 'wc-fontawesome-5'

configure({ shadowDom: true })

Components

  • fa-icon: show icon defined by icon or name property
  • fa-text: show text in layers
  • fa-counter: show counter in layers
  • fa-layers: container for layers (experimental - use div with fa-layers class instead)

Features

The following features are implemented

Basic

Size:

<fa-icon icon="spinner" size="xs"></fa-icon>
<fa-icon icon="spinner" size="lg"></fa-icon>
<fa-icon icon="spinner" size="6x"></fa-icon>

Note that icon size can be controlled with the CSS font-size attribute, and fa-icon's size prop determines icon size relative to the current font-size.

Fixed width:

<fa-icon icon="spinner" fixed-width></fa-icon>

Inverse:

<fa-icon icon="spinner" inverse></fa-icon>

List Items:

<fa-icon icon="spinner" list-item></fa-icon>

Rotate:

<fa-icon icon="spinner" rotation="90"></fa-icon>
<fa-icon icon="spinner" rotation="180"></fa-icon>
<fa-icon icon="spinner" rotation="270"></fa-icon>

Flip horizontally, vertically, or both:

<fa-icon icon="spinner" flip="horizontal"></fa-icon>
<fa-icon icon="spinner" flip="vertical"></fa-icon>
<fa-icon icon="spinner" flip="both"></fa-icon>

Spin and pulse animation:

<fa-icon icon="spinner" spin></fa-icon> <fa-icon icon="spinner" pulse></fa-icon>

Border:

<fa-icon icon="spinner" border></fa-icon>

Pull left or right:

<fa-icon icon="spinner" pull="left"></fa-icon>
<fa-icon icon="spinner" pull="right"></fa-icon>

Swap opacity (duotone icons only):

<fa-icon icon="stroopwafel"></fa-icon>
<fa-icon icon="stroopwafel" swap-opacity></fa-icon>

Advanced

Power Transforms:

<fa-icon icon="spinner" transform="shrink-6 left-4"></fa-icon>

Masking:

<fa-icon icon="coffee" mask="circle"></fa-icon>

Symbols:

<fa-icon icon="edit" symbol></fa-icon>
<fa-icon icon="edit" symbol="edit-icon"></fa-icon>

Layers:

Simple

<span class="fa-layers fa-fw">
  <fa-icon icon="square"></fa-icon>
  <fa-icon icon="check" inverse transform="shrink-6"></fa-icon>
</span>

With text

<span class="fa-layers fa-fw" style="background:MistyRose">
  <fa-icon icon="certificate"></fa-icon>
  <fa-text inverse transform="shrink-11.5 rotate--30" style="font-weight:900"
    >NEW</fa-text
  >
</span>

With counter

<span class="fa-layers fa-fw" style="background:MistyRose">
  <fa-icon icon="envelope"></fa-icon>
  <fa-counter style="background:Tomato">1,419</fa-counter>
</span>

Copyright

2023 - Jonas Marklén 2019 - Luiz Américo Pereira Câmara

Forked from wc-fontawesome Ported from react-fontawesome

wc-fontawesome's People

Contributors

blikblum avatar txc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.