Code Monkey home page Code Monkey logo

heroicon's Introduction

Heroicon

Build Status Ruby Style Guide

Ruby on Rails view helpers for the beautiful hand-crafted SVG icons, Heroicons.

Used in production at beehiiv ๐Ÿ

This gem has no official affiliation with Tailwind CSS or the Heroicon team (yet!). Check out their sites:

Installation

Add this line to your application's Gemfile:

gem "heroicon"

And then execute:

$ bundle

Run the installer

$ rails g heroicon:install

Usage

To use a icon in your views, simply use the provided view helper with the name of an icon.

<%= heroicon "search" %>

Heroicon comes with 3 variants, :outline, :solid and :mini. The default variant is :solid. This can be changed in config/initializers/heroicon.rb, which is generated during installation (See Configuration). To overwrite this in the view, use

<%= heroicon "search", variant: :outline %>

You can also pass HTML options directly to the icon.

<%= heroicon "search", options: { class: "text-primary-500" } %>

Heroicon currently supports icons matching Version 2.0.10. If there is an icon that is missing or a new version released, feel free to contribute by following our contributing guide below.

Configuration

After running rails g heroicon:install in the installation step, a configuration file will be created at config/initializers/heroicon.rb.

Currently there are two configuration options:

  • variant: The default variant to use if no variant is specified in the view.
    • You can set this to either :outline or :solid. Defaults to :solid.
  • default_class: A default class that gets applied to every icon.
    • This accepts either a String to apply to every icon, or a Hash, which applies the class based on the variant of the icon (see the example below).
    • You can disable this on a per-icon basis by passing disable_default_class: true in the options hash within the view.

Note: If you enable the default_class config, make sure to include config/intializers/heroicon.rb in the list of purged paths. For TailwindCSS 3.0+, you should have something like this in your tailwind.config.js:

module.exports = {
  //...
  content: [
    './app/helpers/**/*.rb',
    './app/javascript/**/*.js',
    './app/views/**/*',
    './config/initializers/heroicon.rb', // ๐Ÿ‘ˆ
  ],
  //...
}

An example configuration looks like this:

Heroicon.configure do |config|
  config.variant = :solid
  config.default_class = {solid: "h-5 w-5", outline: "h-6 w-6", mini: "h-4 w-4"}
end

Disabling the default class in the view:

<%= heroicon "search", options: { class: "custom-class", disable_default_class: true } %>

Contributing

Anyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/bharget/heroicon.git
cd heroicon
bundle install
bundle exec rake test

License

The gem is available as open source under the terms of the MIT License.

heroicon's People

Contributors

bharget avatar dorianmariecom avatar mzrnsh avatar n-studio avatar tmaier avatar trautwein 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.