Class: UI::ScrollAreaThumb

Inherits:
Phlex::HTML
  • Object
show all
Includes:
ScrollAreaThumbBehavior, SharedAsChildBehavior
Defined in:
app/components/ui/scroll_area_thumb.rb

Overview

Thumb - Phlex implementation

Draggable scroll indicator inside the scrollbar.

Examples:

Default usage (automatically used by Scrollbar)

render UI::Thumb.new

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Methods included from ScrollAreaThumbBehavior

#scroll_area_thumb_classes, #scroll_area_thumb_html_attributes

Constructor Details

#initialize(as_child: false, classes: "", **attributes) ⇒ ScrollAreaThumb

Returns a new instance of ScrollAreaThumb.

Parameters:

  • as_child (Boolean) (defaults to: false)

    When true, yields attributes to block instead of rendering div

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



16
17
18
19
20
# File 'app/components/ui/scroll_area_thumb.rb', line 16

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

Instance Method Details

#view_template(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/ui/scroll_area_thumb.rb', line 22

def view_template(&block)
  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"

  if @as_child && block_given?
    # asChild mode: yield attributes to block
    yield(thumb_attrs)
  else
    # Default mode: render as empty div
    div(**thumb_attrs)
  end
end