Class: Daisy::DataInput::TextAreaComponent

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

Overview

Note:

Text areas have a border by default. Use textarea-ghost to remove the border.

The TextArea component renders a DaisyUI styled textarea field. It can be used standalone or with a form builder, and supports various styling options and states.

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.



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

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.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def cols
  @cols
end

#disabledObject (readonly)

Returns the value of attribute disabled.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def disabled
  @disabled
end

#idObject (readonly)

Returns the value of attribute id.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def placeholder
  @placeholder
end

#readonlyObject (readonly)

Returns the value of attribute readonly.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def readonly
  @readonly
end

#requiredObject (readonly)

Returns the value of attribute required.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def required
  @required
end

#rowsObject (readonly)

Returns the value of attribute rows.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def rows
  @rows
end

#valueObject (readonly)

Returns the value of attribute value.



46
47
48
# File 'app/components/daisy/data_input/text_area_component.rb', line 46

def value
  @value
end

Instance Method Details

#before_renderObject

Calls the #setup_component method before rendering the component.



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

def before_render
  super

  setup_component
end

#callObject

Renders the component with its value as content.



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

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.



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

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