Class: Tailwinds::Form::MultiselectComponent

Inherits:
TailwindComponent show all
Defined in:
app/components/tailwinds/form/multiselect_component.rb

Overview

Tailwind-styled multi-select field

Constant Summary

Constants inherited from TailwindComponent

TailwindComponent::SIZE_CLASSES

Constants included from Tramway::Helpers::ViewsHelper

Tramway::Helpers::ViewsHelper::FORM_SIZES

Instance Method Summary collapse

Methods included from Tramway::Helpers::ViewsHelper

#tramway_back_button, #tramway_badge, #tramway_button, #tramway_cell, #tramway_container, #tramway_flash, #tramway_form_for, #tramway_header, #tramway_main_container, #tramway_row, #tramway_table, #tramway_title

Methods included from Tramway::Helpers::ComponentHelper

#component

Methods included from Tramway::Helpers::DecorateHelper

#tramway_decorate

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object (private)



90
91
92
93
94
95
96
97
98
# File 'app/components/tailwinds/form/multiselect_component.rb', line 90

def method_missing(method_name, *, &)
  component = component_name(method_name)

  if method_name.to_s.include?('_') && Object.const_defined?(component)
    render(component.constantize.new(*, &))
  else
    super
  end
end

Instance Method Details

#before_renderObject



9
10
11
12
13
# File 'app/components/tailwinds/form/multiselect_component.rb', line 9

def before_render
  @collection = collection.map do |(text, value)|
    { text:, value: }
  end.to_json
end

#controllerObject



22
23
24
25
26
27
# File 'app/components/tailwinds/form/multiselect_component.rb', line 22

def controller
  controllers = [:multiselect]
  controllers << external_action.split('->').last.split('#').first if external_action
  controllers += external_controllers
  controllers.join(' ')
end


35
36
37
38
39
# File 'app/components/tailwinds/form/multiselect_component.rb', line 35

def dropdown_classes
  theme_classes(
    classic: 'p-1 flex border rounded-xl border-gray-700 bg-gray-900 shadow-inner'
  )
end


41
42
43
44
45
# File 'app/components/tailwinds/form/multiselect_component.rb', line 41

def dropdown_indicator_classes
  theme_classes(
    classic: 'w-8 py-1 pl-2 pr-1 border-l flex items-center text-gray-500 border-gray-700'
  )
end

#multiselect_hashObject



15
16
17
18
19
20
# File 'app/components/tailwinds/form/multiselect_component.rb', line 15

def multiselect_hash
  {
    controller:, selected_item_template:, multiselect_selected_items_value:, dropdown_container:, item_container:,
    items:, action:, select_as_input:, placeholder:, value:, on_change:
  }.transform_keys { |key| key.to_s.gsub('_', '-') }
end

#wrapper_classesObject



29
30
31
32
33
# File 'app/components/tailwinds/form/multiselect_component.rb', line 29

def wrapper_classes
  theme_classes(
    classic: 'flex flex-col relative text-gray-200'
  )
end