Class: HakumiComponents::DatePicker::RangePicker
Constant Summary
collapse
- PlaceholderInput =
T.type_alias { T.nilable(T.any(String, T::Array[String])) }
- InputId =
T.type_alias { Types::HtmlKey }
SharedRendering::CalendarOptionValue, SharedRendering::DEFAULT_DATETIME_FORMAT, SharedRendering::DEFAULT_DATETIME_NO_SECONDS_FORMAT, SharedRendering::DEFAULT_DATE_FORMAT, SharedRendering::DateTimeLike, SharedRendering::PICKERS, SharedRendering::PlaceholderValue
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
-
#date_picker_allow_clear ⇒ Object
-
#date_picker_bordered ⇒ Object
-
#date_picker_default_value ⇒ Object
-
#date_picker_disabled ⇒ Object
-
#date_picker_disabled_date ⇒ Object
-
#date_picker_display_format ⇒ Object
-
#date_picker_format ⇒ Object
-
#date_picker_picker ⇒ Object
-
#date_picker_placeholder ⇒ Object
-
#date_picker_show_seconds ⇒ Object
-
#date_picker_show_time ⇒ Object
-
#date_picker_size ⇒ Object
-
#date_picker_value ⇒ Object
-
#display_values ⇒ Object
-
#end_input_attributes ⇒ Object
-
#end_input_id ⇒ Object
-
#end_input_name ⇒ Object
-
#initialize(name: nil, label: nil, caption: nil, start_value: nil, end_value: nil, default_value: nil, format: nil, picker: :date, show_time: false, disabled: false, disabled_date: nil, allow_clear: false, placeholder: nil, size: :default, bordered: true, required: false, errors: [], standalone: true, **html_options) ⇒ RangePicker
constructor
A new instance of RangePicker.
-
#start_input_attributes ⇒ Object
-
#start_input_id ⇒ Object
-
#start_input_name ⇒ Object
-
#wrapper_attributes ⇒ Object
#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?
#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?
#form_field_contract
#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, start_value: nil, end_value: nil, default_value: nil, format: nil, picker: :date, show_time: false, disabled: false, disabled_date: nil, allow_clear: false, placeholder: nil, size: :default, bordered: true, required: false, errors: [], standalone: true, **html_options) ⇒ RangePicker
Returns a new instance of RangePicker.
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
90
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 38
def initialize(
name: nil,
label: nil,
caption: nil,
start_value: nil,
end_value: nil,
default_value: nil,
format: nil,
picker: :date,
show_time: false,
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("range_picker"), Types::FormFieldName)
@label = T.let(label, T.nilable(String))
@caption = T.let(caption, T.nilable(String))
@start_value = T.let(start_value, Types::FormFieldScalar)
@end_value = T.let(end_value, Types::FormFieldScalar)
@value = T.let(@start_value || @end_value, Types::FormFieldValue)
@default_value = T.let(default_value, Types::FormFieldValue)
@format = T.let(format, T.nilable(String))
@picker = T.let(picker, Symbol)
@show_time = T.let(show_time, T::Boolean)
@disabled = T.let(disabled, T::Boolean)
@disabled_date = T.let(disabled_date, T.nilable(Proc))
@allow_clear = T.let(allow_clear, T::Boolean)
@placeholder = T.let(placeholder, PlaceholderInput)
@size = T.let(size, Symbol)
@bordered = T.let(bordered, T::Boolean)
@required = T.let(required, T::Boolean)
@errors = T.let(errors, Types::FormFieldErrors)
@standalone = T.let(standalone, T::Boolean)
@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_clear ⇒ Object
242
243
244
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 242
def date_picker_allow_clear
@allow_clear
end
|
#date_picker_bordered ⇒ Object
232
233
234
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 232
def date_picker_bordered
@bordered
end
|
#date_picker_default_value ⇒ Object
252
253
254
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 252
def date_picker_default_value
@default_value
end
|
#date_picker_disabled ⇒ Object
237
238
239
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 237
def date_picker_disabled
@disabled
end
|
#date_picker_disabled_date ⇒ Object
257
258
259
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 257
def date_picker_disabled_date
@disabled_date
end
|
207
208
209
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 207
def date_picker_display_format
nil
end
|
202
203
204
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 202
def date_picker_format
@format
end
|
#date_picker_picker ⇒ Object
212
213
214
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 212
def date_picker_picker
@picker
end
|
#date_picker_placeholder ⇒ Object
262
263
264
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 262
def date_picker_placeholder
@placeholder
end
|
#date_picker_show_seconds ⇒ Object
222
223
224
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 222
def date_picker_show_seconds
@show_time
end
|
#date_picker_show_time ⇒ Object
217
218
219
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 217
def date_picker_show_time
@show_time
end
|
#date_picker_size ⇒ Object
227
228
229
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 227
def date_picker_size
@size
end
|
#date_picker_value ⇒ Object
247
248
249
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 247
def date_picker_value
@value
end
|
#display_values ⇒ Object
176
177
178
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 176
def display_values
[ formatted_value(@start_value), formatted_value(@end_value) ]
end
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 130
def end_input_attributes
{
type: :text,
name: end_input_name,
id: end_input_id,
value: formatted_value(@end_value),
placeholder: range_placeholders[1],
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": "endInput",
action: "click->hakumi--date-picker#activateEnd"
}
}.compact
end
|
168
169
170
171
172
173
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 168
def end_input_id
custom_id = @html_options[:end_id]
return custom_id if custom_id.is_a?(String) || custom_id.is_a?(Symbol)
"#{@name}_end"
end
|
155
156
157
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 155
def end_input_name
"#{@name}_end"
end
|
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 110
def start_input_attributes
{
type: :text,
name: start_input_name,
id: start_input_id,
value: formatted_value(@start_value),
placeholder: range_placeholders[0],
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": "startInput",
action: "click->hakumi--date-picker#activateStart"
}
}.compact
end
|
160
161
162
163
164
165
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 160
def start_input_id
custom_id = @html_options[:start_id]
return custom_id if custom_id.is_a?(String) || custom_id.is_a?(Symbol)
"#{@name}_start"
end
|
150
151
152
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 150
def start_input_name
"#{@name}_start"
end
|
#wrapper_attributes ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/components/hakumi_components/date_picker/range_picker.rb', line 93
def wrapper_attributes
base_attrs = {
class: base_wrapper_classes(base: "date-picker", extra_classes: range_picker_classes),
data: {
controller: "hakumi--date-picker",
hakumi__date_picker_allow_clear_value: @allow_clear,
hakumi__date_picker_disabled_value: @disabled,
hakumi__date_picker_format_value: display_format,
hakumi__date_picker_picker_value: @picker.to_s,
hakumi__date_picker_range_value: "true"
}
}
merge_attributes(base_attrs, @html_options.except(:class))
end
|