Class: Avo::CommonFieldWrapperComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Avo::CommonFieldWrapperComponent
- Defined in:
- app/components/avo/common_field_wrapper_component.rb
Instance Attribute Summary collapse
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #classes(extra_classes = "") ⇒ Object
-
#initialize(field: nil, dash_if_blank: true, full_width: false, displayed_in_modal: false, form: nil, resource: nil, label: nil, view: nil, **args) ⇒ CommonFieldWrapperComponent
constructor
A new instance of CommonFieldWrapperComponent.
- #label ⇒ Object
- #stimulus_attributes ⇒ Object
- #style ⇒ Object
Constructor Details
#initialize(field: nil, dash_if_blank: true, full_width: false, displayed_in_modal: false, form: nil, resource: nil, label: nil, view: nil, **args) ⇒ CommonFieldWrapperComponent
Returns a new instance of CommonFieldWrapperComponent.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/components/avo/common_field_wrapper_component.rb', line 6 def initialize(field: nil, dash_if_blank: true, full_width: false, displayed_in_modal: false, form: nil, resource: nil, label: nil, view: nil, **args) @field = field @dash_if_blank = dash_if_blank @classes = args[:class].present? ? args[:class] : "" @args = args @displayed_in_modal = displayed_in_modal @form = form @resource = resource @model = resource.present? ? resource.model : nil @full_width = full_width @label = label @view = view end |
Instance Attribute Details
#view ⇒ Object (readonly)
Returns the value of attribute view.
4 5 6 |
# File 'app/components/avo/common_field_wrapper_component.rb', line 4 def view @view end |
Instance Method Details
#classes(extra_classes = "") ⇒ Object
20 21 22 |
# File 'app/components/avo/common_field_wrapper_component.rb', line 20 def classes(extra_classes = "") "#{@classes || ""} #{extra_classes || ""} #{@field.get_html(:classes, view: view, element: :wrapper)}" end |
#label ⇒ Object
28 29 30 |
# File 'app/components/avo/common_field_wrapper_component.rb', line 28 def label @label || @field.name end |
#stimulus_attributes ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/components/avo/common_field_wrapper_component.rb', line 32 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 |
#style ⇒ Object
24 25 26 |
# File 'app/components/avo/common_field_wrapper_component.rb', line 24 def style @field.get_html(:style, view: view, element: :wrapper) end |