Class: Primer::Beta::Flash

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

Overview

Use ‘Flash` to inform users of successful or pending actions.

Constant Summary collapse

DEFAULT_SCHEME =
:default
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => "",
  :warning => "flash-warn",
  :danger => "flash-error",
  :success => "flash-success"
}.freeze

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from AttributesHelper

#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

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(Primer::Beta::Flash::SCHEME_MAPPINGS.keys) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/primer/beta/flash.rb', line 34

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(
    @system_arguments[:classes],
    "flash",
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)],
    "flash-full": full
  )
  @system_arguments[:mb] ||= spacious ? 4 : nil
end