Class: Keystone::Ui::InputComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Keystone::Ui::InputComponent
- Defined in:
- app/components/keystone/ui/input_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"- TYPE_MAP =
{ text: "text", number: "number", email: "email", password: "password", date: "date" }.freeze
- FOCUS_CLASSES =
"focus:border-accent-500 focus:ring-accent-500 dark:focus:border-accent-400 dark:focus:ring-accent-400"
Instance Method Summary collapse
- #classes ⇒ Object
-
#initialize(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil) ⇒ InputComponent
constructor
A new instance of InputComponent.
- #input_type ⇒ Object
- #tag_options ⇒ Object
Constructor Details
#initialize(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil) ⇒ InputComponent
Returns a new instance of InputComponent.
18 19 20 21 22 23 24 25 26 27 |
# File 'app/components/keystone/ui/input_component.rb', line 18 def initialize(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil) @name = name @type = type @value = value @placeholder = placeholder @disabled = disabled @min = min @max = max @step = step end |
Instance Method Details
#classes ⇒ Object
31 32 33 34 35 |
# File 'app/components/keystone/ui/input_component.rb', line 31 def classes tokens = [ BASE_CLASSES, FOCUS_CLASSES ] tokens << DISABLED_CLASSES if @disabled tokens.join(" ") end |
#input_type ⇒ Object
37 38 39 |
# File 'app/components/keystone/ui/input_component.rb', line 37 def input_type TYPE_MAP.fetch(@type) end |
#tag_options ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/components/keystone/ui/input_component.rb', line 41 def = { type: input_type, name: @name, class: classes } [:value] = @value unless @value.nil? [:placeholder] = @placeholder unless @placeholder.nil? [:disabled] = true if @disabled [:min] = @min unless @min.nil? [:max] = @max unless @max.nil? [:step] = @step unless @step.nil? end |