Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rails-designer/rails_icons

Add any icon library to a Rails app. Support for Feather, Lucide, Heroicons, Tabler and others
https://github.com/rails-designer/rails_icons

boxicons feather-icons heroicons icons lucide-icon lucide-icons phosphor phosphor-icons phosphoricons rails tabler-icons

Last synced: 3 days ago
JSON representation

Add any icon library to a Rails app. Support for Feather, Lucide, Heroicons, Tabler and others

Awesome Lists containing this project

README

        

# Rails Icons

Add any icon library to a Rails app. Rails Icons has first-party support for a [handful of libraries](#first-party-libraries). It is library agnostic so it can be used with any icon library using the same interface.

```erb
# Using the default icon library
<%= icon "check", class: "text-gray-500" %>

# Using any custom library
<%= icon "apple", library: "simple_icons", class: "text-black" %>
```

The icons are sourced directly from their respective GitHub repositories, ensuring Rails Icons remain lightweight.

**Sponsored By [Rails Designer](https://railsdesigner.com/)**





Rails Designer

## Install

Add the gem
```bash
bundle add rails_icons
```

Install, choosing one of the supported libraries
```bash
rails generate rails_icons:install --libraries=LIBRARY_NAME
```

**Example**
```bash
rails generate rails_icons:install --libraries=heroicons

Or multiple at once
rails generate rails_icons:install --libraries=heroicons lucide
```

## Usage

```ruby
# Uses the default library and variant defined in config/initializer/rails_icons.rb
icon "check"

# Use another variant
icon "check", variant: "solid"

# Set library explictly
icon "check", library: "heroicons"

# Add CSS
icon "check", class: "text-green-500"

# Add CSS with class_names
# article: https://railsdesigner.com/conditional-css-classes-in-rails/
# docs: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-token_list
icon "check", class: ["size-4", "bg-red-500": !verified?, "bg-green-500": verified?]

# Add data attributes
icon "check", data: { controller: "swap" }

# Set the stroke-width
icon "check", stroke_width: 2
```

## First-party libraries

- [Boxicons](https://github.com/atisawd/boxicons) (1600+ icons)
- [Feather](https://github.com/feathericons/feather) (280+ icons)
- [Heroicons](https://github.com/tailwindlabs/heroicons) (300+ icons)
- [Lucide](https://github.com/lucide-icons/lucide) (1500+ icons)
- [Phosphor](https://github.com/phosphor-icons/core) (9000+ icons)
- [Tabler](https://github.com/tabler/tabler-icons) (5700+ icons)

## Animated icons

Rails Icons also includes a few animated icons. Great for loading states and so on. These are currently included:

- `faded-spinner`
- `trailing-spinner`
- `fading-dots`
- `bouncing-dots`

Use like this: `icon "faded-spinner", library: "animated"`. The same attributes as other libraries are available.

## Custom icon library

Need to use an icon from another library?

1. run `rails generate rails_icons:initializer --custom=simple_icons`;
2. add the (SVG) icons to the created directory **app/assets/svg/icons/simple_icons**;

Every custom icon can now be used with the same interface as first-party icon libraries.
```ruby
icon "apple", library: "simple_icons", class: "text-black"
```

## Sync icons

To sync all installed libraries, run
```bash
rails generate rails_icons:sync
```

To sync only a specific library, run
```bash
rails generate rails_icons:sync --libraries=heroicons

# Or multiple at once:
rails generate rails_icons:sync --libraries=heroicons lucide
```

## Contributing

This project uses [Standard](https://github.com/testdouble/standard) for formatting Ruby code. Please make sure to run `be standardrb` before submitting pull requests. Run tests via `rails test`.

## License

Rails Icons is released under the [MIT License](https://opensource.org/licenses/MIT).