Class: Components::Bulma::TabComponents::Tab

Inherits:
Base
  • Object
show all
Defined in:
lib/components/bulma/tab_components/tab.rb

Overview

# Tab

This component represents a single tab within the Bulma Tabs component.

The component can be used if you need to create or update a tab dynamically.

## Arguments

  • ‘id`: Unique identifier for the tab.

  • ‘title`: The text displayed on the tab.

  • ‘icon`: Optional icon to display on the tab.

  • ‘active`: Boolean indicating if the tab is currently active.

  • ‘data_attributes_proc`: A proc that generates data attributes for the tab.

Instance Method Summary collapse

Constructor Details

#initialize(id:, title:, icon:, active:, data_attributes_proc: Components::Bulma::Tabs::StimulusDataAttributes.new("bulma--tabs").method(:for_tab)) ⇒ Tab



20
21
22
23
24
25
26
27
# File 'lib/components/bulma/tab_components/tab.rb', line 20

def initialize(id:, title:, icon:, active:,
               data_attributes_proc: Components::Bulma::Tabs::StimulusDataAttributes.new("bulma--tabs").method(:for_tab))
  @id = id
  @title = title
  @icon = icon
  @active = active
  @data_attributes_proc = data_attributes_proc
end

Instance Method Details

#view_templateObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/components/bulma/tab_components/tab.rb', line 29

def view_template(&)
  li(
    id: "#{@id}-tab",
    data: @data_attributes_proc.call(@id),
    class: @active ? "is-active" : ""
  ) do
    a do
      icon_span(@icon, "mr-1") if @icon
      span { @title }
    end
  end
end