Module: UI::CarouselNextBehavior

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

Overview

Shared behavior for Carousel Next button

Instance Method Summary collapse

Instance Method Details

Base CSS classes for next button (default horizontal positioning)



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

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

Merge base classes with custom classes



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

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

Data attributes for Stimulus action



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

def carousel_next_data_attributes
  {
    action: "click->ui--carousel#scrollNext",
    ui__carousel_target: "nextButton"
  }
end

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



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

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

Merge user-provided data attributes



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

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