Class: Avo::Index::FieldWrapperComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field: nil, resource: nil, dash_if_blank: true, center_content: false, flush: false, **args) ⇒ FieldWrapperComponent

Returns a new instance of FieldWrapperComponent.



6
7
8
9
10
11
12
13
14
15
# File 'app/components/avo/index/field_wrapper_component.rb', line 6

def initialize(field: nil, resource: nil, dash_if_blank: true, center_content: false, flush: false, **args)
  @field = field
  @resource = resource
  @dash_if_blank = dash_if_blank
  @center_content = center_content
  @classes = args[:class].present? ? args[:class] : ""
  @args = args
  @flush = flush
  @view = Avo::ViewInquirer.new("index")
end

Instance Attribute Details

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#classesObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/avo/index/field_wrapper_component.rb', line 17

def classes
  result = @classes

  unless @flush
    result += " py-3"
  end

  result += " #{@field.get_html(:classes, view: view, element: :wrapper)}"

  result
end

#stimulus_attributesObject



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

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



29
30
31
# File 'app/components/avo/index/field_wrapper_component.rb', line 29

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