Class: Avo::FieldWrapperComponent

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

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Method Summary collapse

Methods included from Concerns::HasResourceStimulusControllers

#add_stimulus_attributes_for, #get_stimulus_controllers, #stimulus_data_attributes

Methods inherited from BaseComponent

#component_name, #hotkey_badge

Methods included from ApplicationHelper

#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #rtl?, #text_direction, #ui, #wrap_in_modal

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table

Methods included from Concerns::FindAssociationField

#find_association_field

Instance Method Details

#after_initializeObject



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

def after_initialize
  @action = @field.action
  @classes = @args.dig(:class) || ""
end

#classes(extra_classes = "") ⇒ Object



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

def classes(extra_classes = "")
  class_names("field-wrapper",
    @classes,
    extra_classes,
    @field.width_class,
    @field.get_html(:classes, view: @view, element: :wrapper),
    {
      "field-wrapper--stacked": stacked?,
      "field-wrapper--full-width": full_width?,
    })
end

#dataObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/components/avo/field_wrapper_component.rb', line 67

def data
  attributes = {
    field_id: @field.id,
    field_type: @field.type,
    **@data
  }

  # Fetch the data attributes off the html option
  wrapper_data_attributes = @field.get_html :data, view: @view, element: :wrapper
  if wrapper_data_attributes.present?
    attributes.merge! wrapper_data_attributes
  end

  # Add the built-in stimulus integration data tags.
  if @resource.present?
    add_stimulus_attributes_for(@resource, attributes)
  end

  if @action.present?
    add_stimulus_attributes_for(@action, attributes)
  end

  attributes
end

#full_width?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/components/avo/field_wrapper_component.rb', line 103

def full_width?
  @full_width
end

#helpObject



55
56
57
# File 'app/components/avo/field_wrapper_component.rb', line 55

def help
  Avo::ExecutionContext.new(target: @help || @field.help, record: record, resource: @resource, view: @view).handle
end

#labelObject



45
46
47
# File 'app/components/avo/field_wrapper_component.rb', line 45

def label
  @label || @field.name
end

#label_forObject



49
50
51
# File 'app/components/avo/field_wrapper_component.rb', line 49

def label_for
  @label_for || @field.form_field_label
end

#label_helpObject



59
60
61
# File 'app/components/avo/field_wrapper_component.rb', line 59

def label_help
  Avo::ExecutionContext.new(target: @label_help || @field.label_help, record: record, resource: @resource, view: @view).handle
end

#recordObject



63
64
65
# File 'app/components/avo/field_wrapper_component.rb', line 63

def record
  @resource.present? ? @resource.record : nil
end

#render_dash?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/components/avo/field_wrapper_component.rb', line 107

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

#stacked?Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
101
# File 'app/components/avo/field_wrapper_component.rb', line 92

def stacked?
  # Override on the declaration level
  return @stacked unless @stacked.nil?

  # Fetch it from the field
  return @field.stacked unless @field.stacked.nil?

  # Fallback to defaults
  Avo.configuration.field_wrapper_layout == :stacked
end

#styleObject



41
42
43
# File 'app/components/avo/field_wrapper_component.rb', line 41

def style
  "#{@style} #{@field.get_html(:style, view: @view, element: :wrapper)}"
end