Class: UI::TabsContentComponent

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

Overview

TabsContent component (ViewComponent) Panel displaying content for active tab

Examples:

Basic usage

<%= render UI::TabsContentComponent.new(value: "account") do %>
  Account settings content
<% end %>

Instance Method Summary collapse

Methods included from TabsContentBehavior

#content_html_attributes, #content_state

Constructor Details

#initialize(value: "", default_value: "", orientation: "horizontal", classes: "", attributes: {}) ⇒ TabsContentComponent

Returns a new instance of TabsContentComponent.

Parameters:

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

    unique identifier for this content panel

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

    currently active tab value

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

    “horizontal” or “vertical”

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

    additional CSS classes

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

    additional HTML attributes



18
19
20
21
22
23
24
# File 'app/view_components/ui/tabs_content_component.rb', line 18

def initialize(value: "", default_value: "", orientation: "horizontal", classes: "", attributes: {})
  @value = value
  @default_value = default_value
  @orientation = orientation
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
# File 'app/view_components/ui/tabs_content_component.rb', line 26

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

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