2022-08-17 11:15:56 +02:00
|
|
|
# see: https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/alerte
|
|
|
|
class Dsfr::AlertComponent < ApplicationComponent
|
|
|
|
renders_one :body
|
|
|
|
|
2024-07-03 15:36:19 +02:00
|
|
|
attr_reader :state, :title, :size, :block, :extra_class_names, :heading_level
|
|
|
|
|
|
|
|
def initialize(state:, title: '', size: '', extra_class_names: nil, heading_level: 'h3')
|
|
|
|
@state = state
|
|
|
|
@title = title
|
|
|
|
@size = size
|
|
|
|
@block = block
|
|
|
|
@extra_class_names = extra_class_names
|
|
|
|
@heading_level = heading_level
|
|
|
|
end
|
|
|
|
|
2022-08-17 11:15:56 +02:00
|
|
|
def prefix_for_state
|
|
|
|
case state
|
|
|
|
when :error then "Erreur : "
|
|
|
|
when :info then "Information : "
|
|
|
|
when :warning then "Attention : "
|
|
|
|
when :success then ""
|
|
|
|
else ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-21 12:24:45 +02:00
|
|
|
def alert_class(state)
|
2023-06-29 13:53:23 +02:00
|
|
|
class_names(
|
|
|
|
"fr-alert fr-alert--#{state}" => true,
|
|
|
|
"fr-alert--sm" => size == :sm,
|
|
|
|
extra_class_names => true
|
|
|
|
)
|
2023-06-21 12:24:45 +02:00
|
|
|
end
|
2022-08-17 11:15:56 +02:00
|
|
|
end
|