Banner
newHeads up, everyone. A full-width notice across the top of a page, closable, in any colour role.
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.
const open = useCookie('banner-maintenance', { default: () => true })
API Reference
class is also accepted on every part and merged over its classes.
Banner
class is also accepted on every part and merged over its classes with tailwind-merge.
| Prop | Default | Type and description |
|---|---|---|
| color | "primary" | BannerColor | (string & {})Colour role of the fill. |
| asChild | — | booleanRender the single child instead of a wrapper, merging the banner's attributes and classes onto it. |
| as | "div" | AsTag | ComponentThe element or component to render. |
| open | true | booleanWhether the banner is shown, bound with |
| Event | Payload and description |
|---|---|
| update:open | [value: boolean]Fires with |
| Slot | Scope and description |
|---|---|
| default | {}An icon as a direct |
BannerTitle
| Slot | Scope and description |
|---|---|
| default | {}The banner's headline. |
BannerSubtitle
| Slot | Scope and description |
|---|---|
| default | {}The text after the headline, in a softer shade of the banner's foreground. |
BannerActions
| Slot | Scope and description |
|---|---|
| default | {}Buttons or links. |
BannerClose
| Slot | Scope and description |
|---|---|
| default | {}The icon. An X by default. |
class is also accepted on every part and merged over its classes with tailwind-merge.
Props
- color
"primary" BannerColor | (string & {})Colour role of the fill.neutralinverts the page's colours. Any name declared on[data-slot][data-color]works too.- asChild
booleanRender the single child instead of a wrapper, merging the banner's attributes and classes onto it.- as
"div" AsTag | ComponentThe element or component to render.- open
true booleanWhether the banner is shown, bound withv-model:open.trueby default;BannerClosesets it tofalse.
Emits
- update:open
[value: boolean]Fires withfalsewhenBannerCloseis pressed.
Slots
- default
{}An icon as a directsvgchild, thenBannerTitle,BannerSubtitle,BannerActionsandBannerClose.
Slots
- default
{}The banner's headline.
Slots
- default
{}The text after the headline, in a softer shade of the banner's foreground.
Slots
- default
{}Buttons or links.size="xs"andcolor="neutral"read well on a coloured fill.
Slots
- default
{}The icon. An X by default.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| banner | data-color | The 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.