font-awesome-sass
font-awesome-sass copied to clipboard
Support for icon on right of text for helper
Right now with the helper icon
you can do
button type="button" class="btn btn-default"
= icon('arrow-right', 'Login') # <i class="fa fa-arrow-right"></i> Login
It would be nice if there was a way to specify the icon on the right hand side.
button type="button" class="btn btn-default"
= icon('arrow-right', 'Login', rtl: true) # Login <i class="fa fa-arrow-right"></i>
bump
This is an ugly way of doing it, but you can make it into a helper like icon_right('angle-double-right','Next')
, but the below does allow for the icon to show on the right.
<%= link_to "Next #{icon('angle-double-right')}".html_safe, "#", class: 'btn btn-default' %>
The font-awesome-rails
gem has similar functionality, implemented as follows:
= icon('arrow-right', 'Login', right: true) # Login <i class="fa fa-arrow-right"></i>
I'm assuming there's been no resolution to this issue?
I'm assuming there's been no resolution to this issue?
Looking at the font-awesome-rails helper as well as this gems helper.
The solution below is working as a replacement allowing you to add the option to position the icon to the right of any text.
fa_icon('fab', 'font-awesome', 'Font Awesome', id: 'my-icon', class: 'strong', right: true)
def fa_icon(style, name, text = nil, html_options = {})
text, html_options = nil, text if text.is_a?(Hash)
content_class = "#{style} fa-#{name}"
content_class += " #{html_options[:class]}" if html_options.key?(:class)
html_options[:class] = content_class
icon = content_tag(:i, nil, html_options)
right_icon = html_options.delete(:right)
icon_join(icon, text, right_icon)
end
private
def icon_join(icon, text, reverse_order = false)
return icon if text.blank?
elements = [icon, ERB::Util.html_escape(text)]
elements.reverse! if reverse_order
safe_join(elements, ' ')
end