Module: FComponents::IconsHelper

Defined in:
app/helpers/f_components/icons_helper.rb

Constant Summary collapse

VALID_STYLES =
{
  solid: 'fa-solid',
  regular: 'fa-regular',
  light: 'fa-light',
  thin: 'fa-thin',
  duotone: 'fa-duotone',
  brands: 'fa-brands'
}.freeze

Instance Method Summary collapse

Instance Method Details

#f_icon(options) ⇒ String

Internal: Creates the <i> tag with the appropriate classes and adds text if necessary

Parameters: Returns:



57
58
59
60
61
62
# File 'app/helpers/f_components/icons_helper.rb', line 57

def f_icon(options)
  text = options.delete(:text)
  tag = (:i, nil, options)
  tag << " #{text}" if text.present?
  tag
end

#fa_icon(name, options = {}) ⇒ String

Public: Creates a Font Awesome icon tag

Examples:

fa_icon('home')
#=> <i class="fa-solid fa-home"></i>

fa_icon('user', style: :regular)
#=> <i class="fa-regular fa-user"></i>

fa_icon('github', style: :brands)
#=> <i class="fa-brands fa-github"></i>

fa_icon('eye', class: 'strong space-x-2', text: 'my text')
#=> <i class="fa-solid fa-eye strong space-x-2"></i> my text

Parameters: Returns:



39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/f_components/icons_helper.rb', line 39

def fa_icon(name, options = {})
  style = options.delete(:style) { :solid }
  style_class = VALID_STYLES[style] || VALID_STYLES[:solid]

  icon_class = "fa-#{name}"
  custom_classes = options[:class].presence
  options[:class] = [style_class, icon_class, custom_classes].compact.join(' ')

  f_icon(options)
end