Class: Keystone::Ui::TextareaComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/keystone/ui/textarea_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 placeholder:text-gray-400 focus:outline-none focus:ring-1 dark:bg-zinc-900 dark:border-zinc-700 dark:text-white dark:placeholder:text-gray-500"
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 Method Summary collapse

Constructor Details

#initialize(name:, value: nil, rows: 3, placeholder: nil, disabled: false) ⇒ TextareaComponent

Returns a new instance of TextareaComponent.



10
11
12
13
14
15
16
# File 'app/components/keystone/ui/textarea_component.rb', line 10

def initialize(name:, value: nil, rows: 3, placeholder: nil, disabled: false)
  @name = name
  @value = value
  @rows = rows
  @placeholder = placeholder
  @disabled = disabled
end

Instance Method Details

#classesObject



20
21
22
23
24
# File 'app/components/keystone/ui/textarea_component.rb', line 20

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

#tag_optionsObject



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

def tag_options
  options = {
    name: @name,
    rows: @rows,
    class: classes
  }
  options[:placeholder] = @placeholder unless @placeholder.nil?
  options[:disabled] = true if @disabled
  options
end