Alert / banner
A message about the state of something, with tone, title and optional actions.
Example
<div class="stack"> <focsd-alert tone="positive" headline="Changes saved" closable >Your workspace name now appears on new invoices.</focsd-alert > <focsd-alert tone="caution" headline="Seat limit almost reached" >You are using 9 of 10 seats.</focsd-alert > <focsd-alert tone="critical" headline="Payment failed" >The card ending 4242 was declined.</focsd-alert > <focsd-alert tone="info" headline="Scheduled maintenance" >Sunday 02:00–03:00 UTC.</focsd-alert ></div>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-alert.js';</script>
<focsd-alert tone="positive" headline="Changes saved" closable>Your workspace name now appears on new invoices.</focsd-alert>import { Alert } from '@focsd-dev/react';
export function Example() { return <Alert onClose={(e) => console.log(e.target)} tone="positive" headline="Changes saved" closable>Your workspace name now appears on new invoices.</Alert>;}<script setup>import '@focsd-dev/components/focsd-alert.js';</script>
<template> <focsd-alert @close="onChange" tone="positive" headline="Changes saved" closable>Your workspace name now appears on new invoices.</focsd-alert></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-alert.js';
// template<focsd-alert (close)="onChange($event)" tone="positive" headline="Changes saved" closable>Your workspace name now appears on new invoices.</focsd-alert><script> import '@focsd-dev/components/focsd-alert.js';</script>
<focsd-alert onclose={(e) => console.log(e.target)} tone="positive" headline="Changes saved" closable>Your workspace name now appears on new invoices.</focsd-alert>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
tone | tone | 'neutral' | 'info' | 'positive' | 'caution' | 'critical' | neutral |
icon | icon | string | — |
icon-library | iconLibrary | string | — |
headline | headline | string | — |
live | live | 'off' | 'polite' | 'assertive' | off |
closable | closable | boolean | false |
Events
| Event | Description |
|---|---|
close | Fired when the close button is pressed, before the alert hides; cancel it to keep the alert. |
Slots
| Slot | Description |
|---|---|
(default) | Default content. |
actions | Buttons or links for the alert. |
icon | Any icon markup (an SVG, an icon component, an icon-font element) instead of the tone's icon. |
CSS parts
Style the inside of the component with ::part(), for example focsd-alert::part(actions).
| Part | Description |
|---|---|
actions | The actions element. |
alert | The alert element. |
body | The body element. |
close | The close (×) button, with `closable`. |
content | The content element. |
headline | The headline element. |
icon | The icon element. |
Accessibility
- Static by default. Set
live="polite"(role="status") orlive="assertive"(role="alert") only when the alert appears in response to something. - Tone always comes with an icon and a headline in words, never color alone.
closableadds a close (×) button named "Close". It fires a cancelableclose(it does not bubble), then hides the alert; cancel it to keep the alert or to remove it yourself.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.