Module: LocoMotion::Concerns::IconableComponent

Overview

The IconableComponent concern provides functionality for components that display icons. It supports both left and right icons and allows for customization of their CSS classes and HTML attributes.

Instance Method Summary collapse

Instance Method Details

#has_icons?Boolean

Determines if any icons are present in the component.

Returns:

  • (Boolean)

    true if any icons are configured, false otherwise



106
107
108
# File 'lib/loco_motion/concerns/iconable_component.rb', line 106

def has_icons?
  @left_icon.present? || @right_icon.present?
end

#left_icon_htmlHash

Returns the HTML attributes for the left icon.

Returns:

  • (Hash)

    HTML attributes for the left icon



88
89
90
# File 'lib/loco_motion/concerns/iconable_component.rb', line 88

def left_icon_html
  { class: @left_icon_css }.merge(@left_icon_html)
end

#render_left_iconString Also known as: render_icon

Renders the left icon as a Hero::IconComponent instance.

Returns:

  • (String)

    The rendered HTML for the icon



115
116
117
118
119
# File 'lib/loco_motion/concerns/iconable_component.rb', line 115

def render_left_icon
  return unless @left_icon.present?

  hero_icon(@left_icon, css: @left_icon_css, html: @left_icon_html, **@left_icon_options)
end

#render_right_iconString

Renders the right icon using a hero icon.

Returns:

  • (String)

    The rendered HTML for the icon



127
128
129
130
131
# File 'lib/loco_motion/concerns/iconable_component.rb', line 127

def render_right_icon
  return unless @right_icon.present?

  hero_icon(@right_icon, css: @right_icon_css, html: @right_icon_html, **@right_icon_options)
end

#right_icon_htmlHash

Returns the HTML attributes for the right icon.

Returns:

  • (Hash)

    HTML attributes for the right icon



97
98
99
# File 'lib/loco_motion/concerns/iconable_component.rb', line 97

def right_icon_html
  { class: @right_icon_css }.merge(@right_icon_html)
end