Class: ViewComponent::InputComponent::DropdownComponent
- Inherits:
-
Object
- Object
- ViewComponent::InputComponent::DropdownComponent
- Includes:
- ComponentHelper
- Defined in:
- app/helpers/view_component/input_component/dropdown_component.rb
Constant Summary collapse
- DROPDOWN_SIZES =
%w[md lg].freeze
- DROPDOWN_SIZE_STYLE =
{ md: 'dropdown-component-md main-text-md-normal', lg: 'dropdown-component-lg main-text-lg-medium' }.freeze
- LABEL_STYLES =
{ md: 'input-text-label-md general-text-sm-normal', lg: 'input-text-label-lg general-text-md-normal' }.freeze
- SUPPORT_TEXT_STYLES =
{ md: 'input-text-subtext-md general-text-sm-normal', lg: 'input-text-subtext-lg general-text-md-normal' }.freeze
Instance Attribute Summary collapse
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#error ⇒ Object
Returns the value of attribute error.
-
#form ⇒ Object
Returns the value of attribute form.
-
#html_options ⇒ Object
Returns the value of attribute html_options.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
-
#size ⇒ Object
Returns the value of attribute size.
-
#support_text ⇒ Object
Returns the value of attribute support_text.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #dropdown_style ⇒ Object
-
#initialize(form:, name:, label:, options:, value:, size:, support_text:, error:, disabled:, html_options:, prompt:) ⇒ DropdownComponent
constructor
A new instance of DropdownComponent.
- #label_style ⇒ Object
- #support_text_style ⇒ Object
Methods included from ComponentHelper
Constructor Details
#initialize(form:, name:, label:, options:, value:, size:, support_text:, error:, disabled:, html_options:, prompt:) ⇒ DropdownComponent
Returns a new instance of DropdownComponent.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 28 def initialize(form:, name:, label:, options:, value:, size:, support_text:, error:, disabled:, html_options:, prompt:) raise "Incorrect dropdown size: #{size}" unless DROPDOWN_SIZES.include?(size) = resolve_error(form, name, error) self.form = form self.name = name self.label = label self. = self.value = value self.size = size self.support_text = (.presence || support_text) self.error = self.disabled = disabled self. = self.prompt = prompt self.[:disabled] = true if disabled self.[:class] = dropdown_style end |
Instance Attribute Details
#disabled ⇒ Object
Returns the value of attribute disabled.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def disabled @disabled end |
#error ⇒ Object
Returns the value of attribute error.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def error @error end |
#form ⇒ Object
Returns the value of attribute form.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def form @form end |
#html_options ⇒ Object
Returns the value of attribute html_options.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def end |
#label ⇒ Object
Returns the value of attribute label.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def end |
#prompt ⇒ Object
Returns the value of attribute prompt.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def prompt @prompt end |
#size ⇒ Object
Returns the value of attribute size.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def size @size end |
#support_text ⇒ Object
Returns the value of attribute support_text.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def support_text @support_text end |
#value ⇒ Object
Returns the value of attribute value.
25 26 27 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 25 def value @value end |
Instance Method Details
#dropdown_style ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 50 def dropdown_style base = ['dropdown-component-base'] size_style = DROPDOWN_SIZE_STYLE[size.to_sym] color_style = if disabled 'text-disabled-color border-disabled-color' elsif error.present? 'text-danger focus:text-danger-dark border-danger focus:border-danger focus:ring-danger' else 'text-letter-color-light border-slate-grey-50 focus:ring-primary' end class_list(base, size_style, color_style) end |
#label_style ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 66 def label_style base = [] size_style = LABEL_STYLES[size.to_sym] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-letter-color-light group-focus-within:text-primary' end class_list(base, size_style, color_style) end |
#support_text_style ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/view_component/input_component/dropdown_component.rb', line 82 def support_text_style base = [] size_style = SUPPORT_TEXT_STYLES[size.to_sym] color_style = if disabled 'text-disabled-color' elsif error.present? 'text-danger-dark' else 'text-letter-color-light' end class_list(base, size_style, color_style) end |