All components (204)
Notifications
Layers · NotificationProvider · .amset-notifications
What it is and when to use it
The notification queue: short messages that appear in a corner, go away on their own and do not get in the way. It is placed once, at the top of the tree (AmsetProvider already includes it), and they are fired from any component inside:
const { show } = useNotifications()
show({ title: 'Factura anulada', tone: 'warning', duration: 0,
action: { label: 'Deshacer', onPress: restaurar } })When to use it
- Telling what has already happened: "Customer saved", "Order sent".
- With
actionto undo what was just done, andduration: 0so it does not go away on its own until closed by hand.textadds a line below the title. tone: 'error'for a failure that needs to be heard right away; withouttone,'info'. They last 5 seconds by default.showreturns the id, in case one has to be removed earlier (close(id));closeAll()removes them all.- On the provider,
positionchooses the corner ('bottom-end'by default) andmaxhow many fit at once (4): when exceeded, the oldest ones go away.
When not to
- What has to be corrected in a form: the field's
error, or anAlertnext to it. - Something about the whole application that stays in view:
GlobalAlert. - A decision:
ConfirmAction,useConfirmationorDialog.
Keyboard: they do not take the focus. Each one has its close button (and its action button), reached with Tab. With the mouse over it or the focus inside, the timer stops; when leaving, it starts counting its whole time again. The action runs and closes the notification.
Accessibility: they appear in a named region (regionLabel, "Notifications"). Inside there are two live regions that exist from the moment the provider is mounted, empty, because a region that is born with the text already inside may not be announced: status for normal ones, which wait for the screen reader to finish what it was reading, and alert for errors, which interrupt (that is why errors are stacked separately, at the end). They have aria-atomic="false": when one arrives, only that one is read. They carry an icon in addition to the color, and the close button is called "Close: <title>".
Fine-tuning: CSS variables --amset-notifications-width and -margin for the queue, and --amset-notification-* (-tone, -slot, -padding-block, -padding-line, -background) for each one. The queue sits on --amset-layer-notification, the last step of the ladder. The action button is the library's Button and the X is the one used by layers: same hover, same focus and 44 px with a finger.
What it looks like
<NotificationProvider>
<App />
</NotificationProvider>
// y dentro, desde cualquier sitio:
const { show } = useNotifications()
show({ tone: 'success', title: 'Saved' })Props
Import it with import { NotificationProvider } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
childrenrequired | ReactNode | — |
max | number | How many fit at once. The oldest ones get closed. |
position | "bottom-end" | "bottom-start" | "top-end" | "top-start" | Where they appear. By default, bottom right. |
regionLabel | string | — |
CSS variables
These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.
| Variable | Default |
|---|---|
--amset-notifications-width | 24rem |
--amset-notifications-margin | var(--amset-space-4) |
How to change it
.amset-notifications {
--amset-notifications-width: ...;
--amset-notifications-margin: ...;
}In the test bench
Every state and variant, to try one at a time, on its page at ui.amset.tech:
