Class: HotwireCombobox::Component
- Inherits:
-
Object
- Object
- HotwireCombobox::Component
- Includes:
- ActiveModel::Validations, Customizable
- Defined in:
- app/presenters/hotwire_combobox/component.rb
Defined Under Namespace
Modules: Customizable
Constant Summary
Constants included from Customizable
Customizable::CUSTOMIZABLE_ELEMENTS, Customizable::PROTECTED_ATTRS
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #announcer_attrs ⇒ Object
- #dialog_attrs ⇒ Object
- #dialog_focus_trap_attrs ⇒ Object
- #dialog_input_attrs ⇒ Object
- #dialog_label ⇒ Object
- #dialog_label_attrs ⇒ Object
- #dialog_listbox_attrs ⇒ Object
- #dialog_wrapper_attrs ⇒ Object
- #fieldset_attrs ⇒ Object
- #handle_attrs ⇒ Object
- #hidden_field_attrs ⇒ Object
-
#initialize(view, name, association_name: nil, async_src: nil, autocomplete: :both, data: {}, dialog_label: nil, form: nil, free_text: false, id: nil, input: {}, label: nil, mobile_at: "640px", multiselect_chip_src: nil, name_when_new: nil, open: false, options: [], value: nil, **rest) ⇒ Component
constructor
A new instance of Component.
- #input_attrs ⇒ Object
- #label_attrs ⇒ Object
- #listbox_attrs ⇒ Object
- #main_wrapper_attrs ⇒ Object
- #paginated? ⇒ Boolean
- #pagination_attrs ⇒ Object
- #render_in(view_context, &block) ⇒ Object
Constructor Details
#initialize(view, name, association_name: nil, async_src: nil, autocomplete: :both, data: {}, dialog_label: nil, form: nil, free_text: false, id: nil, input: {}, label: nil, mobile_at: "640px", multiselect_chip_src: nil, name_when_new: nil, open: false, options: [], value: nil, **rest) ⇒ Component
Returns a new instance of Component.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/presenters/hotwire_combobox/component.rb', line 11 def initialize \ view, name, association_name: nil, async_src: nil, autocomplete: :both, data: {}, dialog_label: nil, form: nil, free_text: false, id: nil, input: {}, label: nil, mobile_at: "640px", multiselect_chip_src: nil, name_when_new: nil, open: false, options: [], value: nil, **rest @view, @autocomplete, @id, @name, @value, @form, @async_src, @label, @free_text, @name_when_new, @open, @data, @mobile_at, @multiselect_chip_src, @options, @dialog_label = view, autocomplete, id, name.to_s, value, form, async_src, label, free_text, name_when_new, open, data, mobile_at, multiselect_chip_src, , dialog_label @combobox_attrs = input.reverse_merge(rest).deep_symbolize_keys @association_name = association_name || infer_association_name validate! end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'app/presenters/hotwire_combobox/component.rb', line 7 def label @label end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'app/presenters/hotwire_combobox/component.rb', line 7 def @options end |
Instance Method Details
#announcer_attrs ⇒ Object
82 83 84 85 86 87 88 |
# File 'app/presenters/hotwire_combobox/component.rb', line 82 def announcer_attrs { class: "hw-combobox__announcer", aria: announcer_aria, data: announcer_data } end |
#dialog_attrs ⇒ Object
134 135 136 137 138 139 140 |
# File 'app/presenters/hotwire_combobox/component.rb', line 134 def dialog_attrs apply_customizations_to :dialog, base: { class: "hw-combobox__dialog", role: :dialog, data: dialog_data } end |
#dialog_focus_trap_attrs ⇒ Object
175 176 177 178 179 180 |
# File 'app/presenters/hotwire_combobox/component.rb', line 175 def dialog_focus_trap_attrs { tabindex: "-1", data: dialog_focus_trap_data } end |
#dialog_input_attrs ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'app/presenters/hotwire_combobox/component.rb', line 153 def dialog_input_attrs apply_customizations_to :dialog_input, base: { id: dialog_input_id, role: :combobox, class: "hw-combobox__dialog__input", autofocus: "", type: input_type, data: dialog_input_data, aria: dialog_input_aria } end |
#dialog_label ⇒ Object
142 143 144 |
# File 'app/presenters/hotwire_combobox/component.rb', line 142 def dialog_label @dialog_label || label end |
#dialog_label_attrs ⇒ Object
146 147 148 149 150 151 |
# File 'app/presenters/hotwire_combobox/component.rb', line 146 def dialog_label_attrs apply_customizations_to :dialog_label, base: { class: "hw-combobox__dialog__label", for: dialog_input_id } end |
#dialog_listbox_attrs ⇒ Object
165 166 167 168 169 170 171 172 173 |
# File 'app/presenters/hotwire_combobox/component.rb', line 165 def dialog_listbox_attrs apply_customizations_to :dialog_listbox, base: { id: dialog_listbox_id, class: "hw-combobox__dialog__listbox", role: :listbox, data: dialog_listbox_data, aria: dialog_listbox_aria } end |
#dialog_wrapper_attrs ⇒ Object
128 129 130 131 132 |
# File 'app/presenters/hotwire_combobox/component.rb', line 128 def dialog_wrapper_attrs apply_customizations_to :dialog_wrapper, base: { class: "hw-combobox__dialog__wrapper" } end |
#fieldset_attrs ⇒ Object
47 48 49 50 51 52 |
# File 'app/presenters/hotwire_combobox/component.rb', line 47 def fieldset_attrs apply_customizations_to :fieldset, base: { class: [ "hw-combobox", { "hw-combobox--multiple": multiselect? } ], data: fieldset_data } end |
#handle_attrs ⇒ Object
108 109 110 111 112 113 |
# File 'app/presenters/hotwire_combobox/component.rb', line 108 def handle_attrs apply_customizations_to :handle, base: { class: "hw-combobox__handle", data: handle_data } end |
#hidden_field_attrs ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'app/presenters/hotwire_combobox/component.rb', line 64 def hidden_field_attrs apply_customizations_to :hidden_field, base: { id: hidden_field_id, name: hidden_field_name, data: hidden_field_data, value: hidden_field_value } end |
#input_attrs ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/presenters/hotwire_combobox/component.rb', line 91 def input_attrs nested_attrs = %i[ data aria ] base = { id: input_id, role: :combobox, class: "hw-combobox__input", type: input_type, data: input_data, aria: input_aria, autocomplete: :off }.merge combobox_attrs.except(*nested_attrs) apply_customizations_to :input, base: base end |
#label_attrs ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/presenters/hotwire_combobox/component.rb', line 55 def label_attrs apply_customizations_to :label, base: { class: "hw-combobox__label", for: input_id, hidden: label.blank? } end |
#listbox_attrs ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'app/presenters/hotwire_combobox/component.rb', line 116 def listbox_attrs apply_customizations_to :listbox, base: { id: listbox_id, role: :listbox, class: "hw-combobox__listbox", hidden: "", data: listbox_data, aria: listbox_aria } end |
#main_wrapper_attrs ⇒ Object
74 75 76 77 78 79 |
# File 'app/presenters/hotwire_combobox/component.rb', line 74 def main_wrapper_attrs apply_customizations_to :main_wrapper, base: { class: "hw-combobox__main__wrapper", data: main_wrapper_data } end |
#paginated? ⇒ Boolean
183 184 185 |
# File 'app/presenters/hotwire_combobox/component.rb', line 183 def paginated? async_src.present? end |
#pagination_attrs ⇒ Object
187 188 189 |
# File 'app/presenters/hotwire_combobox/component.rb', line 187 def pagination_attrs { for_id: canonical_id, src: async_src } end |
#render_in(view_context, &block) ⇒ Object
41 42 43 44 |
# File 'app/presenters/hotwire_combobox/component.rb', line 41 def render_in(view_context, &block) block.call(self) if block_given? view_context.render partial: "hotwire_combobox/component", locals: { component: self } end |