Class: UI::ResizableHandleComponent

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

Overview

ResizableHandle component (ViewComponent) Draggable handle between resizable panels

Examples:

Basic handle

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

Handle with visible grip icon

<%= render UI::HandleComponent.new(with_handle: true) %>

Instance Method Summary collapse

Methods included from ResizableHandleBehavior

#grip_container_classes, #handle_actions, #handle_base_classes, #handle_data_attributes, #handle_html_attributes, #merged_handle_data_attributes

Constructor Details

#initialize(with_handle: false, classes: "", attributes: {}) ⇒ ResizableHandleComponent

Returns a new instance of ResizableHandleComponent.

Parameters:

  • with_handle (Boolean) (defaults to: false)

    show visible grip icon

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

    additional CSS classes

  • attributes (Hash) (defaults to: {})

    additional HTML attributes



17
18
19
20
21
# File 'app/view_components/ui/resizable_handle_component.rb', line 17

def initialize(with_handle: false, classes: "", attributes: {})
  @with_handle = with_handle
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



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

def call
  attrs = handle_html_attributes
  attrs[:data] = attrs[:data].merge(@attributes.fetch(:data, {}))

   :div, **attrs.merge(@attributes.except(:data)) do
    if @with_handle
       :div, class: grip_container_classes do
        helpers.lucide_icon("grip-vertical", class: "h-2.5 w-2.5")
      end
    end
  end
end