Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for icon on right of text for helper #61

Open
jwoertink opened this issue Nov 25, 2014 · 5 comments
Open

Support for icon on right of text for helper #61

jwoertink opened this issue Nov 25, 2014 · 5 comments

Comments

@jwoertink
Copy link

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>
@rhnorment
Copy link

bump

@kobaltz
Copy link

kobaltz commented Apr 20, 2015

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' %>

@andreykul
Copy link

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>

@kampeynco
Copy link

I'm assuming there's been no resolution to this issue?

@CapDev
Copy link

CapDev commented Apr 27, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants