Sha256: 3ad832710806317fd2b88da7f432e9a208cf0a01a69d6a72f5c6a4a7e580ebc1

Contents?: true

Size: 1.31 KB

Versions: 58

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

class Avo::CommonFieldWrapperComponent < ViewComponent::Base
  attr_reader :view

  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

  def classes(extra_classes = "")
    "#{@classes || ""} #{extra_classes || ""} #{@field.get_html(:classes, view: view, element: :wrapper)}"
  end

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

  def label
    @label || @field.name
  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
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
avo-2.16.0 app/components/avo/common_field_wrapper_component.rb
avo-2.15.3 app/components/avo/common_field_wrapper_component.rb
avo-2.15.3.pre.1.data.attrs.to.sidebar.items app/components/avo/common_field_wrapper_component.rb
avo-2.15.2 app/components/avo/common_field_wrapper_component.rb
avo-2.15.2.pre.1 app/components/avo/common_field_wrapper_component.rb
avo-2.15.1 app/components/avo/common_field_wrapper_component.rb
avo-2.15.0 app/components/avo/common_field_wrapper_component.rb
avo-2.14.3.pre.7.polytranslations1 app/components/avo/common_field_wrapper_component.rb
avo-2.14.3.pre.6.nosprockets app/components/avo/common_field_wrapper_component.rb
avo-2.14.3.pre.5.nosprockets app/components/avo/common_field_wrapper_component.rb
avo-2.14.3.pre.4.tosqlfix app/components/avo/common_field_wrapper_component.rb
avo-2.14.3.pre.3.jsbundling app/components/avo/common_field_wrapper_component.rb
avo-2.14.3.pre.2.tailwindcss app/components/avo/common_field_wrapper_component.rb
avo-2.14.3.pre.1.branding app/components/avo/common_field_wrapper_component.rb
avo-2.14.2 app/components/avo/common_field_wrapper_component.rb
avo-2.14.2.pre.1 app/components/avo/common_field_wrapper_component.rb
avo-2.14.1 app/components/avo/common_field_wrapper_component.rb
avo-2.14.1.pre.1 app/components/avo/common_field_wrapper_component.rb
avo-2.14.0 app/components/avo/common_field_wrapper_component.rb
avo-2.13.6.pre.2 app/components/avo/common_field_wrapper_component.rb