Class: UI::ScrollAreaScrollbarComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ScrollAreaScrollbarBehavior
Defined in:
app/view_components/ui/scroll_area_scrollbar_component.rb

Overview

ScrollbarComponent - ViewComponent implementation

Custom scrollbar track that contains the draggable thumb.

Examples:

Vertical scrollbar (default)

<%= render UI::ScrollbarComponent.new(orientation: "vertical") %>

Horizontal scrollbar

<%= render UI::ScrollbarComponent.new(orientation: "horizontal") %>

Instance Method Summary collapse

Methods included from ScrollAreaScrollbarBehavior

#scroll_area_scrollbar_classes, #scroll_area_scrollbar_html_attributes

Constructor Details

#initialize(orientation: "vertical", classes: "", **attributes) ⇒ ScrollAreaScrollbarComponent

Returns a new instance of ScrollAreaScrollbarComponent.

Parameters:

  • orientation (String) (defaults to: "vertical")

    “vertical” or “horizontal”

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



18
19
20
21
22
# File 'app/view_components/ui/scroll_area_scrollbar_component.rb', line 18

def initialize(orientation: "vertical", classes: "", **attributes)
  @orientation = orientation
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/view_components/ui/scroll_area_scrollbar_component.rb', line 24

def call
  scrollbar_attrs = scroll_area_scrollbar_html_attributes.deep_merge(@attributes)

  # Add Stimulus target
  scrollbar_attrs[:data] ||= {}
  scrollbar_attrs[:data][:"ui--scroll-area-target"] = "scrollbar"

   :div, **scrollbar_attrs do
    render UI::ThumbComponent.new
  end
end