sp-banner

Examples API

Attributes and Properties #

Property Attribute Type Default Description
corner corner boolean false Determines if banner sets position at upper right corner or not.
type type 'info' | 'warning' | 'error' 'info' Determines the style, can be "info", "warning", or "error". Default is "info"

Slots #

Name Description
content Secondary message of the banner. Used to provide a description.
header Primary message of the banner.

CSS Custom Properties #

Name Default
--spectrum-banner-border-radius var(--spectrum-global-dimension-static-size-100)
--spectrum-banner-error-background-color var(--spectrum-semantic-negative-color-default)
--spectrum-banner-info-background-color var(--spectrum-semantic-informative-color-default)
--spectrum-banner-padding-x var(--spectrum-global-dimension-static-size-100)
--spectrum-banner-padding-y var(--spectrum-global-dimension-static-size-50)
--spectrum-banner-text-color var(--spectrum-global-color-static-white)
--spectrum-banner-text-line-height var(--spectrum-alias-heading-text-line-height)
--spectrum-banner-text-size var(--spectrum-global-dimension-font-size-75)
--spectrum-banner-warning-background-color var(--spectrum-semantic-notice-color-default)

Description #

An <sp-banner> is an additional label an existing component may have. Banners cannot be interacted with. Banners in Spectrum have three variations for different uses as well as the ability to place it overlaid in the top-right corner of a container.

Usage #

See it on NPM! How big is this package in your project? Try it on webcomponents.dev

yarn add @spectrum-web-components/banner

Import the side effectful registration of <sp-banner> via:

import '@spectrum-web-components/banner/sp-banner.js';

When looking to leverage the Banner base class as a type and/or for extension purposes, do so via:

import { Banner } from '@spectrum-web-components/banner';

Example #

<sp-banner>
<div slot="header">Header text</div>
<div slot="content">Content of the banner</div>
</sp-banner>

Variants #

Info banners #

Banners intended for providing information. This is the default banner variant.

<sp-banner type="info">
<div slot="header">This is an info banner</div>
<div slot="content">Description here</div>
</sp-banner>

Error banners #

Banners intended to indicate an error as occurred, with a brief description of the issue. More severe than a warning banner.

<sp-banner type="error">
<div slot="header">This is an error banner</div>
<div slot="content">Something bad happened</div>
</sp-banner>

Corner placement #

In addition to the variant, banners can be placed in the top-right corner of its container by giving them a corner prop. Note that the position of the containing element needs to be either relative or absolute

<div
style="width: 300px; max-width: 75%; height: 100px; background-color: #ba598b; position: relative;"
>

<sp-banner corner>
<div slot="header">This banner is in a corner</div>
<div slot="content">Neat!</div>
</sp-banner>
</div>

Accessibility #

A Banner does not have a default semantic role communicated to assistive technology, but it does accept id, role and other aria- props that can be added to to improve accessibility depending on context.