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
|
|
|
|
|
|
|
|
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-26 18:27:40 +02:00
|
|
|
if size == 'small'
|
|
|
|
["fr-alert fr-alert--sm fr-alert--#{state}", extra_class_names].compact.flatten
|
|
|
|
else
|
|
|
|
["fr-alert fr-alert--#{state}", extra_class_names].compact.flatten
|
|
|
|
end
|
2023-06-21 12:24:45 +02:00
|
|
|
end
|
|
|
|
|
2022-08-17 11:15:56 +02:00
|
|
|
private
|
2022-08-17 12:25:49 +02:00
|
|
|
|
2023-06-26 18:27:40 +02:00
|
|
|
def initialize(state:, title: '', size: '', extra_class_names: nil, heading_level: 'h3')
|
2022-08-17 11:15:56 +02:00
|
|
|
@state = state
|
|
|
|
@title = title
|
2023-06-26 18:27:40 +02:00
|
|
|
@size = size
|
2022-08-17 11:15:56 +02:00
|
|
|
@block = block
|
2023-06-21 12:24:45 +02:00
|
|
|
@extra_class_names = extra_class_names
|
2022-12-02 17:16:29 +01:00
|
|
|
@heading_level = heading_level
|
2022-08-17 11:15:56 +02:00
|
|
|
end
|
|
|
|
|
2023-06-26 18:27:40 +02:00
|
|
|
attr_reader :state, :title, :size, :block, :extra_class_names, :heading_level
|
2023-06-21 12:24:45 +02:00
|
|
|
|
|
|
|
private
|
2022-08-17 11:15:56 +02:00
|
|
|
end
|