Class: Daisy::DataInput::TextInputComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataInput::TextInputComponent
- Includes:
- LocoMotion::Concerns::LabelableComponent
- Defined in:
- app/components/daisy/data_input/text_input_component.rb
Overview
Input fields have a border by default and a width of 20rem. Use ‘input-ghost` to remove the border.
The TextInput component renders a DaisyUI styled text input field. It can be used standalone or with a form builder, and supports various styling options including different types, sizes and variants.
Direct Known Subclasses
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#readonly ⇒ Object
readonly
Returns the value of attribute readonly.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
-
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
-
#initialize(**kws) ⇒ TextInputComponent
constructor
Instantiate a new TextInput component.
-
#setup_component ⇒ Object
Sets up the component by configuring the tag name, CSS classes, and HTML attributes.
Methods included from LocoMotion::Concerns::LabelableComponent
#has_any_label?, #has_end_label?, #has_floating_label?, #has_start_label?
Methods inherited from LocoMotion::BaseComponent
build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces
Constructor Details
#initialize(**kws) ⇒ TextInputComponent
Instantiate a new TextInput component.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 88 def initialize(**kws) super @name = config_option(:name) @id = config_option(:id) @value = config_option(:value, nil) @type = config_option(:type, "text") @disabled = config_option(:disabled, false) @required = config_option(:required, false) @readonly = config_option(:readonly, false) @change = config_option(:change) end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
63 64 65 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 63 def disabled @disabled end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
63 64 65 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 63 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
63 64 65 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 63 def name @name end |
#readonly ⇒ Object (readonly)
Returns the value of attribute readonly.
63 64 65 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 63 def readonly @readonly end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
63 64 65 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 63 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
63 64 65 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 63 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
63 64 65 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 63 def value @value end |
Instance Method Details
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
104 105 106 107 108 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 104 def before_render super setup_component end |
#setup_component ⇒ Object
Sets up the component by configuring the tag name, CSS classes, and HTML attributes. Sets the tag to input with appropriate type and adds the ‘input’ CSS class.
This configures various attributes of the text input including name, id, value, placeholder, type, and states like disabled, required, and readonly.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/components/daisy/data_input/text_input_component.rb', line 118 def setup_component set_tag_name(:component, :input) if has_floating_label? add_css(:label_wrapper, "floating-label input") elsif has_start_label? || has_end_label? add_css(:label_wrapper, "input") else add_css(:component, "input") end add_html(:component, { type: @type, name: @name, id: @id, value: @value, placeholder: @placeholder, disabled: @disabled, required: @required, readonly: @readonly }) add_html(:component, { onchange: "document.getElementById('#{@change}').value = this.value" }) if @change end |