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, #manual_frame_cookie_name, #manual_frame_remembered?, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_header_menu_items, #render_license_warning, #root_path_without_url, #rtl?, #safe_blob_path, #safe_blob_representation_url, #safe_blob_url, #text_direction, #ui, #wrap_in_modal

Methods included from SummaryChartHelper

#summary_chart_params_for

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
40
# 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?,
      "field-wrapper--density-#{@density}": @density && @density != :default,
    })
end

#dataObject



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

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)


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

def full_width?
  @full_width
end

#helpObject



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

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

#labelObject



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

def label
  @label || @field.name
end

#label_forObject



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

def label_for
  @label_for || @field.form_field_label
end

#label_helpObject



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

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

#recordObject



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

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

#render_dash?Boolean

Returns:

  • (Boolean)


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

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

#stacked?Boolean

Returns:

  • (Boolean)


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

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



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

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