Class: Fluxbit::Form::TextFieldComponent

Inherits:
FieldComponent
  • Object
show all
Includes:
Config::Form::TextFieldComponent
Defined in:
app/components/fluxbit/form/text_field_component.rb

Overview

The Fluxbit::Form::TextFieldComponent is a form input component that extends Fluxbit::Form::FieldComponent. It provides a styled text input (or textarea) with support for various HTML input types, optional icons or add-on content, and color-coded validation states (e.g. default, success, error).

Examples:

Basic usage

= render Fluxbit::Form::TextFieldComponent.new(name: :email)

See Also:

  • For detailed documentation and examples.

Constant Summary collapse

TYPE_DEFAULT =
:text
TYPE_OPTIONS =
i[text textarea text_area color number email password search tel url date datetime_local month time week currency]

Instance Method Summary collapse

Constructor Details

#initialize(**props) ⇒ TextFieldComponent

Initializes the text field component with the given properties.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/components/fluxbit/form/text_field_component.rb', line 43

def initialize(**props)
  super(**props)
  @color = valid_color(@props.delete(:color))
  @type = options(@props.delete(:type), collection: TYPE_OPTIONS, default: TYPE_DEFAULT)
  @icon = @props.delete(:icon)
  @multiline = options(@props.delete(:multiline), default: false)
  @shadow = @props.delete(:shadow)
  @addon = @props.delete(:addon)
  @right_icon = @props.delete(:right_icon)
  @addon_html = @props.delete(:addon_html) || {}
  @div_html = @props.delete(:div_html) || {}
  @icon_html = @props.delete(:icon_html) || {}
  @right_icon_html = @props.delete(:right_icon_html) || {}
  @sizing = sizing_with_addon @props.delete(:sizing)
  @props[:type] = @type

  define_placeholder(@props.delete(:placeholder))
  declare_classes
  @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
end

Instance Method Details

#callObject



64
65
66
67
68
# File 'app/components/fluxbit/form/text_field_component.rb', line 64

def call
   :div, **@wrapper_html do
    safe_join [ label, icon_container, help_text ]
  end
end