Class: UI::FieldComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
FieldBehavior
Defined in:
app/view_components/ui/field_component.rb

Overview

FieldComponent - ViewComponent implementation

Core wrapper for a single form field with support for different orientations. Uses FieldBehavior concern for shared styling logic.

Examples:

Basic usage

<%= render UI::FieldComponent.new do %>
  Field content here
<% end %>

With orientation

<%= render UI::FieldComponent.new(orientation: "horizontal") do %>
  Field content
<% end %>

With validation state

<%= render UI::FieldComponent.new(data_invalid: true) do %>
  Field content
<% end %>

Instance Method Summary collapse

Methods included from FieldBehavior

#field_classes, #field_html_attributes

Constructor Details

#initialize(orientation: "vertical", data_invalid: nil, classes: "", **attributes) ⇒ FieldComponent

Returns a new instance of FieldComponent.

Parameters:

  • orientation (String) (defaults to: "vertical")

    Layout orientation: “vertical”, “horizontal”, or “responsive”

  • data_invalid (Boolean) (defaults to: nil)

    Whether field is in invalid state

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



29
30
31
32
33
34
# File 'app/view_components/ui/field_component.rb', line 29

def initialize(orientation: "vertical", data_invalid: nil, classes: "", **attributes)
  @orientation = orientation
  @data_invalid = data_invalid
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



36
37
38
39
40
# File 'app/view_components/ui/field_component.rb', line 36

def call
   :div, **field_html_attributes do
    content
  end
end