Class: UI::ScrollAreaThumbComponent

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

Overview

ThumbComponent - ViewComponent implementation

Draggable scroll indicator inside the scrollbar.

Examples:

Default usage (automatically used by ScrollbarComponent)

<%= render UI::ThumbComponent.new %>

Instance Method Summary collapse

Methods included from ScrollAreaThumbBehavior

#scroll_area_thumb_classes, #scroll_area_thumb_html_attributes

Constructor Details

#initialize(classes: "", **attributes) ⇒ ScrollAreaThumbComponent

Returns a new instance of ScrollAreaThumbComponent.

Parameters:

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



14
15
16
17
# File 'app/view_components/ui/scroll_area_thumb_component.rb', line 14

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

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
# File 'app/view_components/ui/scroll_area_thumb_component.rb', line 19

def call
  thumb_attrs = scroll_area_thumb_html_attributes.deep_merge(@attributes)

  # Add Stimulus target and action for drag
  thumb_attrs[:data] ||= {}
  thumb_attrs[:data][:"ui--scroll-area-target"] = "thumb"
  thumb_attrs[:data][:action] = "pointerdown->ui--scroll-area#startDrag"

   :div, nil, **thumb_attrs
end