Class: DsfrComponent::AlertComponent

Inherits:
Base
  • Object
show all
Includes:
Traits::HeaderSizeable
Defined in:
app/components/dsfr_component/alert_component.rb

Constant Summary collapse

TYPES =
i[error success info warning].freeze
SIZES =
i[sm md].freeze

Constants included from Traits::HeaderSizeable

Traits::HeaderSizeable::DEFAULT_HEADER_LEVEL

Constants inherited from Base

Base::HEADING_LEVELS

Instance Attribute Summary

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods included from Traits::HeaderSizeable

#default_header_level, #header_level, #header_level=, #header_tag

Constructor Details

#initialize(type: nil, title: nil, size: :md, close_button: false, icon_name: nil, header_level: nil, html_attributes: {}) ⇒ AlertComponent

Note:

La taille ‘:md` requiert un titre mais le contenu est

optionel ; la taille ‘sm` requiert un contenu, mais pas de titre.

Parameters:

  • type (AlertComponent::TYPES) (defaults to: nil)
  • title (String) (defaults to: nil)

    le titre de l’alerte, sauf pour la taille ‘:sm`

  • size (AlertComponent::SIZES) (defaults to: :md)
  • close_button (Boolean) (defaults to: false)

    contrôle l’affichage d’un bouton de fermeture

  • icon_name (String) (defaults to: nil)

    un nom d’icône à afficher, seulement disponible pour le type par défaut

  • header_level (Integer) (defaults to: nil)

    Le niveau de titre



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/dsfr_component/alert_component.rb', line 15

def initialize(
  type: nil,
  title: nil,
  size: :md,
  close_button: false,
  icon_name: nil,
  header_level: nil,
  html_attributes: {}
)
  @title = title
  @type = type
  @size = size
  @close_button = close_button
  @icon_name = icon_name
  self.header_level = header_level

  super(html_attributes: html_attributes)
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
# File 'app/components/dsfr_component/alert_component.rb', line 34

def call
  check_main_content!
  check_icon_allowed!

  tag.div(**html_attributes) do
    safe_join([title_tag, , close_button_tag])
  end
end