Class: DsfrComponent::NoticeComponent
- Defined in:
- app/components/dsfr_component/notice_component.rb
Constant Summary collapse
- GENERIC_TYPES =
%w[info warning alert].freeze
- WEATHER_TYPES =
%w[weather-orange weather-red weather-purple].freeze
- ALERT_TYPES =
%w[kidnapping cyberattack attack witness].freeze
- TYPES =
GENERIC_TYPES + WEATHER_TYPES + ALERT_TYPES
- WEATHER_ICONS =
%w[windy-fill thunderstorms-fill heavy-showers-fill flood-fill temp-cold-fill sun-fill avalanches-fill snowy-fill].freeze
- DESCRIPTION_TAGS =
i[p h1 h2 h3 h4 h5 h6].freeze
Constants inherited from Base
Base::HEADING_LEVELS, Base::SIZES
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(title:, description:, type: "info", description_tag: :p, use_icon: true, icon_name: nil, use_notice: false, dismissible: false, dismiss_label: "Masquer le message", link_label: nil, link_href: nil, link_title: nil, link_blank: true, html_attributes: {}) ⇒ NoticeComponent
constructor
A new instance of NoticeComponent.
Constructor Details
#initialize(title:, description:, type: "info", description_tag: :p, use_icon: true, icon_name: nil, use_notice: false, dismissible: false, dismiss_label: "Masquer le message", link_label: nil, link_href: nil, link_title: nil, link_blank: true, html_attributes: {}) ⇒ NoticeComponent
Returns a new instance of NoticeComponent.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/components/dsfr_component/notice_component.rb', line 25 def initialize(title:, description:, type: "info", description_tag: :p, use_icon: true, icon_name: nil, use_notice: false, dismissible: false, dismiss_label: "Masquer le message", link_label: nil, link_href: nil, link_title: nil, link_blank: true, html_attributes: {}) @title = title @description = description @type = type @description_tag = description_tag @icon_name = icon_name @use_notice = use_notice @dismissible = dismissible @dismiss_label = dismiss_label @link_label = link_label @link_href = link_href @link_title = link_title @link_blank = link_blank # D’après les règles du DSFR les types non génériques ont forcément une icône @use_icon = if GENERIC_TYPES.include?(type) use_icon else true end raise ArgumentError, "Invalid type: #{type}. Valid types: #{TYPES.join(', ')}" unless type_valid? raise ArgumentError, "Invalid description tag: #{description_tag}" unless DESCRIPTION_TAGS.include?(description_tag) if icon_name raise ArgumentError, "L’icône n’est pas personnalisable sur les bandeaux d’alertes" if ALERT_TYPES.include?(type) raise ArgumentError, "L’icône d’un bandeau de type météo doit être une icône météo (#{WEATHER_ICONS.join(', ')})" if WEATHER_TYPES.include?(type) && WEATHER_ICONS.exclude?(icon_name) end super(html_attributes: html_attributes) end |