Sha256: efd6f72c8c3f5af5c387ca840ba4ae11b3a674d9187e8d7b3d5c85bf7d1c071a

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Blacklight
  module System
    class FlashMessageComponent < Blacklight::Component
      renders_one :message

      with_collection_parameter :message

      def initialize(type:, message: nil)
        @message = message
        @classes = alert_class(type)
      end

      def before_render
        with_message { @message } if @message
      end

      # Bootstrap 4 requires the span, but Bootstrap 5 should not have it.
      # See https://getbootstrap.com/docs/4.6/components/alerts/#dismissing
      #     https://getbootstrap.com/docs/5.1/components/alerts/#dismissing
      def button_contents
        return if helpers.controller.blacklight_config.bootstrap_version == 5

        tag.span '&times;'.html_safe, aria: { hidden: true }
      end

      def alert_class(type)
        case type.to_s
        when 'success' then "alert-success"
        when 'notice'  then "alert-info"
        when 'alert'   then "alert-warning"
        when 'error'   then "alert-danger"
        else "alert-#{type}"
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/components/blacklight/system/flash_message_component.rb
blacklight-8.6.0 app/components/blacklight/system/flash_message_component.rb
blacklight-8.5.1 app/components/blacklight/system/flash_message_component.rb
blacklight-8.5.0 app/components/blacklight/system/flash_message_component.rb
blacklight-8.4.0 app/components/blacklight/system/flash_message_component.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/components/blacklight/system/flash_message_component.rb
blacklight-8.3.0 app/components/blacklight/system/flash_message_component.rb
blacklight-8.2.2 app/components/blacklight/system/flash_message_component.rb
blacklight-8.2.1 app/components/blacklight/system/flash_message_component.rb
blacklight-8.2.0 app/components/blacklight/system/flash_message_component.rb
blacklight-8.1.0 app/components/blacklight/system/flash_message_component.rb
blacklight-8.0.1 app/components/blacklight/system/flash_message_component.rb
blacklight-8.0.0 app/components/blacklight/system/flash_message_component.rb
blacklight-8.0.0.beta8 app/components/blacklight/system/flash_message_component.rb
blacklight-8.0.0.beta7 app/components/blacklight/system/flash_message_component.rb
blacklight-8.0.0.beta6 app/components/blacklight/system/flash_message_component.rb
blacklight-8.0.0.beta5 app/components/blacklight/system/flash_message_component.rb