Class: HakumiComponents::DatePicker::Component

Inherits:
BaseComponent
  • Object
show all
Extended by:
T::Sig
Includes:
Concerns::FormField, SharedRendering
Defined in:
app/components/hakumi_components/date_picker/component.rb

Constant Summary

Constants included from SharedRendering

SharedRendering::CalendarOptionValue, SharedRendering::DEFAULT_DATETIME_FORMAT, SharedRendering::DEFAULT_DATETIME_NO_SECONDS_FORMAT, SharedRendering::DEFAULT_DATE_FORMAT, SharedRendering::DateTimeLike, SharedRendering::PICKERS, SharedRendering::PlaceholderValue

Constants inherited from BaseComponent

BaseComponent::ControllerOptions, BaseComponent::DateInput, BaseComponent::DateLikeValue, BaseComponent::DimensionInput, BaseComponent::HtmlPayloadInput, BaseComponent::I18nOptionValue, BaseComponent::PresenceArray, BaseComponent::PresenceScalar, BaseComponent::PresenceValue, BaseComponent::RawHtmlInput, BaseComponent::SIZES, BaseComponent::SizeValue, BaseComponent::SymbolInput

Instance Method Summary collapse

Methods included from SharedRendering

#base_wrapper_classes, #calendar_component_options, #dayjs_to_strftime, #default_strftime_format, #display_format, #format_quarter, #formatted_value, #iso_value, #js_display_format, #parse_date, #parse_datetime, #picker_mode, #picker_panel_attributes, #placeholder_text, #range_placeholders, #show_seconds?, #use_12_hours?

Methods included from Concerns::FormField

#describedby_ids, #error?, #error_message, #form_field_caption, #form_field_contract, #form_field_errors, #form_field_html_options, #form_field_label, #form_field_name, #form_field_required, #form_field_rules, #form_field_standalone, #form_item_attributes, #form_item_classes, #input_id, #render_caption, #render_error, #render_explain, #render_label, #standalone?

Methods included from Concerns::FormFieldInterface

#form_field_contract

Methods inherited from BaseComponent

#append_data_token, boolean_html_param, #build_inline_style, cast_boolean, #cast_boolean, #class_names, #component_classes, #data_attributes_from, #dimension_to_css, #ensure_dom_id!, float_html_param, #generate_id, #html_classes, html_param, html_primitive_param, #html_style, #i18n_scope, integer_html_param, #merge_attributes, #render_value, #size_to_pixels, #stimulus_attrs, string_html_param, string_or_symbol_array_html_param, symbol_html_param, #t_default, #translate_with_default, #validate_inclusion!, #validate_required!, #value_present?

Constructor Details

#initialize(name: nil, label: nil, caption: nil, value: nil, default_value: nil, format: nil, display_format: nil, picker: :date, show_time: false, show_seconds: nil, disabled: false, disabled_date: nil, allow_clear: false, placeholder: nil, size: :default, bordered: true, required: false, errors: [], standalone: true, **html_options) ⇒ Component

Returns a new instance of Component.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/components/hakumi_components/date_picker/component.rb', line 36

def initialize(
  name: nil,
  label: nil,
  caption: nil,
  value: nil,
  default_value: nil,
  format: nil,
  display_format: nil,
  picker: :date,
  show_time: false,
  show_seconds: nil,
  disabled: false,
  disabled_date: nil,
  allow_clear: false,
  placeholder: nil,
  size: :default,
  bordered: true,
  required: false,
  errors: [],
  standalone: true,
  **html_options
)
  @name = T.let(name || generate_id("date_picker"), Types::FormFieldName)
  @label = label
  @caption = caption
  @value = value
  @default_value = default_value
  @format = format
  @display_format = display_format
  @picker = picker
  @show_time = show_time
  @show_seconds = T.let(show_seconds.nil? ? show_time : show_seconds, T::Boolean)
  @disabled = disabled
  @disabled_date = disabled_date
  @allow_clear = allow_clear
  @placeholder = placeholder
  @size = size
  @bordered = bordered
  @required = required
  @errors = T.let(errors, Types::FormFieldErrors)
  @standalone = standalone
  @html_options = T.let(html_options, Types::HtmlAttributes)
  initialize_form_field_contract!(
    name: @name,
    label: @label,
    caption: @caption,
    errors: @errors,
    standalone: @standalone,
    required: @required,
    html_options: @html_options
  )

  validate_props!
end

Instance Method Details

#date_picker_allow_clearObject



229
230
231
# File 'app/components/hakumi_components/date_picker/component.rb', line 229

def date_picker_allow_clear
  @allow_clear
end

#date_picker_borderedObject



219
220
221
# File 'app/components/hakumi_components/date_picker/component.rb', line 219

def date_picker_bordered
  @bordered
end

#date_picker_default_valueObject



239
240
241
# File 'app/components/hakumi_components/date_picker/component.rb', line 239

def date_picker_default_value
  @default_value
end

#date_picker_disabledObject



224
225
226
# File 'app/components/hakumi_components/date_picker/component.rb', line 224

def date_picker_disabled
  @disabled
end

#date_picker_disabled_dateObject



244
245
246
# File 'app/components/hakumi_components/date_picker/component.rb', line 244

def date_picker_disabled_date
  @disabled_date
end

#date_picker_display_formatObject



194
195
196
# File 'app/components/hakumi_components/date_picker/component.rb', line 194

def date_picker_display_format
  @display_format
end

#date_picker_formatObject



189
190
191
# File 'app/components/hakumi_components/date_picker/component.rb', line 189

def date_picker_format
  @format
end

#date_picker_pickerObject



199
200
201
# File 'app/components/hakumi_components/date_picker/component.rb', line 199

def date_picker_picker
  @picker
end

#date_picker_placeholderObject



249
250
251
# File 'app/components/hakumi_components/date_picker/component.rb', line 249

def date_picker_placeholder
  @placeholder
end

#date_picker_show_secondsObject



209
210
211
# File 'app/components/hakumi_components/date_picker/component.rb', line 209

def date_picker_show_seconds
  @show_seconds
end

#date_picker_show_timeObject



204
205
206
# File 'app/components/hakumi_components/date_picker/component.rb', line 204

def date_picker_show_time
  @show_time
end

#date_picker_sizeObject



214
215
216
# File 'app/components/hakumi_components/date_picker/component.rb', line 214

def date_picker_size
  @size
end

#date_picker_valueObject



234
235
236
# File 'app/components/hakumi_components/date_picker/component.rb', line 234

def date_picker_value
  @value
end

#display_valueObject



147
148
149
# File 'app/components/hakumi_components/date_picker/component.rb', line 147

def display_value
  formatted_value(@value || @default_value)
end

#hidden_input_attributesObject



110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/components/hakumi_components/date_picker/component.rb', line 110

def hidden_input_attributes
  {
    type: :hidden,
    name: form_field_name,
    id: input_id,
    value: iso_value(@value),
    disabled: @disabled ? true : nil,
    data: {
      "hakumi--date-picker-target": "hiddenInput"
    }
  }.compact
end

#input_attributesObject



142
143
144
# File 'app/components/hakumi_components/date_picker/component.rb', line 142

def input_attributes
  visible_input_attributes
end

#visible_input_attributesObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/components/hakumi_components/date_picker/component.rb', line 124

def visible_input_attributes
  {
    type: :text,
    value: display_value,
    placeholder: placeholder_text,
    class: "hakumi-date-picker-input-field",
    readonly: true,
    disabled: @disabled ? true : nil,
    "aria-invalid": error? ? "true" : nil,
    "aria-describedby": describedby_ids,
    data: {
      "hakumi--date-picker-target": "displayInput",
      action: "focus->hakumi--date-picker#focus blur->hakumi--date-picker#blur"
    }
  }.compact
end

#wrapper_attributesObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/components/hakumi_components/date_picker/component.rb', line 92

def wrapper_attributes
  base_attrs = {
    class: base_wrapper_classes(base: "date-picker", extra_classes: [ html_class_name ]),
    data: {
      controller: "hakumi--date-picker",
      hakumi__date_picker_allow_clear_value: @allow_clear,
      hakumi__date_picker_disabled_value: @disabled,
      hakumi__date_picker_picker_value: @picker.to_s,
      hakumi__date_picker_show_time_value: @show_time,
      hakumi__date_picker_show_seconds_value: @show_seconds,
      hakumi__date_picker_display_format_value: js_display_format
    }
  }

  merge_attributes(base_attrs, @html_options.except(:class))
end