Alert API
Import
Section titled “Import”import { Alert } from '@cimpress-ui/react';Accessibility notes
Section titled “Accessibility notes”Alert follows the ARIA alert pattern.
Alerts cannot contain interactive content.
Alerts should be rendered dynamically after the initial page load. Alerts that are present on the page before page load completes will not be announced by most screen readers.
Use alerts infrequently to minimize disruption to the user’s workflow.
Don’t remove alerts automatically after a timeout. Use the built-in dismissal feature if you want users to be able to dismiss the alert.
Dismissing alerts
Section titled “Dismissing alerts”Alerts can optionally be dismissed by the users. To enable this, pass an isDismissible prop to the alert component.
import { Alert, Button, Stack } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [isAlertOpen, setIsAlertOpen] = useState(false);
return ( <Stack gap={16}> <Button onPress={() => setIsAlertOpen(true)}>Show dismissible alert</Button>
{isAlertOpen && ( <Alert tone="info" title="Dismissal example" isDismissible onDismiss={() => setIsAlertOpen(false)}> This alert can be dismissed. </Alert> )} </Stack> );}API reference
Section titled “API reference”Displays an inline message banner in response to a user action.
- Ref<HTMLDivElement>
-
The
reftype for this component.
AlertProps
- StringLikeChildren
children *
Section titled “ children * ” -
The content of the alert.
- 'success' | 'info' | 'warning' | 'critical'
tone *
Section titled “ tone * ” -
The tone of the alert.
- string
title
Section titled “ title ” -
The title of the alert.
- boolean
isDismissible
Section titled “ isDismissible ” - Defaults to false .
Whether the alert can be dismissed by the user.
- () => void
onDismiss
Section titled “ onDismiss ” -
Callback function to be called when the dismiss button is pressed. Makes the alert controlled.
- string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.