Class: Daisy::DataInput::CallyComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
ViewComponent::SlotableDefault
Defined in:
app/components/daisy/data_input/cally_component.rb

Overview

The Cally component provides a customizable calendar interface for date selection. It supports both single date and date range selection, with configurable display options including the number of months to show and navigation controls.

Defined Under Namespace

Classes: MonthComponent, NextIcon, PreviousIcon

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

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) ⇒ CallyComponent

Initializes a new CallyComponent.

The Cally component provides a customizable calendar interface for date selection. It supports single date selection by default and can be configured for date range selection. The component automatically handles navigation between months and can display multiple months.



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

def initialize(**kws)
  super

  # If we don't have any modifiers, assume we want a single month for a date select
  @month_count = config_option(:months, modifiers.blank? ? 1 : nil)
  @change = config_option(:change)
  @update = config_option(:update)

  @id = config_option(:id)
  @value = config_option(:value)
  @min = config_option(:min)
  @max = config_option(:max)
  @today = config_option(:today)
end

Instance Method Details

#before_renderObject

Configures the calendar component before rendering.

Sets up the appropriate tag name based on whether range selection is enabled, adds CSS classes, and configures HTML attributes for the calendar component.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/components/daisy/data_input/cally_component.rb', line 126

def before_render
  super

  if modifiers.include?(:range)
    set_tag_name(:component, "calendar-range")
  else
    set_tag_name(:component, "calendar-date")
  end

  add_css(:component, "cally")
  add_html(:component, { months: @month_count }) if @month_count

  add_html(:component, {
    id: @id,
    value: @value,
    min: @min,
    max: @max,
    today: @today
  })

  if @change
    add_html(:component, { onchange: "document.getElementById('#{@change}').value = this.value" })
  end

  if @update
    add_html(:component, { onchange: "document.getElementById('#{@update}').innerHTML = this.value" })
  end
end

#default_next_iconNextIcon

Provides a default next icon if none is specified.



177
178
179
# File 'app/components/daisy/data_input/cally_component.rb', line 177

def default_next_icon
  NextIcon.new(icon: "chevron-right")
end

#default_previous_iconPreviousIcon

Provides a default previous icon if none is specified.



170
171
172
# File 'app/components/daisy/data_input/cally_component.rb', line 170

def default_previous_icon
  PreviousIcon.new(icon: "chevron-left")
end

#month_options(index) ⇒ Hash

Generates options for a month component at the given index.



159
160
161
162
163
164
165
# File 'app/components/daisy/data_input/cally_component.rb', line 159

def month_options(index)
  options = {}

  options[:offset] = index if index > 0

  options
end