Playground

Alert

A message that stays on screen, with a title and a tone.

  • Built on native elements
  • danger and warning are role=alert and announced at once; info and success are role=status and polite.
  • The title always states the meaning in words; colour is not the only signal.
  • Styles in one file: alert.css

Import

import '@monoline/css';
import {Alert} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add alert

Usage

import {Alert} from '@monoline/react';

<div style={{display: 'grid', gap: 'var(--s3)'}}>
  <Alert title="Synced.">42 entries up to date as of 14:20.</Alert>
  <Alert tone="success" title="Saved.">Your changes are live.</Alert>
  <Alert tone="warning" title="Conflict.">Two devices edited 12 March. Pick which copy to keep.</Alert>
  <Alert tone="danger" title="Can't save.">The folder is read-only. Pick another folder.</Alert>
</div>

Examples

Tones

Props

AlertProps

PropTypeDefaultDescription
tone"info" | "success" | "warning" | "danger"'info'Meaning of the message: `info` (default), `success`, `warning` or `danger`. `warning` and `danger` are announced at once to screen readers.
title requiredReactNode–The headline of the message. Required: the words carry the meaning, the colour is only extra.
childrenReactNode–Optional longer explanation shown under the title.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-tone="danger"]alert.css
[data-tone="success"]alert.css
[data-tone="warning"]alert.css

CSS classes

ClassStylesheet
.alertalert.css
.alert-descriptionalert.css
.alert-titlealert.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.alert {
  border-color: var(--accent);
}
.alert[data-tone="danger"] {
  background: var(--wash);
}

Try the props

Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.

Heads up
Your trial ends in three days.
example.tsx
<Alert title="Heads up">Your trial ends in three days.</Alert>

Accessibility

  • danger and warning are role=alert and announced at once; info and success are role=status and polite.
  • The title always states the meaning in words; colour is not the only signal.