packages/grafana-ui/src/components/Alert/Alert.mdx
import { Meta, ArgTypes } from '@storybook/blocks'; import { Alert } from './Alert';
<Meta title="MDX|Alert" component={Alert} />Alert is a fundamental element used for displaying important messages or notifications to users.
About Alert component:
Use Alerts to inform users of updates, changes, or issues. Providing users feedback, keeping them informed, and keeping disruptions to a minimum is important. There are two different use-cases for Alerts: task-generated and system-generated Alerts.
Task-generated Alerts are triggered based on the behaviours of the user and provide quick, direct feedback. This type of Alert should be placed closely to the area the user is actively working in.
System-generated Alerts are triggered by the system, unconnected to the actions of a user. Use these Alerts to provide explanation of system status or other events that have occurred elsewhere.
Within Grafana, we have two different types of alerts and they can be used depending on the context and content.
info-circle iconcheck iconexclamation-triangle iconexclamation-triangle iconTitles in Alerts are required, always. They should be concise, human-focused and jargon free so users can easily understand them.
Description copy is optional and should be used sparingly. Keep the description copy short and focused on the reason for the Alert and include possible solutions or paths forward to prevent users from being blocked.
It is important to always use simple and concise language when crafting messaging for Alerts. Avoid using jargon or system errors in the content of the Alerts. Provide users with a path forward or possible solution. For more recommendations on writing, view the UX writing guidelines.
Alerts (Inline Alerts specifically) can contain calls to action (CTAs), especially if there is an action a user can take to remedy or correct the reason the Alert is being shown. When providing a CTA within an Alert be sure to keep the label concise and ensure the action the user can take is clear, and try to keep the labels short (a few words at most). See Grafana's UX Writing guidelines.
Icon status: represents the importance of the message through the color and icon for each status.
Alert title: should be explicit, clear and short, conveying the most important part of the information.
Details: precise description for the notification, telling users what they need to do.
Button and text links: only persistent notifications should contain text links or buttons.
Close icon: appears when the notification can be dismissed by the user.
Inline Banners are task-oriented alerts that notify users of the status of an action or system. These alerts are contextual — appearing above or below main content areas — allowing users to address issues or to read messages quickly.
- Use the appropriate status for the message (info/success/warning/error).
- Use plain, simple language for the messages to ensure users understand them and know how to address them.
- Focus on notifications if they are relevant to the users' current workflow and should be addressed immediately.
- Do not use Primary calls to actions.
- Do not hide other content with inline notifications.
- Do not repeat the alert copy/title on the details message.
- To inform at that time how to continue a task in which users must perform an action.
- To provide some options for users to take action.
- To explain in detail the reasons why something can’t be done by users.
- Should be placed immediately above or below the related element.
<Alert title={title} severity={severity} buttonContent={buttonContent} onRemove={onRemove}>
Child content that includes some alert details, like maybe what actually happened.
</Alert>
Toast notifications are short messages that appear in the top-right corner of the page and are automatically hidden after a certain amount of time – they provide live notifications, without interrupting the user experience or requiring an action to be taken.
- Use this component using `AppEvents` and `getAppEvents()`.
- Show the `Toast` publishing the `appEvent` with the proper type and payload needed.
import { AppEvents } from '@grafana/data';
import { getAppEvents } from '@grafana/runtime';
const appEvents = getAppEvents();
appEvents.publish({
type: AppEvents.alertSuccess.name,
payload: [text + ': ' + resp.status + ' (' + resp.statusText + ')'],
});
- Do not use this component directly. Instead, emit the `appEvent` to trigger it's appearance.
- To convey general confirmation or non-critical actions.
- Immediately after an event is taken, such as a permission is updated or some Dashboards are imported or deleted.
- Status according to use cases:
- *Success*: When any action is successful, it is confirmed when a task is completed as expected.
- *Warning*: It is used to report a current status that users should be aware of or that could have serious consequences.
- *Error*: Inform users of an error, and sometimes provide more information about how to fix the error.
- Slide in and out from the top right corner of the page.
<Alert title={title} severity={severity} onRemove={onRemove} elevated>
Child content that includes some alert details, like maybe what actually happened.
</Alert>