Module: RailsIowaicon::Helper

Defined in:
lib/rails_iowaicon/helper.rb

Instance Method Summary collapse

Instance Method Details

#iowaicon(symbol, title: nil, **options) ⇒ Object

To add a iowaicon, call <%= iowaicon "icon_name" %> on your erb template. Head over to https://brand.uiowa.edu/graphic-elements to view all the icons.

Options

The helper method accepts mutiple arguments such as:

Variant

There are two types of variants: 'outline' and 'solid', the default being the 'outline'. To specify the solid variant, call <%= iowaicon "icon_name", variant: "solid" %>

HTML attributes

Any html attribute is supported, for eg:

<%= iowaicon "icon_name", class: "text-gray-500", data: { controller: "icon" } %>

Handling the icon size

Normally, if you're just using vanilla iowaicons with tailwindcss, you'd set w-5 h-5 as class attributes on the svg. With this helper, you just need to set the size attribute on the icon.

<%= iowaicon "icon_name", size: 20 %>

This will set the height and width attribute on the svg.

If the variant is set as outline, size automatically defaults to 24, and if the variant is set as solid, size automatically defaults to 20. However, this can be over-written with the size attribute.

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 automatically.



35
36
37
38
39
40
# File 'lib/rails_iowaicon/helper.rb', line 35

def iowaicon(symbol, title: nil, **options)
  icon = RailsIowaicon.new(symbol, **options)

  title_tag = (:title, title) if title
  (:svg, title_tag.to_s.html_safe + icon.svg_path.html_safe, icon.options)
end