Class: Daisy::DataInput::TextAreaComponent

Inherits:
LocoMotion::BaseComponent show all
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

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.



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

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.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def cols
  @cols
end

#disabledObject (readonly)

Returns the value of attribute disabled.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def disabled
  @disabled
end

#idObject (readonly)

Returns the value of attribute id.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def name
  @name
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def placeholder
  @placeholder
end

#readonlyObject (readonly)

Returns the value of attribute readonly.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def readonly
  @readonly
end

#requiredObject (readonly)

Returns the value of attribute required.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def required
  @required
end

#rowsObject (readonly)

Returns the value of attribute rows.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def rows
  @rows
end

#valueObject (readonly)

Returns the value of attribute value.



44
45
46
# File 'app/components/daisy/data_input/text_area_component.rb', line 44

def value
  @value
end

Instance Method Details

#before_renderObject

Calls the #setup_component method before rendering the component.



89
90
91
# File 'app/components/daisy/data_input/text_area_component.rb', line 89

def before_render
  setup_component
end

#callObject

Renders the component with its value as content.



120
121
122
123
124
125
126
# File 'app/components/daisy/data_input/text_area_component.rb', line 120

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.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/components/daisy/data_input/text_area_component.rb', line 100

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