Skip to content

Alert

A message about something that just happened, set into the page. Use it for notices that stay on screen: a save confirmation, a validation error, a setting that needs attention.

tsx
import { Alert } from 'neba';

<Alert color="success">Your changes have been saved.</Alert>
<Alert color="danger" title="Deploy failed" onClose={dismiss}>
  The build exited with code 1.
</Alert>;

Props

PropTypeDefaultDescription
localestringBCP 47 tag naming the dismiss button in that language
variantshared'solid' | 'outline' | 'text''outline'Weight of the surface. An alert *is* the thing being coloured, so the sheet takes the tint. Reach for text inside a form
sizeshared'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Height and type scale
colorshared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info''info'The severity: it picks the surface and the glyph together. The default is info rather than primary. An alert with no severity named is an informational one
densityshared'default' | 'compact''default'Padding only: never the height, never the type scale
elevationshared0 | 1 | 2 | 30Drop shadow depth. An alert sits in the flow of the page; the one that floats is a Toast
titleReactNodeThe heading line. With it the alert is two-part; without it the whole thing is one line
iconReactNode | falseThe glyph at the start. Defaults to the one that goes with `color`; `false` drops it. The shapes differ per family so severity is not carried by colour alone
actionReactNodeContent pinned to the end of the row. Stays on the first line while the message wraps
onClose(event) => voidPassing it is what makes the dismiss button appear
closeLabelstringAccessible name of the dismiss button
childrenReactNodeThe message
transitionsharedNebaTransitionAn entrance animation, run once on mount (transition="slide"). Wrap it in an Animate* component for a trigger or a replay

color defaults to info rather than primary.

Examples

title and children

children alone is a one-line notice; adding title gives you a headline with the detail under it. It is the same component with a different number of slots filled.

variant

An alert is the thing being coloured, so unlike a Box its sheet takes the tint. Use text inside a form, where a second bordered rectangle among the fields is one too many.

color

color sets the severity, and the glyph changes with it. Three drawings cover the six families, so the kind of message carries even where the colour does not.

icon

Pass a node to replace the default glyph, or icon={false} to draw none.

An <svg> anywhere in an alert is sized to 1.2em of the text around it, so an icon from any set arrives at the right size without being told one. Anything that is not an <svg> — an <img>, a sprite, a glyph in a font — carries its own size.

action and onClose

action is a slot outside children, so it stays on the first line while the message wraps beside it. Passing onClose is what makes the × appear.

Accessibility

  • The severity picks the live region: warning and danger get role="alert", which interrupts what a screen reader is saying, and the rest get role="status", which waits for a pause.
  • Passing role yourself overrides the default.
  • With several alerts on screen, use closeLabel to name what is being dismissed.
  • locale decides the dismiss button's accessible name; closeLabel writes it out instead.

Released under the MIT License