- Регистрация
- 1 Мар 2015
- Сообщения
- 5,923
- Баллы
- 155
This article was originally published on
After about 8 months and a modest multiple thousands downloads, !
Rails Icons is a gem for Rails to add (SVG) icons to your library. 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 :
<%= 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!
Any icon 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 , meaning you can contribute if you want to. I'd like to thank and for their work on this release!
After about 8 months and a modest multiple thousands downloads, !
Rails Icons is a gem for Rails to add (SVG) icons to your library. 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 :
<%= 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!
Any icon 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 , meaning you can contribute if you want to. I'd like to thank and for their work on this release!