Class: Pulse::Flash

Inherits:
Component
  • Object
show all
Defined in:
app/components/pulse/flash.rb

Overview

Use Flash to inform users of successful or pending actions.

Constant Summary collapse

DEFAULT_SCHEME =

TODO: Style icon in scheme color

:default
SCHEME_MAPPINGS =
{
  default: 'pulse-bg-[#ddf4ff] pulse-border pulse-border-[#54aeff]',
  warning: 'pulse-bg-[#fff8c5] pulse-border pulse-border-[#f6e05e]',
  danger: 'pulse-bg-[#ffebe9] pulse-border pulse-border-[#ff8182]',
  success: 'pulse-bg-[#dafbe1] pulse-border pulse-border-[#4ac26b]'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(full: false, spacious: false, dismissible: false, icon: nil, scheme: DEFAULT_SCHEME, **system_arguments) ⇒ Flash

Returns a new instance of Flash.

Parameters:

  • full (Boolean) (defaults to: false)

    Whether the component should take up the full width of the screen.

  • spacious (Boolean) (defaults to: false)

    Whether to add margin to the bottom of the component.

  • dismissible (Boolean) (defaults to: false)

    Whether the component can be dismissed with an X button.

  • icon (Symbol) (defaults to: nil)

    Name of Octicon icon to use.

  • scheme (Symbol) (defaults to: DEFAULT_SCHEME)

    <%= one_of(Pulse::Flash::SCHEME_MAPPINGS.keys) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/pulse/flash.rb', line 35

def initialize(full: false, spacious: false, dismissible: false,
               icon: nil, scheme: DEFAULT_SCHEME, **system_arguments)
  @icon = icon
  @dismissible = dismissible
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :div
  @system_arguments[:classes] = class_names(
    'pulse-px-3 pulse-py-2 pulse-font-medium pulse-rounded-lg pulse-my-3',
    'pulse-flex pulse-gap-2 pulse-items-center pulse-justify-start',
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme,
                                      DEFAULT_SCHEME)],
    system_arguments[:classes],
    'flash-full': full
  )
  @system_arguments[:mb] ||= spacious ? 4 : nil
end