Class: ViewComponent::InputComponent::DatePickerComponent

Inherits:
Object
  • Object
show all
Includes:
ComponentHelper
Defined in:
app/helpers/view_component/input_component/date_picker_component.rb

Constant Summary collapse

DATE_PICKER_SIZES =
%w[md lg].freeze
DATE_PICKER_SIZE_STYLE =
{
  md: 'input-text-div-base-md main-text-md-normal',
  lg: 'input-text-div-base-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
ICON_SIZE =
{
  md: 'input-text-icon-md',
  lg: 'input-text-icon-lg'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComponentHelper

#class_list, #resolve_error

Constructor Details

#initialize(form:, name:, label:, value:, placeholder:, size:, support_text:, error:, disabled:, html_options:) ⇒ DatePickerComponent

Returns a new instance of DatePickerComponent.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 33

def initialize(form:, name:, label:, value:, placeholder:, size:, support_text:, error:, disabled:, html_options:)
  raise "Incorrect date picker size: #{size}" unless DATE_PICKER_SIZES.include?(size)

  error_message = resolve_error(form, name, error)

  self.form = form
  self.name = name
  self.label = label
  self.value = value
  self.placeholder = placeholder
  self.size = size
  self.support_text = (error_message.presence || support_text)
  self.error = error_message
  self.disabled = disabled
  self.html_options = html_options

  self.html_options[:disabled] = true if disabled
  self.html_options[:class] = date_picker_style
end

Instance Attribute Details

#disabledObject

Returns the value of attribute disabled.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def disabled
  @disabled
end

#errorObject

Returns the value of attribute error.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def error
  @error
end

#formObject

Returns the value of attribute form.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def form
  @form
end

#html_optionsObject

Returns the value of attribute html_options.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def html_options
  @html_options
end

#labelObject

Returns the value of attribute label.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def label
  @label
end

#nameObject

Returns the value of attribute name.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def name
  @name
end

#placeholderObject

Returns the value of attribute placeholder.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def placeholder
  @placeholder
end

#sizeObject

Returns the value of attribute size.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def size
  @size
end

#support_textObject

Returns the value of attribute support_text.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def support_text
  @support_text
end

#valueObject

Returns the value of attribute value.



30
31
32
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 30

def value
  @value
end

Instance Method Details

#date_picker_styleObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 53

def date_picker_style
  base = ['w-full border']
  size_style = DATE_PICKER_SIZE_STYLE[size.to_sym]

  color_style =
    if disabled
      'border-disabled-color text-disabled-color placeholder-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

#icon_styleObject



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 112

def icon_style
  size_style = ICON_SIZE[size.to_sym]

  color_style =
    if disabled
      'text-disabled-color'
    elsif error.present?
      'text-danger'
    else
      'text-letter-color-light hover:text-primary'
    end
  class_list([], size_style, color_style)
end

#icon_wrapper_styleObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 99

def icon_wrapper_style
  base = ['date-picker-icon-wrapper']

  disabled_style =
    if disabled
      'date-picker-icon-wrapper-disabled'
    else
      ''
    end

  class_list(base, disabled_style)
end

#label_styleObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 69

def label_style
  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([], size_style, color_style)
end

#support_text_styleObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/helpers/view_component/input_component/date_picker_component.rb', line 84

def support_text_style
  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([], size_style, color_style)
end