Module: RailsPulse::IconHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/rails_pulse/icon_helper.rb

Instance Method Summary collapse

Instance Method Details

#rails_pulse_icon(name, options = {}) ⇒ Object Also known as: lucide_icon

Replacement for lucide_icon helper that works with pre-compiled assets Outputs a custom element that will be hydrated by Stimulus



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/rails_pulse/icon_helper.rb', line 5

def rails_pulse_icon(name, options = {})
  width = options[:width] || options["width"] || 24
  height = options[:height] || options["height"] || 24
  css_class = options[:class] || options["class"] || ""
  custom_style = options[:style] || options["style"]

  # Normalize numeric width/height values into px for layout stability
  width_css = normalize_dimension(width)
  height_css = normalize_dimension(height)

  default_style = [
    "display:inline-flex",
    "align-items:center",
    "justify-content:center",
    "width:#{width_css}",
    "height:#{height_css}",
    "flex-shrink:0"
  ].join(";")

  style_attribute = [ default_style, custom_style ].compact.join(";")

  # Additional HTML attributes
  attrs = options.except(:width, :height, :class, :style, "width", "height", "class", "style")

  ("rails-pulse-icon",
    "",
    data: {
      controller: "rails-pulse--icon",
      'rails-pulse--icon-name-value': name,
      'rails-pulse--icon-width-value': width,
      'rails-pulse--icon-height-value': height
    },
    class: css_class,
    style: style_attribute,
    **attrs
  )
end