Class: Jav::Fields::Common::Files::ListViewerComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Jav::Fields::Common::Files::ListViewerComponent
- Includes:
- Turbo::FramesHelper
- Defined in:
- app/components/jav/fields/common/files/list_viewer_component.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #available_view_types ⇒ Object
- #classes ⇒ Object
- #extra_classes ⇒ Object
-
#initialize(field:, resource:) ⇒ ListViewerComponent
constructor
A new instance of ListViewerComponent.
- #view_type ⇒ Object
- #view_type_component(file) ⇒ Object
- #wrapper_classes ⇒ Object
Constructor Details
#initialize(field:, resource:) ⇒ ListViewerComponent
Returns a new instance of ListViewerComponent.
8 9 10 11 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 8 def initialize(field:, resource:) @field = field @resource = resource end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
6 7 8 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 6 def field @field end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 6 def resource @resource end |
Instance Method Details
#available_view_types ⇒ Object
37 38 39 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 37 def available_view_types [:list, :grid] end |
#classes ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/components/jav/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" elsif field. "relative grid xs:grid-cols-2 lg:grid-cols-3 gap-6" 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 |
#extra_classes ⇒ Object
28 29 30 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 28 def extra_classes @extra_classes ||= field.get_html(:classes, view: resource.view, element: :present) end |
#view_type ⇒ Object
46 47 48 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 46 def view_type @view_type ||= (resource.params.dig(:view_type) || field.view_type).to_sym end |
#view_type_component(file) ⇒ Object
41 42 43 44 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 41 def view_type_component(file) component = "Jav::Fields::Common::Files::ViewType::#{view_type.to_s.capitalize}ItemComponent".constantize component.new(field: field, resource: resource, file: file, extra_classes: extra_classes.presence || "aspect-video") end |
#wrapper_classes ⇒ Object
33 34 35 |
# File 'app/components/jav/fields/common/files/list_viewer_component.rb', line 33 def wrapper_classes (field.stacked && !field.hide_view_type_switcher) ? "-mt-9" : "" end |