Class: ViewComponent::Form::HintComponent

Inherits:
FieldComponent show all
Defined in:
app/components/view_component/form/hint_component.rb

Instance Attribute Summary collapse

Attributes inherited from FieldComponent

#method_name

Attributes inherited from BaseComponent

#form, #object_name, #options

Instance Method Summary collapse

Methods inherited from FieldComponent

#label_text, #method_errors, #method_errors?, #object_method_names, #optional?, #required?, #validators, #value

Methods inherited from BaseComponent

#html_class, #object_errors, #object_errors?

Methods included from ClassNamesHelper

#build_tag_values, #class_names

Constructor Details

#initialize(form, object_name, method_name, content_or_options = nil, options = nil) ⇒ HintComponent

Returns a new instance of HintComponent.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/view_component/form/hint_component.rb', line 12

def initialize(form, object_name, method_name, content_or_options = nil, options = nil)
  options ||= {}

  content_is_options = content_or_options.is_a?(Hash)
  if content_is_options
    options.merge! content_or_options
    @attribute_content = nil
  else
    @attribute_content = content_or_options
  end

  super(form, object_name, method_name, options)
end

Instance Attribute Details

#attribute_contentObject (readonly)

Returns the value of attribute attribute_content.



8
9
10
# File 'app/components/view_component/form/hint_component.rb', line 8

def attribute_content
  @attribute_content
end

Instance Method Details

#callObject



26
27
28
29
30
# File 'app/components/view_component/form/hint_component.rb', line 26

def call
  content_or_options = content.presence || attribute_content.presence

  tag.public_send(self.class.tag, content_or_options, **options)
end

#render?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/components/view_component/form/hint_component.rb', line 32

def render?
  content.present? || attribute_content.present?
end