Class: UI::ScrollArea
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- UI::ScrollArea
- Includes:
- ScrollAreaBehavior, SharedAsChildBehavior
- Defined in:
- app/components/ui/scroll_area.rb
Overview
ScrollArea - Phlex implementation
Augments native scroll functionality for custom, cross-browser styling. Root container with Stimulus controller.
Instance Method Summary collapse
-
#initialize(as_child: false, type: "hover", scroll_hide_delay: 600, classes: "", **attributes) ⇒ ScrollArea
constructor
A new instance of ScrollArea.
- #view_template(&block) ⇒ Object
Methods included from SharedAsChildBehavior
Methods included from ScrollAreaBehavior
#scroll_area_classes, #scroll_area_html_attributes
Constructor Details
#initialize(as_child: false, type: "hover", scroll_hide_delay: 600, classes: "", **attributes) ⇒ ScrollArea
Returns a new instance of ScrollArea.
31 32 33 34 35 36 37 |
# File 'app/components/ui/scroll_area.rb', line 31 def initialize(as_child: false, type: "hover", scroll_hide_delay: 600, classes: "", **attributes) @as_child = as_child @type = type @scroll_hide_delay = scroll_hide_delay @classes = classes @attributes = attributes end |
Instance Method Details
#view_template(&block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/components/ui/scroll_area.rb', line 39 def view_template(&block) root_attrs = scroll_area_html_attributes.deep_merge(@attributes) # Add Stimulus controller and values root_attrs[:data] ||= {} root_attrs[:data][:controller] = "ui--scroll-area" root_attrs[:data][:ui__scroll_area_type_value] = @type root_attrs[:data][:ui__scroll_area_scroll_hide_delay_value] = @scroll_hide_delay if @as_child && block_given? # asChild mode: yield attributes to block, but also render scrollbar and corner yield(root_attrs) render UI::Scrollbar.new(orientation: "vertical") render UI::Corner.new else # Default mode: render as div with viewport, scrollbar, and corner div(**root_attrs) do render UI::Viewport.new(&block) render UI::Scrollbar.new(orientation: "vertical") render UI::Corner.new end end end |