Feedback

Alert

A message banner in four tones. Urgent tones are announced immediately.

JxAlert import 'package:jx_cli/ui.dart' Available since 0.0.1

Preview

Saved

Your changes are online.

When to use it

  • Confirming a save.
  • Explaining why a payment failed.
  • A notice at the top of a page.

States

A new version is available.
Info
Warning

Minimal example

Dart
JxAlert(tone: JxTone.success, [.text('Your changes are online.')])

Complete example

A full Jaspr component you can paste into a project.

Dart
import 'package:jaspr/dom.dart';
import 'package:jaspr/jaspr.dart';
import 'package:jx_cli/ui.dart';

/// Shows the result of a form submission.
class SubmitResult extends StatelessComponent {
  const SubmitResult({required this.error, super.key});

  final String? error;

  @override
  Component build(BuildContext context) {
    if (error case final error?) {
      return JxAlert(title: 'Not sent', tone: JxTone.danger, [
        p([.text(error)]),
        const JxButton(variant: JxButtonVariant.outline, size: JxButtonSize.sm, [.text('Try again')]),
      ]);
    }
    return const JxAlert(title: 'Sent', tone: JxTone.success, [.text('We reply within a day.')]);
  }
}

Properties

Property Type Default Description
children List<Component> required Message body.
tone JxTone info info , success , warning or danger ( neutral falls back to info ).
title String? null Bold first line.
classes String? null Extra JX classes, appended after the component classes.

Related types

Name Role
JxTone neutral, info, success, warning, danger. Shared with the badge.

Customizing

  • Pass classes to add or override utilities: they come last, so classes: 'w:full' wins over the default width.
  • Colors come from the theme families blue, gray, red, green and yellow. Redefine them in theme.extend.colors to restyle every component at once.

Accessibility

  • warning and danger carry role="alert" (announced at once); the others role="status" (announced politely).
  • The tone is also carried by the text and the thick left border, not by color alone.
  • In dark mode, tones switch to light text on a deep tint.

Limitations

  • Screen readers announce an alert when it is inserted in the page, not when the page loads with it.
  • Not dismissible: no close button. Remove it from your state to hide it.