This article was originally published on Rails Designer
After about 8 months and a modest multiple thousands downloads, Rails Icons 1.0.0 is here!
Rails Icons is a gem for Rails to add (SVG) icons to your app. It is library agnostic so it can be used with any icon library using the same interface.
Like this:
<%= icon "check", class: "text-gray-500" %>
It uses the library you set as a default, which could be any one from the first-party libraries supported: Feather, Heroicons, Lucide or Tabler. But icons from any other library can be added! Like the Apple logo from the Simple Icons library:
<%= icon "apple", library: "simple_icons", class: "text-black" %>
No icons included
Initially Rails Icons was released with all the icons included, but that quickly became burdensome. It also added extra workload for the maintainer (me), to update the gem whenever a library was updated.
So the icons were quickly removed from the gem, and now use a sync feature to pull the icons from their respective GitHub repo. If a library gets updated you simply run rails generate rails_icons:sync --libraries=heroicons
and you are up to date. Pretty neat! ✨
All icons included
Having support for any icon was important to me. If you ever used any library, you know it doesn't always have all the icons. While it isn't advised to mix libraries, every now and then, there is no way around it. I've extended my current library with own home-made ones, but, logo's from brands and platforms are also great example.
You can simply add the icons in the default folder at app/assets/svg/icons/LIBRARY (where LIBRARY is the custom library name) and you can use them with Rails Icons: <%= icon "apple", library: "simple_icons", class: "text-black" %>
.
If you need more configuration, run rails generate rails_icons:initializer --custom=LIBRARY
. This will add a configuration to your config/initializer/rails_icons.rb
file.
Animated icons
Also included in this release are a few animated icons. I added four custom-made icons that will work great for loading states (empty states, buttons etc.). These are included: faded-spinner, trailing-spinner, fading-dots, bouncing-dots. Use them like this: <% icon "faded-spinner", library: "animated" %>
.
Upgrade
Most of Rails Icon's API is the same to earlier versions. One breaking change is the replacing of set
with variant
for the icon helper (to choose the variant it uses, eg. solid instead of outline. Another smaller one is space-delimited instead of comma-separated options for the --libraries
flag for the initializer- and sync generator. The introduction of that flag is new too.
Rails Icons 1.0.0 is out now. It is also OSS, meaning you can contribute if you want to. I'd like to thank jordancalhoun and aamfahim for their work on this release! ❤️
Top comments (1)
Is there a library that should be supported as a first-party library? Let me know or add a PR!