Class: Tramway::Form::TramwaySelectComponent
- Inherits:
-
TailwindComponent
- Object
- ViewComponent::Base
- BaseComponent
- TailwindComponent
- Tramway::Form::TramwaySelectComponent
- Defined in:
- app/components/tramway/form/tramway_select_component.rb
Overview
Tailwind-styled multi-select field
Constant Summary
Constants inherited from TailwindComponent
TailwindComponent::SIZE_CLASSES
Constants included from Helpers::ViewsHelper
Helpers::ViewsHelper::FORM_SIZES
Instance Method Summary collapse
-
#autocomplete_input ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize.
- #before_render ⇒ Object
- #controller ⇒ Object
- #dropdown_data ⇒ Object
- #dropdown_options ⇒ Object
- #input_classes ⇒ Object
- #tramway_select_classes ⇒ Object
-
#tramway_select_hash ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
Methods included from Helpers::ViewsHelper
#tramway_back_button, #tramway_badge, #tramway_button, #tramway_cell, #tramway_chat, #tramway_container, #tramway_flash, #tramway_form_for, #tramway_header, #tramway_main_container, #tramway_row, #tramway_table, #tramway_title
Methods included from Helpers::ComponentHelper
Methods included from Helpers::DecorateHelper
Instance Method Details
#autocomplete_input ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize
43 44 45 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 43 def autocomplete_input component 'tramway/form/tramway_select/autocomplete_input' end |
#before_render ⇒ Object
11 12 13 14 15 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 11 def before_render @collection = collection.map do |(text, value)| { text:, value: } end.to_json end |
#controller ⇒ Object
56 57 58 59 60 61 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 56 def controller controllers = ['tramway-select'] controllers << external_action.split('->').last.split('#').first if external_action controllers += external_controllers controllers.join(' ') end |
#dropdown_data ⇒ Object
63 64 65 66 67 68 69 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 63 def dropdown_data ([:data] || {}).merge( 'tramway-select-target' => 'dropdown', 'dropdown-container' => dropdown_container, 'item-container' => item_container ) end |
#dropdown_options ⇒ Object
71 72 73 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 71 def .except(:data).merge(class: input_classes) end |
#input_classes ⇒ Object
75 76 77 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 75 def input_classes "#{size_class(:tramway_select_input)} #{select_base_classes}" end |
#tramway_select_classes ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 47 def tramway_select_classes classes = '' classes += 'select--multiple ' if multiple classes += 'select--autocomplete ' if autocomplete classes end |
#tramway_select_hash ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/components/tramway/form/tramway_select_component.rb', line 19 def tramway_select_hash default = { controller:, selected_item_template:, tramway_select_selected_items_value:, dropdown_container:, item_container:, items:, action:, select_as_input:, placeholder:, value:, on_change:, multiple: multiple.to_s, autocomplete: autocomplete.to_s }.transform_keys { |key| key.to_s.gsub('_', '-') } default.merge!(autocomplete_input:) if autocomplete default end |