Class: BetterUi::General::Input::Select::SelectComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/better_ui/general/input/select/select_component.rb

Constant Summary collapse

BASE_SELECT_CLASSES =
"h-10 px-3 py-2 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm disabled:bg-gray-100 disabled:cursor-not-allowed"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, options:, selected: nil, required: false, disabled: false, multiple: false, options_html: {}, classes: '', **html_options) ⇒ SelectComponent

Returns a new instance of SelectComponent.

Parameters:

  • name (String)

    Nome del campo

  • options (Array)

    Opzioni del select ([=> label, => label, …])

  • selected (String, Array) (defaults to: nil)

    Valore selezionato

  • required (Boolean) (defaults to: false)

    Se il campo è obbligatorio

  • disabled (Boolean) (defaults to: false)

    Se il campo è disabilitato

  • multiple (Boolean) (defaults to: false)

    Se il select è multiplo

  • options_html (Hash) (defaults to: {})

    Opzioni HTML aggiuntive per le option

  • classes (String) (defaults to: '')

    Classi del campo

  • html_options (Hash)

    Opzioni HTML del campo



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/better_ui/general/input/select/select_component.rb', line 20

def initialize(name:, options:, selected: nil, required: false, disabled: false, multiple: false, options_html: {}, classes: '', **html_options)
  @name = name
  @type = :select
  @required = required
  @disabled = disabled
  @options = options.map { |option| { value: option[:value], label: option[:label] } }
  @selected = selected
  @multiple = multiple
  @options_html = options_html
  @classes = BASE_SELECT_CLASSES + classes

  puts "Optionssssssssssssssssssssssss: #{selected}" 
end

Instance Attribute Details

#classesObject (readonly)

Returns the value of attribute classes.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def classes
  @classes
end

#disabledObject (readonly)

Returns the value of attribute disabled.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def disabled
  @disabled
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def html_options
  @html_options
end

#multipleObject (readonly)

Returns the value of attribute multiple.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def multiple
  @multiple
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def options
  @options
end

#options_htmlObject (readonly)

Returns the value of attribute options_html.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def options_html
  @options_html
end

#requiredObject (readonly)

Returns the value of attribute required.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def required
  @required
end

#selectedObject (readonly)

Returns the value of attribute selected.



8
9
10
# File 'app/components/better_ui/general/input/select/select_component.rb', line 8

def selected
  @selected
end