Class: BulmaPhlex::FormControl

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

Overview

Wraps form elements in a [Bulma form control](bulma.io/documentation/form/general/#form-control) container. Supports optional icons on the left and/or right side of the control.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(icon_left: nil, icon_right: nil, **html_attributes) ⇒ FormControl

Returns a new instance of FormControl.



16
17
18
19
20
# File 'lib/bulma_phlex/form_control.rb', line 16

def initialize(icon_left: nil, icon_right: nil, **html_attributes)
  @icon_left = icon_left
  @icon_right = icon_right
  @html_attributes = html_attributes
end

Class Method Details

.new(icon_left: nil, icon_right: nil, **html_attributes) ⇒ Object

Parameters

  • ‘icon_left` — Icon class for the left side of the control (e.g. `“fas fa-check”`)

  • ‘icon_right` — Icon class for the right side of the control (e.g. `“fas fa-check”`)

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



12
13
14
# File 'lib/bulma_phlex/form_control.rb', line 12

def self.new(icon_left: nil, icon_right: nil, **html_attributes)
  super
end

Instance Method Details

#view_templateObject



22
23
24
25
26
27
28
# File 'lib/bulma_phlex/form_control.rb', line 22

def view_template(&)
  div(**mix({ class: classes }, @html_attributes)) do
    raw yield
    Icon(@icon_left, size: :small, left: true) if @icon_left
    Icon(@icon_right, size: :small, right: true) if @icon_right
  end
end