Class: Daisy::DataInput::CallyInputComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::LabelableComponent, ViewComponent::SlotableDefault
Defined in:
app/components/daisy/data_input/cally_input_component.rb

Overview

A specialized input component that combines a text input with a calendar picker. The calendar appears in a popover when the input is focused or clicked.

Defined Under Namespace

Classes: CallyCalendarComponent, CallyTextInputComponent

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 included from LocoMotion::Concerns::LabelableComponent

#has_any_label?, #has_floating_label?, #has_leading_label?, #has_trailing_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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

#initialize(**kws) ⇒ CallyInputComponent

Initializes a new CallyInputComponent.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • id (String)

    A unique identifier for the input. Defaults to an auto-generated UUID.

  • name (String)

    The name attribute for the input field.

  • value (Date, String)

    The initial value of the input. Defaults to nil.

  • auto_scroll_padding (Integer)

    The padding to use when scrolling the calendar into view. Defaults to 100.

  • css (String)

    Additional CSS classes for the component.

  • leading (String)

    Text to display in the leading label position (before the input). Forwarded to the nested text input.

  • trailing (String)

    Text to display in the trailing label position (after the input). Forwarded to the nested text input.

  • floating (String)

    Text to display in the floating label position. Forwarded to the nested text input.

  • placeholder (String)

    Placeholder text for the input. Forwarded to the nested text input.

  • floating_placeholder (String)

    Convenience option that sets both floating and placeholder to the same value. Forwarded to the nested text input.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/components/daisy/data_input/cally_input_component.rb', line 130

def initialize(**kws)
  super(**kws)

  @id = config_option(:id, SecureRandom.uuid)
  @name = config_option(:name)
  @value = config_option(:value)
  @auto_scroll_padding = config_option(:auto_scroll_padding, 100)

  # Input ID should match our ID
  @input_id = @id

  # Other IDs / options are generated
  @calendar_id = "#{@id}-calendar"
  @popover_id = "#{@id}-popover"
  @anchor = "#{@id}-anchor"
end

Instance Attribute Details

#anchorObject (readonly)

Returns the value of attribute anchor.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def anchor
  @anchor
end

#auto_scroll_paddingObject (readonly)

Returns the value of attribute auto_scroll_padding.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def auto_scroll_padding
  @auto_scroll_padding
end

#calendar_idObject (readonly)

Returns the value of attribute calendar_id.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def calendar_id
  @calendar_id
end

#idObject (readonly)

Returns the value of attribute id.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def id
  @id
end

#input_idObject (readonly)

Returns the value of attribute input_id.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def input_id
  @input_id
end

#nameObject (readonly)

Returns the value of attribute name.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def name
  @name
end

#popover_idObject (readonly)

Returns the value of attribute popover_id.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def popover_id
  @popover_id
end

#valueObject (readonly)

Returns the value of attribute value.



95
96
97
# File 'app/components/daisy/data_input/cally_input_component.rb', line 95

def value
  @value
end

Instance Method Details

#before_rendervoid

This method returns an undefined value.

Sets up the component before rendering. Calls the parent's before_render and then runs the component setup.



151
152
153
154
155
# File 'app/components/daisy/data_input/cally_input_component.rb', line 151

def before_render
  super

  setup_component
end

#default_calendarCallyCalendarComponent

Provides a default calendar component instance. This is used when no custom calendar component is provided.

Returns:



161
162
163
# File 'app/components/daisy/data_input/cally_input_component.rb', line 161

def default_calendar
  CallyCalendarComponent.new
end

#default_inputCallyTextInputComponent

Provides a default input component instance. This is used when no custom input component is provided.

Returns:



169
170
171
# File 'app/components/daisy/data_input/cally_input_component.rb', line 169

def default_input
  CallyTextInputComponent.new
end