Module: Bh::Helpers::Notices

Included in:
Bh::Helpers
Defined in:
lib/bh/helpers/notices.rb

Overview

What the flash says, as the toasts every Bh page shows them in.

Constant Summary collapse

TONES =

Bootstrap's tone for each key, so a notice and an alert read apart; a key of the host's own reads neutral.

{ 'notice' => 'theme-success', 'alert' => 'theme-danger' }.freeze
HOLD =

The toast controller's hooks: the timed hide stops while a reader hovers or focuses a toast, so a message stays while someone reads it or aims for the X.

'mouseenter->toast#stopTimer mouseleave->toast#startTimer ' \
'focusin->toast#stopTimer focusout->toast#startTimer'

Instance Method Summary collapse

Instance Method Details

#noticesObject

Every message in the flash as a toast at the bottom right, visible at first paint and gone after a moment or a click. Only messages: a value that is not words is data some other part of a host keeps in the flash, and is not something to show. Nothing at all where there is nothing to say. data-turbo-temporary, so a toast born visible does not replay from the page's snapshot on every Back.



19
20
21
22
23
24
25
26
27
# File 'lib/bh/helpers/notices.rb', line 19

def notices
  messages = flash.to_hash.select { |_, message| message.is_a? String }
  return if messages.empty?

  toasts = messages.map { |key, message| bh_toast key, message }

  tag.div safe_join(toasts), class: 'toast-container position-fixed bottom-0 end-0 p-3',
                             data: { turbo_temporary: '' }
end