Class: Avo::CommonFieldWrapperComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/avo/common_field_wrapper_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field: nil, dash_if_blank: true, full_width: false, displayed_in_modal: false, form: nil, resource: nil, label: nil, view: nil, **args) ⇒ CommonFieldWrapperComponent

Returns a new instance of CommonFieldWrapperComponent.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/components/avo/common_field_wrapper_component.rb', line 6

def initialize(field: nil, dash_if_blank: true, full_width: false, displayed_in_modal: false, form: nil, resource: nil, label: nil, view: nil, **args)
  @field = field
  @dash_if_blank = dash_if_blank
  @classes = args[:class].present? ? args[:class] : ""
  @args = args
  @displayed_in_modal = displayed_in_modal
  @form = form
  @resource = resource
  @model = resource.present? ? resource.model : nil
  @full_width = full_width
  @label = label
  @view = view
end

Instance Attribute Details

#viewObject (readonly)

Returns the value of attribute view.



4
5
6
# File 'app/components/avo/common_field_wrapper_component.rb', line 4

def view
  @view
end

Instance Method Details

#classes(extra_classes = "") ⇒ Object



20
21
22
# File 'app/components/avo/common_field_wrapper_component.rb', line 20

def classes(extra_classes = "")
  "#{@classes || ""} #{extra_classes || ""} #{@field.get_html(:classes, view: view, element: :wrapper)}"
end

#labelObject



28
29
30
# File 'app/components/avo/common_field_wrapper_component.rb', line 28

def label
  @label || @field.name
end

#stimulus_attributesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/avo/common_field_wrapper_component.rb', line 32

def stimulus_attributes
  attributes = {}

  @resource.get_stimulus_controllers.split(" ").each do |controller|
    attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
  end

  wrapper_data_attributes = @field.get_html :data, view: view, element: :wrapper
  if wrapper_data_attributes.present?
    attributes.merge! wrapper_data_attributes
  end

  attributes
end

#styleObject



24
25
26
# File 'app/components/avo/common_field_wrapper_component.rb', line 24

def style
  @field.get_html(:style, view: view, element: :wrapper)
end