Module: UI::CarouselPreviousBehavior

Defined in:
app/behaviors/ui/carousel_previous_behavior.rb

Overview

Shared behavior for Carousel Previous button

Instance Method Summary collapse

Instance Method Details

Base CSS classes for previous button (default horizontal positioning)



8
9
10
# File 'app/behaviors/ui/carousel_previous_behavior.rb', line 8

def carousel_previous_base_classes
  "absolute size-8 !rounded-full top-1/2 -translate-y-1/2 -left-12"
end

Merge base classes with custom classes



13
14
15
# File 'app/behaviors/ui/carousel_previous_behavior.rb', line 13

def carousel_previous_classes
  TailwindMerge::Merger.new.merge([carousel_previous_base_classes, @classes].compact.join(" "))
end

Data attributes for Stimulus action



18
19
20
21
22
23
# File 'app/behaviors/ui/carousel_previous_behavior.rb', line 18

def carousel_previous_data_attributes
  {
    action: "click->ui--carousel#scrollPrev",
    ui__carousel_target: "prevButton"
  }
end

Build complete HTML attributes hash (without class, which is handled separately)



32
33
34
35
36
37
38
# File 'app/behaviors/ui/carousel_previous_behavior.rb', line 32

def carousel_previous_html_attributes
  base_attrs = @attributes&.except(:data, :class) || {}
  base_attrs.merge(
    "aria-label": "Previous slide",
    data: merged_carousel_previous_data_attributes
  )
end

Merge user-provided data attributes



26
27
28
29
# File 'app/behaviors/ui/carousel_previous_behavior.rb', line 26

def merged_carousel_previous_data_attributes
  user_data = @attributes&.fetch(:data, {}) || {}
  user_data.merge(carousel_previous_data_attributes)
end