Class: DesignSystem::Generic::Builders::Notification
- Includes:
- ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::SanitizeHelper
- Defined in:
- lib/design_system/generic/builders/notification.rb
Overview
This class provides generic methods to display notifications.
Direct Known Subclasses
Instance Method Summary collapse
- #render_alert(msg = nil) ⇒ Object
- #render_notice(msg = nil, type: :information, content_heading: { text: nil, tag: :h3 }) ⇒ Object
Methods inherited from Base
Methods included from Helpers::CssHelper
Methods included from Concerns::BrandDerivable
Constructor Details
This class inherits a constructor from DesignSystem::Generic::Builders::Base
Instance Method Details
#render_alert(msg = nil) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/design_system/generic/builders/notification.rb', line 11 def render_alert(msg = nil, &) content_to_display = block_given? ? capture(&) : msg content_tag(:div, class: "#{brand}-error-summary", 'aria-labelledby': 'error-summary-title', role: 'alert', tabindex: '-1') do content_tag(:h2, content_to_display, class: "#{brand}-error-summary__title", id: 'error-summary-title') end end |
#render_notice(msg = nil, type: :information, content_heading: { text: nil, tag: :h3 }) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/design_system/generic/builders/notification.rb', line 20 def render_notice(msg = nil, type: :information, content_heading: { text: nil, tag: :h3 }, &) @context.instance_variable_set(:@link_context, :notification_banner) unless notification_type_hash.key?(type) raise ArgumentError, "Invalid notification type: #{type}. Must be one of: #{notification_type_hash.keys.join(', ')}" end header = notification_type_hash.dig(type, :header) content_body = block_given? ? capture(&) : msg content_tag(:div, class: notification_type_hash.dig(type, :class), role: notification_type_hash.dig(type, :role), 'aria-labelledby': "#{brand}-notification-banner-title", 'data-module': "#{brand}-notification-banner") do (header) + (content_body, content_heading:) end end |