Class: Avo::Fields::Common::Files::ListViewerComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
Turbo::FramesHelper
Defined in:
app/components/avo/fields/common/files/list_viewer_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field:, resource:) ⇒ ListViewerComponent

Returns a new instance of ListViewerComponent.



8
9
10
11
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 8

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

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



6
7
8
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 6

def field
  @field
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 6

def resource
  @resource
end

Instance Method Details

#available_view_typesObject



29
30
31
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 29

def available_view_types
  [:list, :grid]
end

#classesObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 13

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

#view_typeObject



38
39
40
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 38

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

#view_type_component(file) ⇒ Object



33
34
35
36
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 33

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

#wrapper_classesObject



25
26
27
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 25

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