Class: Keystone::Ui::SelectComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/keystone/ui/select_component.rb

Constant Summary collapse

BASE_CLASSES =
"block w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 focus:outline-none focus:ring-1 dark:bg-zinc-900 dark:border-zinc-700 dark:text-white"
DISABLED_CLASSES =
"cursor-not-allowed bg-gray-50 text-gray-500 dark:bg-zinc-800 dark:text-gray-400"
FOCUS_CLASSES =
"focus:border-accent-500 focus:ring-accent-500 dark:focus:border-accent-400 dark:focus:ring-accent-400"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, options: [], selected: nil, include_blank: nil, disabled: false) ⇒ SelectComponent

Returns a new instance of SelectComponent.



12
13
14
15
16
17
18
# File 'app/components/keystone/ui/select_component.rb', line 12

def initialize(name:, options: [], selected: nil, include_blank: nil, disabled: false)
  @name = name
  @options = options
  @selected = selected
  @include_blank = include_blank
  @disabled = disabled
end

Instance Attribute Details

#include_blankObject (readonly)

Returns the value of attribute include_blank.



10
11
12
# File 'app/components/keystone/ui/select_component.rb', line 10

def include_blank
  @include_blank
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'app/components/keystone/ui/select_component.rb', line 10

def options
  @options
end

#selectedObject (readonly)

Returns the value of attribute selected.



10
11
12
# File 'app/components/keystone/ui/select_component.rb', line 10

def selected
  @selected
end

Instance Method Details

#classesObject



22
23
24
25
26
# File 'app/components/keystone/ui/select_component.rb', line 22

def classes
  tokens = [ BASE_CLASSES, FOCUS_CLASSES ]
  tokens << DISABLED_CLASSES if @disabled
  tokens.join(" ")
end

#tag_optionsObject



28
29
30
31
32
33
34
35
# File 'app/components/keystone/ui/select_component.rb', line 28

def tag_options
  opts = {
    name: @name,
    class: classes
  }
  opts[:disabled] = true if @disabled
  opts
end