Class: Components::ImageCarousel

Inherits:
Base
  • Object
show all
Includes:
Phlex::Rails::Helpers::FormWith
Defined in:
app/components/image_carousel.rb

Instance Method Summary collapse

Constructor Details

#initialize(images:) ⇒ ImageCarousel

Returns a new instance of ImageCarousel.



6
7
8
# File 'app/components/image_carousel.rb', line 6

def initialize(images:)
  @images = images
end

Instance Method Details

#render? ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/components/image_carousel.rb', line 10

def render?
  !@images.empty?
end

#view_template ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/image_carousel.rb', line 14

def view_template
  div id: "imageCarousel",
    class: "carousel slide mb-3",
    role: "group",
    data: {
      bs_ride: "carousel",
      controller: "carousel",
      action: "mouseenter->carousel#onEnter mouseleave->carousel#onLeave"
    },
    aria: {
      roledescription: "carousel"
    } do
    if @images.count > 1
      play_pause_control
    end
    div id: "imageCarouselInner",
      class: "carousel-inner",
      aria: {
        atomic: false,
        live: "off"
      } do
      @images.each_with_index do |image, index|
        div class: ((index == 0) ? "carousel-item active" : "carousel-item"),
          role: "group",
          aria: {
            roledescription: "slide",
            label: translate("components.image_carousel.slide_label", index: (index + 1), count: @images.count, name: image.name)
          } do
          img src: model_model_file_path(image.model, image, format: image.extension, derivative: "carousel"),
            alt: image.name,
            class: "d-block w-100 carousel"
          button_overlay(image)
        end
      end
    end
    if @images.count > 1
      slide_indicators
      next_prev_controls
    end
  end
end