Class: FieldComponent

Inherits:
Component show all
Defined in:
app/components/field_component.rb

Overview

Field — Fomantic UI field wrapper.

Renders <div class=“… field”> for use inside forms.

Usage:

Field {
  Input(icon: "user", icon_position: "left") {
    TextField(:email, placeholder: "E-mail address")
  }
}

Field(required: true, label: "Email") {
  TextField(:email, placeholder: "you@example.com")
}

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/field_component.rb', line 28

def to_s
  classes = class_names(
    width,
    { "required" => required, "disabled" => disabled,
      "error" => error, "warning" => warning, "inline" => inline },
    "field"
  )

  label_el = label ? tag.label(label) : nil

  tag.div(**merge_html_options(class: classes)) {
    safe_join([ label_el, @content ].compact)
  }
end