Origami Frontend Components & Services

Readme: n-alert-banner

n-alert-banner is not maintained by the Origami team. This means that the Origami team will not necessarily be able to help you with support requests. The people who maintain this component may be able to offer support, but it's not guaranteed.

n-alert-banner has a support status of "experimental". This means that the component's API may change without notice, and there is no guarantee that the component is ready for production use.

n-alert-banner is a component used for product messaging.

Usage

n-alert-banner includes Sass and JavaScript to show and hide the alert banner. They can be created declaratively by adding Markup to the page, or imperatively using JavaScript (Build).

Behaviour

n-alert-banner elements appears fixed to the top of the screen. You can dismiss a banner, which will hide it but not remove it from the DOM. By default the last banner to be created will be the one that automatically opens. Opening a new banner will close any that are currently open.

Markup

This HTML demonstrates the declarative way to instantiate n-alert-banner. Initialize the alert banner by using AlertBanner.init() and add the following to your code:

<div class="n-alert-banner n-alert-banner--{theme}" data-n-component="n-alert-banner">
    <div class="n-alert-banner__outer">
        <div class="n-alert-banner__inner" data-n-alert-banner-inner="">

            <!-- Content to display on larger screens -->
            <div class="n-alert-banner__content n-alert-banner__content--long">
                <p><b>Something went wrong!</b> Please check and try again.</p>
            </div>

            <!-- Content to display on smaller screens -->
            <div class="n-alert-banner__content n-alert-banner__content--short">
                <p>Please check and try again.</p>
            </div>

            <!-- Button and link -->
            <div class="n-alert-banner__actions">
                <div class="n-alert-banner__action">
                    <a href="#" class="n-alert-banner__button">Button</a>
                </div>
                <div class="n-alert-banner__action--secondary">
                    <a href="#" class="n-alert-banner__link">Text link</a>
                </div>
            </div>

        </div>
    </div>
</div>

Additional optional data components

Build

Constructing an n-alert-banner

If you have set up your alert banner declaratively:

const nAlertBanner = require('n-alert-banner');
const alertBannerElement = document.getElementById('my-alert-banner-element');
const myAlertBanner = new nAlertBanner(alertBannerElement);

The second argument passed to nAlertBanner is an options object, this can be used to change the behaviour and display of a banner.

If you wish to create an alert banner from scratch with no existing DOM elements, you can set up your banner like this:

const AlertBanner = require('n-alert-banner');
const myAlertBanner = new AlertBanner(null, {
    theme: 'error',
    contentLong: 'Something went wrong! Please check and try again.',
    contentShort: 'Please check and try again.',
    buttonLabel: 'Button',
    buttonUrl: '#try-button',
    linkLabel: 'Text link',
    linkUrl: '#feedback-link'
});

The available options are documented below.

Manipulating an n-alert-banner

Once you have an n-alert-banner instance, you can manipulate it using the following methods (assume an instance named myAlertBanner exists):

Options

There are several options used to change the appearance or behaviour of n-alert-banner. All of these are optional, but it's recommended to set at least contentLong, buttonLabel, and buttonUrl or linkLabel and linkUrl. Set the following as properties on the second argument to new AlertBanner:

Sass

Similar to Origami components, n-alert-banner has a silent mode. To use its compiled CSS (rather than using its mixins with your own Sass) set $n-alert-banner-is-silent: false; in your Sass before you've imported the n-alert-banner Sass.

n-alert-banner includes mixins that you can use if you'd rather not have next classnames in your page.

@include nAlertBanner($class: 'n-alert-banner', $themes: 'all');

The $themes parameter can be either all or a specific theme:

@include nAlertBanner($themes: 'error');

Themes

n-alert-banner has the following built-in themes:

In the markup, these can be applied as classes alongside the n-alert-banner class. They are exposed as modifiers:

<div class="n-alert-banner n-alert-banner--error" data-n-component="n-alert-banner">

    ...
</div>

In the JavaScript, use the theme option and pass in the theme name:

const myBanner = new AlertBanner({
    theme: 'success'
});

Install and run


Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, slack #ft-next-conversion, or email ft-next-conversion.


Licence

This software is published by the Financial Times under the MIT licence.

Status
experimental Origami v1 (Bower)
Switch component view

GitHub: n-alert-banner

Install n-alert-banner

If using the Build Service, add n-alert-banner@^2.0.0 to your script and link tags.

If using the npm package manager for a Manual Build, run npm install --save-peer "@financial-times/n-alert-banner@^2.0.0".

Help & Support

n-alert-banner is not supported directly by the Origami team. We make no guarantees, but will help if we can. First try contacting its maintainers at:

Slack: #ft-next-conversion
Email: conversion.tech@ft.com