Class: Jav::Index::FieldWrapperComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Jav::Index::FieldWrapperComponent
- Defined in:
- app/components/jav/index/field_wrapper_component.rb
Instance Attribute Summary collapse
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #classes ⇒ Object
-
#initialize(field: nil, resource: nil, dash_if_blank: true, center_content: false, flush: false, **args) ⇒ FieldWrapperComponent
constructor
A new instance of FieldWrapperComponent.
- #stimulus_attributes ⇒ Object
- #style ⇒ Object
Constructor Details
#initialize(field: nil, resource: nil, dash_if_blank: true, center_content: false, flush: false, **args) ⇒ FieldWrapperComponent
Returns a new instance of FieldWrapperComponent.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/components/jav/index/field_wrapper_component.rb', line 6 def initialize(field: nil, resource: nil, dash_if_blank: true, center_content: false, flush: false, **args) super @field = field @resource = resource @dash_if_blank = dash_if_blank @center_content = center_content @classes = args[:class].presence || "" @args = args @flush = flush @view = :index end |
Instance Attribute Details
#view ⇒ Object (readonly)
Returns the value of attribute view.
4 5 6 |
# File 'app/components/jav/index/field_wrapper_component.rb', line 4 def view @view end |
Instance Method Details
#classes ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/components/jav/index/field_wrapper_component.rb', line 18 def classes result = @classes # @flush is a boolean that removes the vertical padding (py-3) for this field # It's useful when you want to remove the space between a field and a tab or a card result += " py-3" unless @flush result += " #{text_align_classes}" result += " #{@field.get_html(:classes, view: view, element: :wrapper)}" result end |
#stimulus_attributes ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/components/jav/index/field_wrapper_component.rb', line 35 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 attributes.merge! wrapper_data_attributes if wrapper_data_attributes.present? attributes end |
#style ⇒ Object
31 32 33 |
# File 'app/components/jav/index/field_wrapper_component.rb', line 31 def style @field.get_html(:style, view: view, element: :wrapper) end |