alert-banner
A message in the page: info, success, warning or danger, with an icon, a heading and text. A danger alert is announced as soon as it appears (role="alert"); the others politely (role="status"). dismissible adds a close button, which hides it and fires close.
Try it: events appear here (close).
Every variant
Source: alert-banner.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/alert-banner.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/alert-banner.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/alert-banner.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/alert-banner.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/alert-banner.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/alert-banner.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/alert-banner.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/alert-banner.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/alert-banner.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/alert-banner.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/alert-banner.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/alert-banner.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/alert-banner.js"></script>The compiled install writes src/components/zubra/alert-banner.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<alert-banner variant="warning" heading="Your trial ends in 3 days">
Add a payment method to keep your projects and their history.
</alert-banner>
<script type="module">
import './components/zubra/alert-banner.js';
const element = document.querySelector('alert-banner');
element.dismissible = true;
element.addEventListener('close', (event) => console.log('close', event.detail));
</script>import './components/zubra/alert-banner.js';
const dismissible = true;
export function AlertBannerExample() {
return (
<alert-banner
variant="warning"
heading="Your trial ends in 3 days"
dismissible={dismissible}
onclose={(event) => console.log('close', event.detail)}
>
Add a payment method to keep your projects and their history.
</alert-banner>
);
}<script setup>
import './components/zubra/alert-banner.js';
const dismissible = true;
const onClose = (event) => console.log('close', event.detail);
</script>
<template>
<alert-banner
variant="warning"
heading="Your trial ends in 3 days"
:dismissible.prop="dismissible"
@close="onClose"
>
Add a payment method to keep your projects and their history.
</alert-banner>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/alert-banner.js';
const dismissible = true;
</script>
<alert-banner
variant="warning"
heading="Your trial ends in 3 days"
{dismissible}
onclose={(event) => console.log('close', event.detail)}
>
Add a payment method to keep your projects and their history.
</alert-banner>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/alert-banner.js';
@Component({
selector: 'app-alert-banner-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<alert-banner
variant="warning"
heading="Your trial ends in 3 days"
[dismissible]="dismissible"
(close)="onClose($event)"
>
Add a payment method to keep your projects and their history.
</alert-banner>
`,
})
export class AlertBannerExample {
dismissible = true;
onClose(event: Event) {
console.log('close', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
variant | "info" | "success" | "warning" | "danger" | "info" |
heading | string | "" |
dismissible | boolean | false |
| Event | When |
|---|---|
beforeclose | The close button was pressed; cancel it to keep the alert. |
close | The alert was closed. |
| Slot | For |
|---|---|
(default) | The message. |
actions | Buttons or links under the message. |
heading | Its heading (defaults to heading). |
Size
1.4 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.1 KB.