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

#has_with_trial

Methods included from Concerns::FindAssociationField

#find_association_field

Instance Method Details

#after_initializeObject



27
28
29
# File 'app/components/avo/field_wrapper_component.rb', line 27

def after_initialize
  @action = @field.action
end

#classes(extra_classes = "") ⇒ Object



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

def classes(extra_classes = "")
  class_names("field-wrapper relative flex flex-col grow pb-2 md:pb-0 leading-tight h-full",
    @classes,
    extra_classes,
    @field.get_html(:classes, view: @view, element: :wrapper),
    {
      "min-h-14": !short?,
      "min-h-10": short?,
      "field-wrapper-size-compact": compact?,
      "field-wrapper-size-regular": !compact?,
      "field-width-full": full_width?,
      "field-width-regular": !full_width?,
      "field-wrapper-layout-stacked": stacked?,
      "field-wrapper-layout-inline md:flex-row md:items-center": !stacked?
    })
end

#compact?Boolean

Returns:

  • (Boolean)


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

def compact?
  @compact
end

#dataObject



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

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)


114
115
116
# File 'app/components/avo/field_wrapper_component.rb', line 114

def full_width?
  @full_width
end

#helpObject



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

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

#labelObject



52
53
54
# File 'app/components/avo/field_wrapper_component.rb', line 52

def label
  @label || @field.name
end

#label_forObject



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

def label_for
  @label_for || @field.form_field_label
end

#recordObject



66
67
68
# File 'app/components/avo/field_wrapper_component.rb', line 66

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

#render_dash?Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
124
# File 'app/components/avo/field_wrapper_component.rb', line 118

def render_dash?
  if @field.type == "boolean"
    @field.value.nil?
  else
    @field.value.blank? && @dash_if_blank
  end
end

#short?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/components/avo/field_wrapper_component.rb', line 110

def short?
  @short
end

#stacked?Boolean

Returns:

  • (Boolean)


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

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



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

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