Sha256: 4498b31dd80c2e10a4e69f48518d28d451f6763d8491532c6006209fc3e60a0a

Contents?: true

Size: 1021 Bytes

Versions: 67

Compression:

Stored size: 1021 Bytes

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}Component".constantize
    component.new(field: field, resource: resource, file: file)
  end

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

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
avo-3.0.1.beta17 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta18 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta19 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta15 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta16 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta14 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta12 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta13 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta10 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta11 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.0.pre19 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta8 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta9 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta6 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta7 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta5 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta2 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta4 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.1.beta3 app/components/avo/fields/common/files/list_viewer_component.rb
avo-3.0.0.beta1 app/components/avo/fields/common/files/list_viewer_component.rb