Class: UI::ResizablePanelGroupComponent

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

Overview

ResizablePanelGroup container component (ViewComponent) Wraps resizable panels with Stimulus controller

Examples:

Basic horizontal layout

<%= render UI::PanelGroupComponent.new(direction: "horizontal") do %>
  <%= render UI::PanelComponent.new(default_size: 50) do %>
    Left panel content
  <% end %>
  <%= render UI::HandleComponent.new %>
  <%= render UI::PanelComponent.new(default_size: 50) do %>
    Right panel content
  <% end %>
<% end %>

Vertical layout

<%= render UI::PanelGroupComponent.new(direction: "vertical") do %>
  <%= render UI::PanelComponent.new(default_size: 30) { "Top" } %>
  <%= render UI::HandleComponent.new %>
  <%= render UI::PanelComponent.new(default_size: 70) { "Bottom" } %>
<% end %>

Instance Method Summary collapse

Methods included from ResizablePanelGroupBehavior

#merged_panel_group_data_attributes, #panel_group_base_classes, #panel_group_data_attributes, #panel_group_html_attributes

Constructor Details

#initialize(direction: "horizontal", keyboard_resize_by: 10, classes: "", attributes: {}) ⇒ ResizablePanelGroupComponent

Returns a new instance of ResizablePanelGroupComponent.

Parameters:

  • direction (String) (defaults to: "horizontal")

    “horizontal” or “vertical” layout

  • keyboard_resize_by (Integer) (defaults to: 10)

    percentage to resize by on keyboard input

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

    additional CSS classes

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

    additional HTML attributes



30
31
32
33
34
35
# File 'app/view_components/ui/resizable_panel_group_component.rb', line 30

def initialize(direction: "horizontal", keyboard_resize_by: 10, classes: "", attributes: {})
  @direction = direction
  @keyboard_resize_by = keyboard_resize_by
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



37
38
39
40
41
42
43
44
# File 'app/view_components/ui/resizable_panel_group_component.rb', line 37

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

   :div, **attrs.merge(@attributes.except(:data)) do
    content
  end
end