Sha256: 92c90eb7ccff80d4cc4af117a2a054081888d30a9f2df25ad14b730f8b499627

Contents?: true

Size: 1.35 KB

Versions: 160

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

class Avo::Index::FieldWrapperComponent < ViewComponent::Base
  attr_reader :view

  def initialize(field: nil, resource: nil, dash_if_blank: true, center_content: false, flush: false, **args)
    @field = field
    @resource = resource
    @dash_if_blank = dash_if_blank
    @center_content = center_content
    @classes = args[:class].present? ? args[:class] : ""
    @args = args
    @flush = flush
    @view = :index
  end

  def classes
    result = @classes

    unless @flush
      result += " py-3"
    end

    result += " #{text_align_classes}"
    result += " #{@field.get_html(:classes, view: view, element: :wrapper)}"

    result
  end

  def style
    @field.get_html(:style, view: view, element: :wrapper)
  end

  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

  private

  def text_align_classes
    case @field.index_text_align.to_sym
    when :right
      "text-right"
    when :center
      "text-center"
    end
  end
end

Version data entries

160 entries across 160 versions & 1 rubygems

Version Path
avo-2.23.1 app/components/avo/index/field_wrapper_component.rb
avo-2.23.0 app/components/avo/index/field_wrapper_component.rb
avo-2.22.0 app/components/avo/index/field_wrapper_component.rb
avo-2.21.3.pre.pr1489 app/components/avo/index/field_wrapper_component.rb
avo-2.21.2.pre.pr1486 app/components/avo/index/field_wrapper_component.rb
avo-2.21.1.pre.pr1484 app/components/avo/index/field_wrapper_component.rb
avo-2.21.0 app/components/avo/index/field_wrapper_component.rb
avo-2.21.1.pre.pr1476 app/components/avo/index/field_wrapper_component.rb
avo-2.21.1.pre.issue1450 app/components/avo/index/field_wrapper_component.rb
avo-2.21.1.pre.issue1444 app/components/avo/index/field_wrapper_component.rb
avo-2.20.0 app/components/avo/index/field_wrapper_component.rb
avo-2.19.0 app/components/avo/index/field_wrapper_component.rb
avo-2.18.1 app/components/avo/index/field_wrapper_component.rb
avo-2.18.1.pre.1.eagerloaddirs app/components/avo/index/field_wrapper_component.rb
avo-2.18.0 app/components/avo/index/field_wrapper_component.rb
avo-2.17.1.pre.5.stackedlayout app/components/avo/index/field_wrapper_component.rb
avo-2.17.1.pre.4.issue.1342 app/components/avo/index/field_wrapper_component.rb
avo-2.17.1.pre.3 app/components/avo/index/field_wrapper_component.rb
avo-2.17.1.pre.2.customauthorizationclients app/components/avo/index/field_wrapper_component.rb
avo-2.17.1.pre.1.zeitwerk.eager.load.dir app/components/avo/index/field_wrapper_component.rb