Zubra UI
Code for
GitHub

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.

Add a payment method to keep your projects and their history.

Try it: events appear here (close).

Every variant

Maintenance on Sunday, 2–3 am.Thanks: your receipt is on its way.Try another card, or contact your bank.

Source: alert-banner.zb, and its registry item.

Install

Compiled (any project)
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
One file, no dependencies (4.4 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
variant"info" | "success" | "warning" | "danger""info"
headingstring""
dismissiblebooleanfalse
Events
EventWhen
beforecloseThe close button was pressed; cancel it to keep the alert.
closeThe alert was closed.
Slots
SlotFor
(default)The message.
actionsButtons or links under the message.
headingIts 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour