Sha256: e1101190b908eed22c99f003b3b451e0e2e019bf3ad8e8a2782dc13948174bcc

Contents?: true

Size: 1.05 KB

Versions: 69

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

class Avo::Fields::Common::Files::ListViewerComponent < ViewComponent::Base
  include Turbo::FramesHelper

  attr_reader :field, :resource

  def initialize(field:, resource:)
    @field = field
    @resource = resource
  end

  def classes
    base_classes = "py-4 rounded-xl max-w-full"

    view_type_classes = if view_type == :list
      "flex flex-col space-y-2"
    else
      "relative grid xs:grid-cols-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-6 gap-6"
    end

    "#{base_classes} #{view_type_classes}"
  end

  def wrapper_classes
    (field.stacked && !field.hide_view_type_switcher) ? "-mt-9" : ""
  end

  def available_view_types
    [:list, :grid]
  end

  def view_type_component(file)
    component = "Avo::Fields::Common::Files::ViewType::#{view_type.to_s.capitalize}ItemComponent".constantize
    component.new(field: field, resource: resource, file: file, extra_classes: "aspect-video")
  end

  def view_type
    @view_type ||= (resource.params.dig(:view_type) || field.view_type).to_sym
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
avo-2.53.0 app/components/avo/fields/common/files/list_viewer_component.rb
avo-2.52.0 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.9.2 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.9.1 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.8.2 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.9.0 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.8.1 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.8.0 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.6.4 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.6.3 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.6.2 app/components/avo/fields/common/files/list_viewer_component.rb
avo-2.49.0 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.6.1 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.6.0 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.5.8 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.5.7 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.5.6 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.5.6.beta1 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.5.5 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.5.4 app/components/avo/fields/common/files/list_viewer_component.rb