Class: DsfrComponent::TabsComponent::TabComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/dsfr_component/tabs_component/tab_component.rb

Constant Summary

Constants inherited from Base

Base::HEADING_LEVELS

Instance Attribute Summary

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(title:, active: false, path: nil, icon: nil, classes: [], html_attributes: {}) ⇒ TabComponent

Returns a new instance of TabComponent.

Parameters:

  • title (String)

    Le titre de l’onglet affiché dans la barre d’onglets

  • active (Boolean) (defaults to: false)

    Définit si l’onglet est actif ou non

  • path (String) (defaults to: nil)

    (optionnel) chemin vers lequel l’onglet pointe, utilisable avec Turbo Drive, transforme le bouton en lien, avec une turbo action ‘advance`

  • icon (String) (defaults to: nil)

    (optionnel) icône affichée à gauche du titre de l’onglet (sans le préfixe ‘fr-icon-`)



6
7
8
9
10
11
12
13
# File 'app/components/dsfr_component/tabs_component/tab_component.rb', line 6

def initialize(title:, active: false, path: nil, icon: nil, classes: [], html_attributes: {})
  @title = title
  @active = active
  @path = path
  @icon = icon

  super(classes: classes, html_attributes: html_attributes)
end

Instance Method Details

#callObject



27
28
29
# File 'app/components/dsfr_component/tabs_component/tab_component.rb', line 27

def call
  tag.div(**html_attributes) { content }
end


15
16
17
# File 'app/components/dsfr_component/tabs_component/tab_component.rb', line 15

def nav_id
  @nav_id ||= "tab-#{title_slug}-nav"
end


23
24
25
# File 'app/components/dsfr_component/tabs_component/tab_component.rb', line 23

def nav_item
  path ? nav_link : nav_button
end

#panel_idObject



19
20
21
# File 'app/components/dsfr_component/tabs_component/tab_component.rb', line 19

def panel_id
  @panel_id ||= "tab-#{title_slug}-panel"
end