Class: Daisy::DataInput::TextAreaComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::AriableComponent
Defined in:
app/components/daisy/data_input/text_area_component.rb

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary collapse

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(**kws) ⇒ TextAreaComponent

Instantiate a new TextArea component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • name (String)

    The name attribute for the textarea.

  • id (String)

    The ID attribute for the textarea.

  • value (String)

    The initial value of the textarea.

  • placeholder (String)

    Placeholder text for the textarea.

  • rows (Integer)

    The number of visible text lines. Defaults to 4.

  • cols (Integer)

    The visible width of the textarea. Defaults to nil.

  • disabled (Boolean)

    Whether the textarea is disabled. Defaults to false.

  • required (Boolean)

    Whether the textarea is required for form validation. Defaults to false.

  • readonly (Boolean)

    Whether the textarea is read-only. Defaults to false.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/components/daisy/data_input/text_area_component.rb', line 76

def initialize(**kws)
  super

  @name = config_option(:name)
  @id = config_option(:id)
  @value = config_option(:value, nil)
  @placeholder = config_option(:placeholder, nil)
  @rows = config_option(:rows, 4)
  @cols = config_option(:cols, nil)
  @disabled = config_option(:disabled, false)
  @required = config_option(:required, false)
  @readonly = config_option(:readonly, false)
end

Instance Attribute Details

#colsObject (readonly)

Returns the value of attribute cols.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def cols
  @cols
end

#disabledObject (readonly)

Returns the value of attribute disabled.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def disabled
  @disabled
end

#idObject (readonly)

Returns the value of attribute id.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def placeholder
  @placeholder
end

#readonlyObject (readonly)

Returns the value of attribute readonly.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def readonly
  @readonly
end

#requiredObject (readonly)

Returns the value of attribute required.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def required
  @required
end

#rowsObject (readonly)

Returns the value of attribute rows.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def rows
  @rows
end

#valueObject (readonly)

Returns the value of attribute value.



48
49
50
# File 'app/components/daisy/data_input/text_area_component.rb', line 48

def value
  @value
end

Instance Method Details

#before_renderObject

Calls the #setup_component method before rendering the component.



93
94
95
96
97
# File 'app/components/daisy/data_input/text_area_component.rb', line 93

def before_render
  super

  setup_component
end

#callObject

Renders the component with its value as content.



126
127
128
129
130
131
132
# File 'app/components/daisy/data_input/text_area_component.rb', line 126

def call
  if @value
    part(:component) { @value }
  else
    part(:component)
  end
end

#setup_componentObject

Sets up the component by configuring the tag name, CSS classes, and HTML attributes. Sets the tag to textarea and adds the ‘textarea’ CSS class.

This configures various attributes of the textarea including name, id, value, placeholder, rows, cols, and states like disabled, required, and readonly.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/components/daisy/data_input/text_area_component.rb', line 106

def setup_component
  set_tag_name(:component, :textarea)

  add_css(:component, "textarea")

  add_html(:component, {
             name: @name,
             id: @id,
             placeholder: @placeholder,
             rows: @rows,
             cols: @cols,
             disabled: @disabled,
             required: @required,
             readonly: @readonly
           })
end