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.Payment failed
Check the card number, then try again.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.
Your trial ends in 3 days.
Minimal example
JxAlert(tone: JxTone.success, [.text('Your changes are online.')])
Complete example
A full Jaspr component you can paste into a project.
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
classesto add or override utilities: they come last, soclasses: 'w:full'wins over the default width. -
Colors come from the theme families
blue,gray,red,greenandyellow. Redefine them intheme.extend.colorsto restyle every component at once.
Accessibility
-
warninganddangercarryrole="alert"(announced at once); the othersrole="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.