1.0.0 • Published 12 months ago

@element-public/react-banner v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Banner

Description

A banner displays a prominent message and related optional actions.

See live demos on storybook

Storybook Banner Demos

Install bundle from npm-e

npm i @element-public/react-components @element-public/themes

Optional: install the component individually

npm i @element-public/react-banner @element-public/themes

Open ~/.npmrc in an editor and add the following line to enable the @element-public scope:

@element-public:registry=https://npm.platforms.engineering

Troubleshooting

See below if you have never installed a package from Bayer's npm-enterprise or run into the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

Setup an access token

See the devtools npm-e guide to learn how to create an access token if this is the first time you are using a npm-e package at Bayer or you do not have a line that starts with the following in your ~/.npmrc file:

//npm.platforms.engineering/:_authToken=

Notes

Banners should be displayed at the top of the screen, below a top app bar. They’re persistent and nonmodal, allowing the user to either ignore them or interact with them at any time. Only one banner should be shown at a time.

ComponentPriorityUser action
SnackbarLow priorityOptional: Snackbars disappear automatically
BannerProminent, medium priorityOptional: Banners remain until dismissed by the user, or if the state that caused the banner is resolved
DialogHighest priorityRequired: Dialogs block app usage until the user takes a dialog action or exits the dialog (if available)

Accessibility Considerations

The context and content surrounding banner will determine the type of ARIA and accessibility concerns that should be maintained. In the spirit of keeping our Banner component light, no specific accessibility concerns have been addressed outside of semantic markup.

Each product and application will be different. To decide how best to support users with Banner, consider some of the following questions:

  • Will Banner load into view, or will it potentially show up dynamically and need to be announced?
  • Will Banner be tied to another control or content piece on the page? What other content might Banner be labeling?
  • Will Banner's content change over time? Or will it be removed from the DOM each time as content changes?

In some ways, Banner could act as a notification, a label, an aside, error/form feedback, or as a live-region content announcement. In many instances, Banner will likely be acting as a notification.

For further reading into creating inclusive, usable, and accessible components consider the following while developing Banner solutions:

Banner CSS Custom Props

Banner comes with one CSS custom property for easy styling access.

:root {
    --lmnt-banner-max-width-content: 100%;
}
NameTypeDefaultDescription
--lmnt-banner-max-width-contentmax-width100%Set the Banner content max-width and center the contents inside of Banner. Defaults to 100%.

Banner Props

NameTypeDefaultRequiredDescription
airybooleannullfalseIndicates that the banner should have more white-space padding than default.
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
customTopAppBarHeightstringnullfalseIf using a custom top app bar with banner, you will have to send in the height of the custom top app bar so the banner positions correctly, ie 55px. You will be responsible for making sure the page content aligns properly upon opening and closing the Banner. The Banner Margin Fix component allows you to wrap the content and send in the margin top or you can use a custom component.
drawerbooleannullfalseIndicates that the banner will be used with an Element Drawer.
elevatedbooleannullfalseIndicates that the banner should have box-shadow and elevation styles. Should be used when banner is fixed. Flat style by default.
fixedbooleannullfalseIndicates that the banner will be in a fixed position.
openbooleantruefalseIndicates that the banner should be open. Open by default. Animates between states with transition CSS.
primaryButtonDismissivebooleantruefalseIf true clicking on the primary button will dismiss the banner. At least one button must dismiss the banner. If both primary and secondary buttons are marked as not dismissive, the primary button will default to dismissive.
primaryButtonLabelstring'Ok'falseBanner primary button label text.
secondaryButtonDismissivebooleantruefalseIf true clicking on the secondary button will dismiss the banner. At least one button must dismiss the banner. If both secondary and secondary buttons are marked as not dismissive, the primary button will default to dismissive.
secondaryButtonLabelstringnullfalseBanner action button label text.
surfaceVariantbooleannullfalseIndicates that the banner background-color should use Element's 'surface variant' color. Uses 'surface' by default.
topAppBarbooleannullfalseIndicates that the banner will be used with an Element Top App Bar.
topAppBarVariantstring'fixed'falseIndicates which type of Element Top App Bar Banner will be used with.Accepted Values: fixed, relative, dense, prominent, dense-prominent, dense-fixed, prominent-fixed, dense-prominent-fixed

Banner Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenulltrueContent to be rendered inside the banner. Accepts any valid markup.
mediaReact.ReactNodenullfalseBanner media slot can hold an image, icon, or other media. (40x40).

Banner Events

NameDefaultRequiredParamsDescription
onClosednullfalse1. Name: reason, Type: string, Description: Reason for closing. ie. Primary Action or Secondary Action.,2. Name: event, Type: object, Description: The javascript eventFired when the banner finishes its closing animation.
onClosingnullfalse1. Name: reason, Type: string, Description: Reason for closing. ie. Primary Action or Secondary Action.,2. Name: event, Type: object, Description: The javascript eventFired when the banner begins its closing animation.
onOpenednullfalse1. Name: event, Type: object, Description: The javascript eventFired when the banner finishes its opened animation.
onOpeningnullfalse1. Name: event, Type: object, Description: The javascript eventFired when the banner begins its MDCBanner:opening animation.
onPrimaryClickednullfalse1. Name: event, Type: object, Description: The javascript eventFired when the Primary Action Button is clicked. Runs after closing animation begins.
onSecondaryClickednullfalse1. Name: event, Type: object, Description: The javascript eventFired when the Secondary Action Button is clicked. Runs after closing animation begins.

Banner Margin Fix Props

NameTypeDefaultRequiredDescription
bannerIdstringundefinedfalseIf supplied, the adjusted margin will attempt to be automatically calculated.
bannerOpenbooleanfalsefalseApply the adjusted left margin.
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
extraMarginnumber24falseThe spacing between the bottom of the banner and the top of the content being adjusted.
marginTopnumber0falseCustom margin.
styleobjectnullfalsePassthrough style object.

Banner Margin Fix Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be vertically adjusted. Accepts any valid markup.