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_end_label?, #has_floating_label?, #has_start_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

Constructor Details

#initialize(**kws) ⇒ CallyInputComponent

Initializes a new CallyInputComponent.

Parameters:

  • kws (Hash)

    The options hash

Options Hash (**kws):

  • :id (String)

    A unique identifier for the input (default: auto-generated)

  • :name (String)

    The name attribute for the input field

  • :value (Date, String)

    The initial value of the input (default: nil)

  • :auto_scroll_padding (Integer)

    The padding to use when scrolling the calendar into view (default: 100)

  • :css (String)

    Additional CSS classes for the component



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

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.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

def anchor
  @anchor
end

#auto_scroll_paddingObject (readonly)

Returns the value of attribute auto_scroll_padding.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

def auto_scroll_padding
  @auto_scroll_padding
end

#calendar_idObject (readonly)

Returns the value of attribute calendar_id.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

def calendar_id
  @calendar_id
end

#idObject (readonly)

Returns the value of attribute id.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

def id
  @id
end

#input_idObject (readonly)

Returns the value of attribute input_id.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

def input_id
  @input_id
end

#nameObject (readonly)

Returns the value of attribute name.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

def name
  @name
end

#popover_idObject (readonly)

Returns the value of attribute popover_id.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

def popover_id
  @popover_id
end

#valueObject (readonly)

Returns the value of attribute value.



92
93
94
# File 'app/components/daisy/data_input/cally_input_component.rb', line 92

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.



123
124
125
126
127
# File 'app/components/daisy/data_input/cally_input_component.rb', line 123

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:



133
134
135
# File 'app/components/daisy/data_input/cally_input_component.rb', line 133

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:



141
142
143
# File 'app/components/daisy/data_input/cally_input_component.rb', line 141

def default_input
  CallyTextInputComponent.new
end