Giter Club home page Giter Club logo

fontawesome.macro's Introduction

fontawesome.macro

Node.js CI

Description

This babel macro enables fontawesome icons to be imported automatically when using the following tagged template/function syntax

Before:

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faSquare } from '@fortawesome/free-solid-svg-icons'


<FontAwesome icon={faSquare} />

After:

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { fas } from 'fontawesome.macro'

<FontAwesome icon={fas`square`} />
// or
<FontAwesome icon={fas('square')} />

Usage

https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md

Read the above doc to enable babel macros. If you are using create-react-app, babel macros are enabled by default so you should be able to import this macro without configuring anything.

You can use the following tagged template/function macros:

fal -> light
fas -> solid
fab -> brands
fad -> duotone (pro only)

You can specify free or pro in the babel plugin macro config. The below config enables use of pro icons(by default this macro uses free icons).

// babel-plugin-macros.config.js
module.exports = {
  // ...
  'fontawesome.macro': {
    type: 'pro'
  }
}

Note that you need to install svg font packages you want to use in your project by yourself.

https://fontawesome.com/how-to-use/with-the-api/setup/importing-icons

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

fontawesome.macro's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar javascripter avatar sojinsamuel avatar thorn0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fontawesome.macro's Issues

MacroError: Only string literals are supported when referencing icons (use a string here instead)

I understand that this might be a Typescript issue rather than a macro issue, but I wonder if you could be of help.

I'm trying to make a basic utility to conditionally render "chevron-up" OR "chevron-down".

Doing this...

const chevronIconName: IconName = isExpanded ? "chevron-up" : "chevron-down";
const chevronIcon = solid(chevronIconName) ;

Throws this error and of course it breaks the webpack build.

MacroError: Only string literals are supported when referencing icons (use a string here instead)

SyntaxError when replace string icon name with a const

Hello guys,
When I'm using a string like fas('phone-alt') its works perfectly, but when I replace that string with a const or a props it giving me this error.

SyntaxError: /components/layout/Molecules/ProductIconCard.js: fontawesome.macro: Invalid number or type of arguments.
  13 |   // }
  14 |   const icon = "phone-alt";
> 15 |   console.log("icon", fas(icon));
     |                       ^^^^^^^^^

What I'm doing wrong?

Module not found: Can't resolve 'fs'

after install fontawesome libraries, fontawesome.macro and cosmiconfig I'm getting this error.

error - ./node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist/readFile.js
Module not found: Can't resolve 'fs' in '/node_modules/babel-plugin-macros/node_modules/cosmiconfig/dist'

What I'm missing? :/

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.