Giter VIP home page Giter VIP logo

elm-fontawesome's Introduction

FontAwesome 5 for Elm. Build Status

This is an Elm library for FontAwesome 5. This does not rely on any external javascript (e.g: using the JavaScript library to replace nodes, which can cause issues with Elm), and unlike the font, only includes the icons you use in your Elm code if you minify your output, as well as providing access to the powerful transformation, layering, text, counter, and masking features.

How it works.

This package is generated using the FontAwesome SVG JavaScript Core. If you are interested in how this is done, would like to make a version of the library for pro icons, or want to update to a new version of FontAwesome (do also feel free to submit an issue if the library is out of date) please see the generator repo.

This does mean that this is a big package, the compiled Elm code weighs in at over 1MB. This would naturally not be ideal in most situations. The good news is that it is easy to minify out any unused icons thanks to Elm's pure nature. If you are already minifying your compiled Elm (which is good practice anyway), then you don't need to do anything more. If you are not, then it is simple to do. This will result in perfect subsetting - you only ship the icons you use.

Using the elm library.

The easiest way to use the library is to install the elm package directly: elm install lattyware/elm-fontawesome.

Once you have done that, the best place to start is at the elm-fontawesome-example project which should give you a good idea of what you can do and how to do it. For more detail on the available options, please see the documentation, which gives an exhaustive description.

Function names.

In general, names are just the camel-cased version of the original name. E.g: arrow-alt-circle-right becomes FontAwesome.Solid.arrowAltCircleRight. Where the first character of the name isn't valid as an Elm identifier, the name is prefixed with fa, e.g: 500px becomes FontAwesome.Brands.fa500px. Note this applies to the FontAwesome.Attributes module as well, so 2x becomes FontAwesome.Attributes.fa2x.

Required CSS.

FontAwesome does require some CSS styles. You can either use FontAwesome.Styles.css to include an HTML style node with the necessary code directly in your page in Elm, or you can include the CSS from @fortawesome/fontawesome-free/css/svg-with-js.min.css in your page however you choose. Do note you do not need the webfont version - the icons in this package are rendered with SVG, and while that CSS will work, you will make your users load a webfont for no reason.

Styling icons.

Font Awesome supports styling your icons in various ways. These styles are exposed as attributes for the various classes in the FontAwesome.Attributes module.

Differences in behaviour from the official library.

While effort has been made to produce the same output where possible, some differences from the official library do exist:

  • We don't produce or consume any data attributes as we won't use them from Elm code anyway.
  • When masks are created, the official library generates random ids to avoid collisions from multiple icons on the same page. In Elm, this is impossible to do without exposing it in the API, so we don't. If you need ids you will need to manually specify them. It is possible to use random ids, please see the example for more.

Troubleshooting.

Icons show up as giant images.

This normally means you have not included the required CSS.

My class isn't applied, or it is but the icon breaks.

Mixing Svg.Attribute.class and Html.Attribute.class can cause the classes to get overwritten. This library uses Svg.Attribute.class, so if you always use this when providing attributes to the library you should not have problems.

elm-fontawesome's People

Contributors

lattyware avatar

Watchers

James Cloos 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.