Module: UI::CarouselBehavior
- Defined in:
- app/behaviors/ui/carousel_behavior.rb
Overview
UI::CarouselBehavior
Instance Method Summary collapse
-
#carousel_base_classes ⇒ Object
Base CSS classes for carousel container.
-
#carousel_classes ⇒ Object
Merge base classes with custom classes.
-
#carousel_data_attributes ⇒ Object
Data attributes for Stimulus controller.
-
#carousel_html_attributes ⇒ Object
Build complete HTML attributes hash.
-
#merged_carousel_data_attributes ⇒ Object
Merge user-provided data attributes.
Instance Method Details
#carousel_base_classes ⇒ Object
Base CSS classes for carousel container
34 35 36 |
# File 'app/behaviors/ui/carousel_behavior.rb', line 34 def carousel_base_classes "relative" end |
#carousel_classes ⇒ Object
Merge base classes with custom classes
39 40 41 |
# File 'app/behaviors/ui/carousel_behavior.rb', line 39 def carousel_classes TailwindMerge::Merger.new.merge([carousel_base_classes, @classes].compact.join(" ")) end |
#carousel_data_attributes ⇒ Object
Data attributes for Stimulus controller
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/behaviors/ui/carousel_behavior.rb', line 44 def carousel_data_attributes attrs = { controller: "ui--carousel", ui__carousel_orientation_value: @orientation || "horizontal" } # Add options if provided if @opts attrs[:ui__carousel_opts_value] = @opts.to_json end # Add plugins if provided if @plugins attrs[:ui__carousel_plugins_value] = @plugins.to_json end attrs end |
#carousel_html_attributes ⇒ Object
Build complete HTML attributes hash
70 71 72 73 74 75 76 77 78 |
# File 'app/behaviors/ui/carousel_behavior.rb', line 70 def carousel_html_attributes base_attrs = @attributes&.except(:data) || {} base_attrs.merge( class: carousel_classes, role: "region", "aria-roledescription": "carousel", data: merged_carousel_data_attributes ) end |
#merged_carousel_data_attributes ⇒ Object
Merge user-provided data attributes
64 65 66 67 |
# File 'app/behaviors/ui/carousel_behavior.rb', line 64 def merged_carousel_data_attributes user_data = @attributes&.fetch(:data, {}) || {} user_data.merge(carousel_data_attributes) end |