Class: Daisy::DataInput::RangeComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::AriableComponent
Defined in:
app/components/daisy/data_input/range_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) ⇒ RangeComponent

Instantiate a new Range component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • name (String)

    The name attribute for the range input.

  • id (String)

    The ID attribute for the range input.

  • min (Integer)

    The minimum value (default: 0).

  • max (Integer)

    The maximum value (default: 100).

  • step (Integer)

    The step increment (default: 1).

  • value (Integer)

    The current value (default: min).

  • disabled (Boolean)

    Whether the range input is disabled. Defaults to false.

  • required (Boolean)

    Whether the range input is required for form validation. Defaults to false.



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/components/daisy/data_input/range_component.rb', line 48

def initialize(**kws)
  super

  @name = config_option(:name)
  @id = config_option(:id)
  @min = config_option(:min, 0)
  @max = config_option(:max, 100)
  @step = config_option(:step, 1)
  @value = config_option(:value, @min)
  @disabled = config_option(:disabled, false)
  @required = config_option(:required, false)
end

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def disabled
  @disabled
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def id
  @id
end

#maxObject (readonly)

Returns the value of attribute max.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def min
  @min
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def required
  @required
end

#stepObject (readonly)

Returns the value of attribute step.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def step
  @step
end

#valueObject (readonly)

Returns the value of attribute value.



23
24
25
# File 'app/components/daisy/data_input/range_component.rb', line 23

def value
  @value
end

Instance Method Details

#before_renderObject

Calls the #setup_component method before rendering the component.



64
65
66
67
68
# File 'app/components/daisy/data_input/range_component.rb', line 64

def before_render
  super

  setup_component
end

#callObject

Renders the component inline with no additional whitespace.



98
99
100
# File 'app/components/daisy/data_input/range_component.rb', line 98

def call
  part(:component)
end

#setup_componentObject

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

This configures the min, max, step values along with name, id, value, disabled state, and required state of the range input.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/components/daisy/data_input/range_component.rb', line 77

def setup_component
  set_tag_name(:component, :input)

  add_css(:component, "range")

  add_html(:component, {
             type: "range",
             name: @name,
             id: @id,
             min: @min,
             max: @max,
             step: @step,
             value: @value,
             disabled: @disabled,
             required: @required
           })
end