Class: Satis::Input::Component

Inherits:
ApplicationComponent show all
Defined in:
app/components/satis/input/component.rb

Instance Attribute Summary collapse

Attributes inherited from ApplicationComponent

#original_view_context

Instance Method Summary collapse

Methods inherited from ApplicationComponent

add_helper, #component_name

Constructor Details

#initialize(form: nil, attribute: nil, **options) ⇒ Component

Returns a new instance of Component.



23
24
25
26
27
# File 'app/components/satis/input/component.rb', line 23

def initialize(form: nil, attribute: nil, **options)
  @form = form
  @attribute = attribute
  @options = options
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



15
16
17
# File 'app/components/satis/input/component.rb', line 15

def attribute
  @attribute
end

#formObject (readonly)

Returns the value of attribute form.



15
16
17
# File 'app/components/satis/input/component.rb', line 15

def form
  @form
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'app/components/satis/input/component.rb', line 15

def options
  @options
end

Instance Method Details

#input_classObject



29
30
31
# File 'app/components/satis/input/component.rb', line 29

def input_class
  [@options.fetch(:input_html, {}).fetch(:class, ""), "sts-input__input", form.has_error?(attribute) ? "is-invalid" : ""].join(" ")
end

#input_container_classObject



33
34
35
# File 'app/components/satis/input/component.rb', line 33

def input_container_class
  form.has_error?(attribute) && "is-invalid"
end