Class: Primer::Alpha::Banner

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/alpha/banner.rb

Overview

Use ‘Banner` to highlight important information.

### Events

|Name |Type |Bubbles |Cancelable | |:———|:——————-|:——-|:———-| |‘dismiss` |`CustomEvent<void>` |No |No |

Constant Summary collapse

DEFAULT_TAG =
:div
TAG_OPTIONS =
[DEFAULT_TAG, :section].freeze
DEFAULT_SCHEME =
:default
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => "",
  :warning => "Banner--warning",
  :danger => "Banner--error",
  :success => "Banner--success",
  :upsell => "Banner--upsell"
}.freeze
LEGACY_SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => "",
  :warning => "flash-warn",
  :danger => "flash-error",
  :success => "flash-success",
}.freeze
DEFAULT_ICONS =
{
  default: :bell,
  warning: :alert,
  danger: :stop,
  success: :"check-circle",
  upsell: :info,
}.freeze
DEFAULT_DISMISS_SCHEME =
:none
DISMISS_SCHEMES =
[
  DEFAULT_DISMISS_SCHEME,
  :remove,
  :hide
].freeze
DEFAULT_DISMISS_LABEL =
"Dismiss"

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 Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::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 Primer::AttributesHelper

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

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(tag: DEFAULT_TAG, full: false, full_when_narrow: false, dismiss_scheme: DEFAULT_DISMISS_SCHEME, dismiss_label: DEFAULT_DISMISS_LABEL, description: nil, icon: nil, scheme: DEFAULT_SCHEME, **system_arguments) ⇒ Banner



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/components/primer/alpha/banner.rb', line 101

def initialize(tag: DEFAULT_TAG, full: false, full_when_narrow: false, dismiss_scheme: DEFAULT_DISMISS_SCHEME, dismiss_label: DEFAULT_DISMISS_LABEL, description: nil, icon: nil, scheme: DEFAULT_SCHEME, **system_arguments)
  @scheme = fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)
  @icon = icon || DEFAULT_ICONS[@scheme]
  @dismiss_scheme = dismiss_scheme
  @dismiss_label = dismiss_label
  @description = description

  @system_arguments = system_arguments
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "Banner",
    "flash", # legacy
    SCHEME_MAPPINGS[@scheme],
    LEGACY_SCHEME_MAPPINGS[@scheme],
    "Banner--full": full,
    "flash-full": full, # legacy
    "Banner--full-whenNarrow": full_when_narrow
  )

  @message_arguments = {
    tag: :div,
    classes: "Banner-message"
  }

  @wrapper_arguments = {
    tag: custom_element_name,
    data: { dismiss_scheme: @dismiss_scheme }
  }
end