Method: Primer::Alpha::Banner#initialize

Defined in:
app/components/primer/alpha/banner.rb

#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

Returns a new instance of Banner.

Parameters:

  • tag (Symbol) (defaults to: DEFAULT_TAG)

    <%= one_of(Primer::Alpha::Banner::TAG_OPTIONS) %>

  • full (Boolean) (defaults to: false)

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

  • full_when_narrow (Boolean) (defaults to: false)

    Whether the component should take up the full width of the screen when rendered inside smaller viewports.

  • dismiss_scheme (Symbol) (defaults to: DEFAULT_DISMISS_SCHEME)

    Whether the component can be dismissed with an “x” button. <%= one_of(Primer::Alpha::Banner::DISMISS_SCHEMES) %>

  • dismiss_label (String) (defaults to: DEFAULT_DISMISS_LABEL)

    The aria-label text of the dismiss “x” button

  • description (String) (defaults to: nil)

    Description text rendered underneath the message.

  • icon (Symbol) (defaults to: nil)

    The name of an <%= link_to_octicons %> icon to use. If no icon is provided, a default one will be chosen based on the scheme.

  • scheme (Symbol) (defaults to: DEFAULT_SCHEME)

    <%= one_of(Primer::Alpha::Banner::SCHEME_MAPPINGS.keys) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>

[View source]

99
100
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
# File 'app/components/primer/alpha/banner.rb', line 99

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