Class: DsfrComponent::ButtonComponent

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

Constant Summary collapse

SIZES =
%i[sm md lg].freeze
ICON_POSITIONS =
%i[left right].freeze
ICON_LEVELS =
%i[primary secondary tertiary].freeze

Constants inherited from Base

DsfrComponent::Base::HEADING_LEVELS

Instance Attribute Summary

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(label: nil, title: nil, icon: nil, icon_position: :left, level: nil, size: nil, classes: [], html_attributes: {}) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.

Parameters:

  • label (String) (defaults to: nil)

    Le label du bouton (optionnel si un icône présent)

  • icon (String) (defaults to: nil)

    Le nom de l’icône à afficher (exemple ‘arrow-right-line`) (optionnel)

  • icon_position (String) (defaults to: :left)

    Position de l’icône : :left (défaut) ou :right (optionnel)

  • title (String) (defaults to: nil)

    Le titre du bouton permettant d’afficher une infobulle (optionnel)

  • level (String) (defaults to: nil)

    Le niveau du bouton : :primary (défaut), :secondary ou :tertiary (optionnel)

  • size (String) (defaults to: nil)

    La taille du bouton : :sm, :md (défaut), :lg (optionnel)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/dsfr_component/button_component.rb', line 13

def initialize(label: nil, title: nil, icon: nil, icon_position: :left, level: nil, size: nil, classes: [], html_attributes: {})
  @label = label
  @title = title
  @icon = icon
  @icon_position = icon_position
  @level = level
  @outline = outline
  @size = size

  validate_size
  validate_icon_position
  validate_level
  validate_label

  super(classes: classes, html_attributes: html_attributes)
end

Instance Method Details

#callObject



30
31
32
# File 'app/components/dsfr_component/button_component.rb', line 30

def call
  tag.button(**html_attributes) { label }
end