Banner component displays important information to the user. The importance of the message can be highlighted with colors.

Open in new tab
import { Banner } from "@kesko/components";

export default () => (
  <Banner>
    Weekend home delivery slots fill up early. <a href="#">Book a delivery time</a>.
  </Banner>
);
import { Banner } from "@kesko/components";
import { IconHeart } from "@kesko/iconography/react";

export default () => (
  <Banner icon={<IconHeart />}>
    Thank you for shopping at K-Rauta. Your K-Plussa points have been added.
  </Banner>
);
import { useState } from "react";
import { Banner, Button } from "@kesko/components";

export default () => {
  const [open, setOpen] = useState(true);

  if (!open) {
    return (
      <Button appearance="outline" onClick={() => setOpen(true)}>
        Show banner
      </Button>
    );
  }

  return (
    <Banner variant="secondary" dismissible onDismiss={() => setOpen(false)}>
      Pick a store to see local prices and availability. <a href="#">Choose your store</a>.
    </Banner>
  );
};
import { useState } from "react";
import { Banner, Button, Stack } from "@kesko/components";

export default () => {
  const [open, setOpen] = useState(true);

  if (!open) {
    return (
      <Button appearance="outline" onClick={() => setOpen(true)}>
        Show banner
      </Button>
    );
  }

  return (
    <Banner variant="success" dismissible onDismiss={() => setOpen(false)}>
      <h3>Delivery confirmed</h3>
      <p>Your K-Ruoka order will be delivered on Friday between 16:00 and 18:00.</p>
      <Stack>
        <Button>Track delivery</Button>
        <Button appearance="outline">Edit order</Button>
      </Stack>
    </Banner>
  );
};
import { useState } from "react";
import { Banner, Button, Stack } from "@kesko/components";

export default () => {
  const [saved, setSaved] = useState(false);

  return (
    <Stack>
      <Button onClick={() => setSaved(true)}>Save list</Button>
      <div role="status">
        {saved && (
          <Banner variant="success" dismissible onDismiss={() => setSaved(false)}>
            Your shopping list has been saved.
          </Banner>
        )}
      </div>
    </Stack>
  );
};
import { Banner, Stack } from "@kesko/components";

export default () => (
  <Stack>
    <Banner variant="primary">
      Weekend home delivery slots fill up early. <a href="#">Book a delivery time</a>.
    </Banner>
    <Banner variant="secondary">
      Your K-Ruoka order can still be edited until 22:00 tonight. <a href="#">Edit order</a>.
    </Banner>
    <Banner variant="success">
      Your order is packed and ready for pickup at K-Citymarket Sello. <a href="#">Show pickup code</a>.
    </Banner>
    <Banner variant="warning">
      Your payment card expires this month. To keep home delivery running, <a href="#">update your card</a>.
    </Banner>
    <Banner variant="error">
      We couldn’t load stock levels for your store. <a href="#">Try again</a> or check back in a few minutes.
    </Banner>
    <Banner variant="neutral">
      Prices include VAT. Delivery fees are shown at checkout. <a href="#">See delivery fees</a>.
    </Banner>
  </Stack>
);
import { Banner, Button, Stack } from "@kesko/components";

export default () => (
  <Stack>
    <Banner variant="primary" dismissible>
      <h3>Delivery slots filling up</h3>
      <p>Weekend home delivery slots for your area are almost full.</p>
      <Stack>
        <Button>Book a delivery time</Button>
        <Button appearance="outline">View pickup options</Button>
      </Stack>
    </Banner>
    <Banner variant="secondary" dismissible>
      <h3>Order still editable</h3>
      <p>You can add or remove items from your K-Ruoka order until 22:00 tonight.</p>
      <Stack>
        <Button>Edit order</Button>
        <Button appearance="outline">View order</Button>
      </Stack>
    </Banner>
    <Banner variant="success" dismissible>
      <h3>Delivery confirmed</h3>
      <p>Your K-Ruoka order will be delivered on Friday between 16:00 and 18:00.</p>
      <Stack>
        <Button>Track delivery</Button>
        <Button appearance="outline">Edit order</Button>
      </Stack>
    </Banner>
    <Banner variant="warning" dismissible>
      <h3>Payment card expiring</h3>
      <p>Your card expires this month. Update it to keep home delivery running.</p>
      <Stack>
        <Button>Update card</Button>
        <Button appearance="outline">Remind me later</Button>
      </Stack>
    </Banner>
    <Banner variant="error" dismissible>
      <h3>Stock levels unavailable</h3>
      <p>We couldn’t load stock levels for your store. Prices may be out of date.</p>
      <Stack>
        <Button>Try again</Button>
        <Button appearance="outline">Change store</Button>
      </Stack>
    </Banner>
    <Banner variant="neutral" dismissible>
      <h3>Closed on Midsummer Day</h3>
      <p>All K-Rauta stores are closed on Saturday. Online orders ship again on Monday.</p>
      <Stack>
        <Button>See opening hours</Button>
        <Button appearance="outline">Find a store</Button>
      </Stack>
    </Banner>
  </Stack>
);

Properties #

NameDescriptionTypeDefault
variant

The style variant of the banner.

"primary" | "secondary" | "success" | "warning" | "error" | "neutral""primary"
icon

The leading icon. Each variant has a default; pass an icon element to replace it, or false to render the banner without one.

ReactNode | false—
dismissible

Renders a close button at the end of the banner. The banner does not remove itself: handle onDismiss and stop rendering it.

booleanfalse

Events #

NameDescriptionType
onDismiss

Called when the close button is activated.

(event: MouseEvent<HTMLButtonElement>) => void

Styles #

CSS custom properties provide finer-grained control than properties. See Styling API for more details. Prefer the Properties API when it suits your need.

NameDescriptionDefault
--k-banner-radius

Overrides the border radius.

var(--k-radius-md)
--k-banner-shadow

Overrides the box shadow.

none
--k-banner-bg

Overrides the background color.

var(--k-color-bg-primary)
--k-banner-border

Overrides the border color.

var(--k-color-border-primary)
--k-banner-text

Overrides the text and icon color.

light-dark(var(--k-color-theme-primary-hover), var(--k-color-text-base))

Accessibility #

Banner is built on a <k-banner> element holding your content, so headings, links and buttons inside it keep their native semantics.

  • Decide whether it is a live region. A banner that is part of the page when it loads needs no role. When you insert one after an action, render it inside an element that already has role="status", so screen readers announce it without interrupting, or role="alert" for an error that blocks the workflow. A region that appears together with its content is often not announced.
  • Keep the meaning in the words. The variant colors the message for people who see them. The text has to carry the meaning for everyone: say “Payment failed” rather than relying on the red.
  • Pick the heading level from the page outline. Every level from h1 to h6 looks the same inside the banner, so choose the one that follows the heading above the banner. The examples use h3 only because they sit under an h2.
  • Say what to do next. Link the fix or the details inside the message, or add action buttons, so people do not have to look for them.
  • Close is named for you. The close button is called “Sulje” and follows the language like the other built-in text. Handle onDismiss and stop rendering the banner; the component does not hide itself.
  • Check contrast if you override colors. --k-banner-text needs 4.5:1 against --k-banner-bg, and buttons inside the banner take the banner's colors. Verify with the WebAIM contrast checker.

See the accessibility guidelines and the A11Y checklist for more details.


Usage #

There are two necessary parts to using the Banner component. The @kesko/components package and the CSS Framework are required. Everything else is optional:

npm install @kesko/components @kesko/css

Once installed, load the CSS Framework in your app’s entry point or root layout:

import "@kesko/css";

Then, you can import the Banner:

import { Banner } from "@kesko/components";

Projects without React can get the same styles from @kesko/css by importing the components stylesheet as well:

@import "@kesko/css";
@import "@kesko/css/components";

Resources #