Class: Avo::Index::FieldWrapperComponent

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

Constant Summary collapse

DENSITY_PADDING =

Vertical padding for each density step. nil density falls back to Avo.configuration.density.

{
  tight: "py-2",
  normal: "py-4",
  relaxed: "py-6"
}.freeze

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



23
24
25
26
# File 'app/components/avo/index/field_wrapper_component.rb', line 23

def after_initialize
  @view = Avo::ViewInquirer.new("index")
  @classes = @args.dig(:class) || ""
end

#density_padding_classObject



47
48
49
# File 'app/components/avo/index/field_wrapper_component.rb', line 47

def density_padding_class
  DENSITY_PADDING[(@density || Avo.configuration.density)&.to_sym] || DENSITY_PADDING[:normal]
end

#render_dash?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/components/avo/index/field_wrapper_component.rb', line 43

def render_dash?
  @field.value.blank? && @dash_if_blank
end

#stimulus_attributesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/avo/index/field_wrapper_component.rb', line 28

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