Class: UI::TabsTriggerComponent

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

Overview

TabsTrigger component (ViewComponent) Button that activates associated content panel

Examples:

Basic usage

<%= render UI::TabsTriggerComponent.new(value: "account") { "Account" } %>

Disabled trigger

<%= render UI::TabsTriggerComponent.new(value: "disabled", disabled: true) { "Disabled" } %>

Instance Method Summary collapse

Methods included from TabsTriggerBehavior

#trigger_html_attributes, #trigger_state

Constructor Details

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

Returns a new instance of TabsTriggerComponent.

Parameters:

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

    unique identifier for this trigger

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

    currently active tab value

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

    “horizontal” or “vertical”

  • disabled (Boolean) (defaults to: false)

    whether trigger is disabled

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

    additional CSS classes

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

    additional HTML attributes



20
21
22
23
24
25
26
27
# File 'app/view_components/ui/tabs_trigger_component.rb', line 20

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

Instance Method Details

#callObject



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

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

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