Sha256: a0788aa170cd99968fcac53730fa54e14a3f9649e845c4b210badfb9903217fa

Contents?: true

Size: 1.36 KB

Versions: 29

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

class Avo::Fields::ShowComponent < ViewComponent::Base
  include Avo::ResourcesHelper

  attr_reader :compact
  attr_reader :field
  attr_reader :index
  attr_reader :resource
  attr_reader :stacked
  attr_reader :short
  attr_reader :view

  def initialize(field: nil, resource: nil, index: 0, form: nil, compact: false, short: false, stacked: nil)
    @compact = compact
    @field = field
    @index = index
    @resource = resource
    @stacked = stacked
    @short = short
    @view = Avo::ViewInquirer.new("show")
  end

  def wrapper_data
    {
      **stimulus_attributes
    }
  end

  def stimulus_attributes
    attributes = {}

    if @resource.present?
      @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
    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

  def field_wrapper_args
    {
      compact: compact,
      field: field,
      index: index,
      resource: resource,
      short: short,
      stacked: stacked,
      view: view
    }
  end

  def disabled?
    field.is_readonly? || field.is_disabled?
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
avo-3.0.1.beta23 app/components/avo/fields/show_component.rb
avo-3.0.1.beta20 app/components/avo/fields/show_component.rb
avo-3.0.1.beta21 app/components/avo/fields/show_component.rb
avo-3.0.1.beta17 app/components/avo/fields/show_component.rb
avo-3.0.1.beta22 app/components/avo/fields/show_component.rb
avo-3.0.1.beta18 app/components/avo/fields/show_component.rb
avo-3.0.1.beta19 app/components/avo/fields/show_component.rb
avo-3.0.1.beta24 app/components/avo/fields/show_component.rb
avo-3.0.1.beta15 app/components/avo/fields/show_component.rb
avo-3.0.1.beta16 app/components/avo/fields/show_component.rb
avo-3.0.1.beta14 app/components/avo/fields/show_component.rb
avo-3.0.1.beta12 app/components/avo/fields/show_component.rb
avo-3.0.1.beta13 app/components/avo/fields/show_component.rb
avo-3.0.1.beta10 app/components/avo/fields/show_component.rb
avo-3.0.1.beta11 app/components/avo/fields/show_component.rb
avo-3.0.0.pre19 app/components/avo/fields/show_component.rb
avo-3.0.1.beta8 app/components/avo/fields/show_component.rb
avo-3.0.1.beta9 app/components/avo/fields/show_component.rb
avo-3.1.3 app/components/avo/fields/show_component.rb
avo-3.1.2 app/components/avo/fields/show_component.rb