You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

42 lines
1.3 KiB

# Font Awesome Helper
module FaIconHelper
##
# mandatory:
# name: without 'fa-' prefix
# might be a symbol, automatic conversion of undashed symbol
# for instance symbol :magnify_lens is converted to string 'magnify-lens'
# optional:
# stroke: [:solid|:regular|:brands] solid as default value
# size: [2x, 3x, ... ]
# class: extra classes, any tailwind keyword...
# aria-hidden: true as default value
#
# example:
# fa_icon(:user)
# fa_icon(:user, stroke: :regular)
# fa_icon(:user, size: '2x')
# fa_icon(:user, class: 'text-blue-500')
##
def fa_icon(name, html_options = {})
warn_useless_options html_options
icon = to_dash(name)
stroke = to_dash(html_options[:stroke] || :solid)
content_class = "fa-#{icon} fa-#{stroke}"
content_class << " fa-#{html_options[:size]}" if html_options.key? :size
content_class << " #{html_options[:class]}" if html_options.key? :class
tag.i(class: content_class, 'aria-hidden': html_options['aria-hidden'] || true)
end
private
def to_dash(symbol) = symbol.to_s.dasherize
def warn_useless_options(hash)
hash.except(:stroke, :size, :class, 'aria-hidden').each_key do |key|
SemanticLogger[Module.nesting[0]].warn "useless option <#{key}>, please consider removal for safety reason!"
end
end
end