Class: BulmaPhlex::Icon

Inherits:
Base
  • Object
show all
Defined in:
lib/bulma_phlex/icon.rb

Overview

Renders a [Bulma icon element](bulma.io/documentation/elements/icon/) with optional text and form control positioning.

Supports color and size options, optional text to the left or right of the icon, and positioning helpers (‘left`/`right`) for use inside form controls.

## Example

render BulmaPhlex::Icon.new("fas fa-home")
render BulmaPhlex::Icon.new("fas fa-home", color: :primary, size: :large, text_right: "Home")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(icon, text_right: nil, text_left: nil, size: nil, color: nil, left: false, right: false, **html_attributes) ⇒ Icon

Returns a new instance of Icon.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bulma_phlex/icon.rb', line 36

def initialize(icon,
               text_right: nil,
               text_left: nil,
               size: nil,
               color: nil,
               left: false,
               right: false,
               **html_attributes)
  @icon = icon
  @text_right = text_right
  @text_left = text_left
  @size = size
  @color = color
  @left = left
  @right = right
  @html_attributes = html_attributes
end

Class Method Details

.new(icon, text_right: nil, text_left: nil, size: nil, color: nil, left: false, right: false, **html_attributes) ⇒ Object

Parameters

  • ‘icon` — The icon class string (e.g. `“fas fa-home”`)

  • ‘color` — Sets the [color of the icon](bulma.io/documentation/elements/icon/#colors)

  • ‘size` — Sets the [size of the icon](bulma.io/documentation/elements/icon/#sizes)

  • ‘text_right` — Text to display to the right of the icon

  • ‘text_left` — Text to display to the left of the icon

  • ‘left` — If `true`, adds the `is-left` class for use in form controls

  • ‘right` — If `true`, adds the `is-right` class for use in form controls

  • ‘**html_attributes` — Additional HTML attributes for the icon span element



25
26
27
28
29
30
31
32
33
34
# File 'lib/bulma_phlex/icon.rb', line 25

def self.new(icon,
             text_right: nil,
             text_left: nil,
             size: nil,
             color: nil,
             left: false,
             right: false,
             **html_attributes)
  super
end

Instance Method Details

#view_templateObject



54
55
56
57
58
59
60
61
62
# File 'lib/bulma_phlex/icon.rb', line 54

def view_template
  optional_text_wrapper do
    span { @text_left } if @text_left
    span(**mix({ class: icon_classes }, @html_attributes)) do
      i(class: @icon)
    end
    span { @text_right } if @text_right
  end
end