Class: UI::Field

Inherits:
Phlex::HTML
  • Object
show all
Includes:
FieldBehavior
Defined in:
app/components/ui/field.rb

Overview

Field - Phlex 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::Field.new { "Field content here" }

With orientation

render UI::Field.new(orientation: "horizontal") { "Field content" }

With validation state

render UI::Field.new(data_invalid: true) { "Field content" }

Instance Method Summary collapse

Methods included from FieldBehavior

#field_classes, #field_html_attributes

Constructor Details

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

Returns a new instance of Field.

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



23
24
25
26
27
28
# File 'app/components/ui/field.rb', line 23

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

Instance Method Details

#view_template(&block) ⇒ Object



30
31
32
33
34
# File 'app/components/ui/field.rb', line 30

def view_template(&block)
  div(**field_html_attributes) do
    yield if block_given?
  end
end