Class: ViewComponent::InputComponent::InputMobileComponent

Inherits:
InputTextComponent show all
Defined in:
app/helpers/view_component/input_component/input_mobile_component.rb

Constant Summary collapse

CODE_WIDTH =
{
  md: 'w-16',
  lg: 'w-20'
}.freeze
CODE_SELECT_WIDTH =
{
  md: 'w-20',
  lg: 'w-24'
}.freeze
CODE_TEXT =
{
  md: 'mobile-code-md',
  lg: 'mobile-code-lg'
}.freeze

Constants inherited from InputTextComponent

ViewComponent::InputComponent::InputTextComponent::ICON_SIZE, ViewComponent::InputComponent::InputTextComponent::INPUT_SIZE_STYLE, ViewComponent::InputComponent::InputTextComponent::INPUT_WRAPPER_STYLES, ViewComponent::InputComponent::InputTextComponent::LABEL_STYLES, ViewComponent::InputComponent::InputTextComponent::SUBTEXT_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from InputTextComponent

#icon_size, #icon_style, #input_style, #input_wrapper_style, #label_style, #placeholder, #placeholder=, #subtext_style

Methods included from ComponentHelper

#class_list, #resolve_error

Constructor Details

#initialize(form:, name:, label:, type:, placeholder:, code_value:, value:, subtext:, error:, icon_name:, icon_position:, disabled:, size:, html_options:) ⇒ InputMobileComponent

Returns a new instance of InputMobileComponent.



24
25
26
27
28
29
30
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 24

def initialize(form:, name:, label:, type:, placeholder:, code_value:, value:, subtext:, error:,
               icon_name:, icon_position:, disabled:, size:, html_options:)
  super(form:, name:, label:, type:, placeholder:, value:, subtext:, error:, icon_name:, icon_position:,
        disabled:, size:, html_options:)
  self.code_value = code_value
  self.code_name = name.present? ? "#{name}_code" : 'code'
end

Instance Attribute Details

#code_nameObject

Returns the value of attribute code_name.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def code_name
  @code_name
end

#code_valueObject

Returns the value of attribute code_value.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def code_value
  @code_value
end

#disabledObject

Returns the value of attribute disabled.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def disabled
  @disabled
end

#errorObject

Returns the value of attribute error.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def error
  @error
end

#formObject

Returns the value of attribute form.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def form
  @form
end

#html_optionsObject

Returns the value of attribute html_options.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def html_options
  @html_options
end

#icon_nameObject

Returns the value of attribute icon_name.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def icon_name
  @icon_name
end

#icon_positionObject

Returns the value of attribute icon_position.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def icon_position
  @icon_position
end

#labelObject

Returns the value of attribute label.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def label
  @label
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def name
  @name
end

#sizeObject

Returns the value of attribute size.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def size
  @size
end

#subtextObject

Returns the value of attribute subtext.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def subtext
  @subtext
end

#typeObject

Returns the value of attribute type.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def type
  @type
end

#valueObject

Returns the value of attribute value.



21
22
23
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 21

def value
  @value
end

Instance Method Details

#code_selectable?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 32

def code_selectable?
  code_value.blank?
end

#code_wrapper_styleObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 49

def code_wrapper_style
  base = ['mobile-code-base']
  color_style = if disabled
                  'border-disabled-color'
                elsif error.present?
                  error_style
                elsif code_selectable?
                  'border-slate-grey-50 group-focus:ring-primary group-focus:border-primary'
                else
                  'border-slate-grey-50 group-focus-within:border-primary'
                end

  size_style = INPUT_WRAPPER_STYLES[size.to_sym]
  code_width = code_selectable? ? CODE_SELECT_WIDTH[size.to_sym] : CODE_WIDTH[size.to_sym]
  code_text = CODE_TEXT[size.to_sym]
  [class_list(base, size_style, color_style), code_width, code_text].join(' ')
end

#error_styleObject



36
37
38
39
40
41
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 36

def error_style
  base = ['text-danger border-danger-dark',
          'group-focus-within:ring-danger-dark group-focus-within:border-danger-dark']
  base << 'group-focus-within:ring-1' unless code_selectable?
  base.join(' ')
end

#normal_styleObject



43
44
45
46
47
# File 'app/helpers/view_component/input_component/input_mobile_component.rb', line 43

def normal_style
  base = ['border-slate-grey-50 group-focus-within:border-primary']
  base << 'group-focus-within:ring-primary' if code_selectable?
  base.join(' ')
end