Module: RailsFeather::Helper

Defined in:
lib/rails_feather/helper.rb

Instance Method Summary collapse

Instance Method Details

#feather_icon(icon_name, **options) ⇒ Object

To add a feather_icon, call <%= feather_icon "activity" %> on your erb template. Head over to feathericons.com to view all the icons.

Options

The helper method accepts mutiple arguments such as:

Handling the icon size

Specify a size param in the helper method to set the height and width on the svg icon.

<%= feather_icon "activity", size: 20 %>

size defaults to 24 if not defined.

Handling the stroke width

Specify a stroke_width param in the helper method to set the stroke-width on the svg icon.

<%= feather_icon "activity", stroke_width: 1 %>

stroke_width defaults to 2 if not defined.

HTML attributes

Any html and eruby attribute syntax is supported, for eg:

<%= feather_icon "activity", class: "custom-class", aria: { label: "User activity" } %>

Accessibility

The helper method automatically sets aria-hidden="true" if aria-label is not set, and if aria-label is set, then role="img" is set on the svg.



36
37
38
39
# File 'lib/rails_feather/helper.rb', line 36

def feather_icon(icon_name, **options)
  icon = RailsFeather.new(icon_name, **options)
  (:svg, icon.svg_path.html_safe, icon.options)
end