Banner

new

Heads up, everyone. A full-width notice across the top of a page, closable, in any colour role.

Demo
kappa-ui 0.15
Tour, Banner and Marker are in.

Open Props in the corner of the example to try color.

color picks the colour role of the fill, primary by default. neutral inverts the page's colours. Any name declared on [data-slot][data-color] works too.

Installation

Usage

<script setup lang="ts">
import { Banner, BannerActions, BannerClose, BannerSubtitle, BannerTitle } from '@/components/ui/banner'
</script>

<template>
  <Banner>
    <MegaphoneIcon />
    <BannerTitle>kappa-ui 0.15</BannerTitle>
    <BannerSubtitle>Tour, Banner and Marker are in.</BannerSubtitle>
    <BannerActions>
      <Button size="xs" color="neutral">Read more</Button>
    </BannerActions>
    <BannerClose />
  </Banner>
</template>

A banner spans the page above everything else, for news, maintenance or a problem with the account. Its parts sit in one centred row and wrap on narrow screens; an icon goes in as a direct svg child. Nuxt UI's Banner, taken apart into parts.

BannerClose sets open to false, and the banner leaves the DOM. Bind v-model:open to react to it or bring the banner back. A close button keeps the content centred: the banner pads both sides by the button's width.

Examples

Remembering the choice

The banner keeps no state of its own beyond open, so remembering a dismissal is a matter of where you store it. useLocalStorage from VueUse keeps it in the browser; with initOnMounted: true it reads the storage after hydration, so a server-rendered page does not mismatch, though the banner shows for a moment before it hides. In Nuxt, useCookie reaches the server, which then never renders a dismissed banner at all.

Persistent banner
Scheduled maintenance
Sunday 02:00–03:00 UTC.
const open = useCookie('banner-maintenance', { default: () => true })

API Reference

class is also accepted on every part and merged over its classes.

Data attributes

data-slotAttributesDescription
bannerdata-colorThe bar.
banner-title—The headline.
banner-subtitle—The secondary text.
banner-actions—The row of actions.
banner-close—The close button at the end.

Accessibility

The banner has no role, since most banners are there from the start and need no announcement. For one that appears while the page is open, add role="status", or role="alert" when it is urgent. BannerClose is labelled "Close"; pass your own aria-label to translate it.

Changelog

  1. registry 0.22.0

    95b68d3 — Breaking: the focus ring's colour hook is --focus-ring-color, no longer --color-ring. focus-ring and focus-ring-inset read var(--focus-ring-color, --theme(--color-ring)), so a .dark island (or any subtree that sets --ring) rings its controls in its own --ring; a class such as [--color-ring:currentColor] copied from the kit now has no effect and becomes [--focus-ring-color:currentColor]. tone-control, AlertClose, BannerClose and the ChoiceGroup cards set the new variable.

    cb25aeb — AlertClose and BannerClose render type="button", so in a form they are no longer its default button: Enter in a field submits the form instead of closing the notice.

  2. core 0.16.0

    95b68d3 — Breaking: the focus ring's colour hook is --focus-ring-color, no longer --color-ring. focus-ring and focus-ring-inset read var(--focus-ring-color, --theme(--color-ring)), so a .dark island (or any subtree that sets --ring) rings its controls in its own --ring; a class such as [--color-ring:currentColor] copied from the kit now has no effect and becomes [--focus-ring-color:currentColor]. tone-control, AlertClose, BannerClose and the ChoiceGroup cards set the new variable.

  3. registry 0.21.0

    6d5114c — AlertClose: a close button for Alert, like BannerClose. It sits at the end of the title's line (centred when horizontal), takes the alert's text colour and a size that follows the alert's, and the text keeps clear of it. Alert gains v-model:open; the item now depends on button and @lucide/vue.

  4. registry 0.17.0

    7951a0f — New Marker: an inline status, a bordered row or a labelled separator, from shadcn-vue, with a color. New Banner: a full-width notice with a title, a subtitle, actions and a close button, v-model:open and color. New Tour: parts over Popover for a guided tour driven by useTour. Skeleton takes a color.