Solar Icons
Packages

Rails

Solar Icons for Ruby on Rails views through the solar_icon helper.

# Gemfile
gem "solar_icons"

Requires Ruby 3.1+ and Rails 7+. The railtie includes the helper in every view and mailer template, so no initializer is needed.

Usage

The helper embeds the SVG with no network and no JavaScript:

<%= solar_icon("arrow-right") %>
<%= solar_icon("heart", weight: "bold-duotone", size: 32, class: "icon") %>

Options:

  • weight: one of linear (default), broken, line-duotone, outline, bold, bold-duotone
  • size: sets width and height together
  • stroke_width: overrides the stroke on Linear, Broken, and Line Duotone icons
  • secondary_color: and secondary_opacity: (0 to 1) style the accent layer of the two duotone styles
  • alt: renders an accessible <title> and drops the default aria-hidden
  • any extra keyword becomes an SVG attribute (style:, class:, ...); class: merges with configured defaults

Unknown names or weights raise an exception instead of rendering broken output.

Lookup constants

Generated constants keep the catalogue and the six weights discoverable in editors, and typos surface as NameError:

<%= solar_icon(SolarIcons::Icons::ARROW_UP, weight: SolarIcons::Weights::BOLD_DUOTONE) %>

solar_icon accepts the constants anywhere it accepts name or weight strings. Icon constants are autoloaded, so apps that only pass strings never load them; for runtime enumeration use SolarIcons.icon_names(style).

Configuration

# config/initializers/solar_icons.rb
SolarIcons.configure do |config|
  config.default_weight = "linear"
  config.default_size = 24
  config.default_attrs = { class: "icon" }
end

See solar_icons for the release history.

How is this guide?

Last updated on

On this page