Blueprint

Alert

Alert displays an inline, persistent, message to convey the status of an action or feature.

React

Alert composes Chakra's Alert component and is available in five status to indicate the type of event that triggered it.

live

<Stack direction="column" spacing="400">
<Alert status="info">An informational alert</Alert>
<Alert status="warning">An alert that serves as a warning</Alert>
<Alert status="error">An alert indicating an error</Alert>
<Alert status="success">A successful alert</Alert>
<Alert status="loading">A pending alert</Alert>
</Stack>

Icon

The icon defaults to visible, pass showIcon={false} to hide it.

live

<Stack direction="column" spacing="400">
<Alert>An informational alert</Alert>
<Alert showIcon={false}>An informational alert with no icon</Alert>
</Stack>

Size

A smaller alert is available by setting size to small. The smaller size works well inline in forms.

live

<Stack direction="column" spacing="400">
<Alert status="error">Something broke</Alert>
<Alert status="error" size="small">
Incorrect username or password
</Alert>
</Stack>

Confirmation

Optionally, pass onConfirmClick to display a button for triggering an action associated with the Alert.

live

<Stack direction="column" spacing="400">
<Alert
onConfirmClick={() => alert('✅')}
status="warning"
title="Something happened!"
>
You should confirm it because of these details
</Alert>
<Alert
onCloseClick={() => alert('💨')}
onConfirmClick={() => alert('✅')}
status="warning"
title="Something happened!"
>
You should confirm it because of these details (or close it)
</Alert>
<Divider />
<Alert
confirmText="Try Again"
onConfirmClick={() => alert('♻️')}
size="small"
status="error"
title="Something broke!"
>
You should try this instead because of these details
</Alert>
<Alert
confirmText="Try Again"
onCloseClick={() => alert('💨')}
onConfirmClick={() => alert('♻️')}
size="small"
status="error"
title="Something broke!"
>
You should try this instead because of these details (or close it)
</Alert>
</Stack>

Close

Pass onCloseClick to enable the close button. Actually hiding the Alert requires wiring up some state.

live

() => {
const [isOpen, { off }] = useBoolean(true);
return (
<Stack direction="column" spacing="400">
<Alert onCloseClick={() => alert('💨')}>I have a close button</Alert>
<Alert
onCloseClick={() => alert('💨')}
title="I have a title and a close button"
>
Here's why you might <em>not</em> want to close me
</Alert>
<Divider />
{isOpen ? (
<Alert onCloseClick={off}>
I have a close button <em>and</em> you can close me
</Alert>
) : (
<Panel bg="transparent" textAlign="center">
Poof 💨
</Panel>
)}
</Stack>
);
};

Loading

Set status to loading to display a pending state while something is processing. Usually this would be followed by an Alert with the proper status to indicate the result of the action.

live

<Stack direction="column" spacing="400">
<Alert status="loading">A pending alert</Alert>
<Alert status="loading" onConfirmClick={() => {}}>
Confirm button is disabled
</Alert>
<Alert
onConfirmClick={() => {}}
onCloseClick={() => alert('💨')}
size="small"
status="loading"
title="Processing"
>
Details about what's processing
</Alert>
</Stack>

Bootstrap

Add the .alert and .alert-[status] classes to a container to display an Alert. See Bootstrap's Alert documentation for more information.

live

<div class="vstack gap-400">
<div class="alert alert-info mb-0" role="alert">An informational alert</div>
<div class="alert alert-warning mb-0" role="alert">
An alert that serves as a warning
</div>
<div class="alert alert-danger mb-0" role="alert">
An alert indicating an error
</div>
<div class="alert alert-success mb-0" role="alert">A successful alert</div>
<div class="alert alert-light mb-0" role="alert">A neutral alert</div>
</div>

Close

live

<div class="vstack gap-400">
<div class="alert alert-info alert-dismissible with-icon mb-0" role="alert">
<svg
class="icon icon-medium text-primary-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-alert-circle" />
</svg>
<span>I have a close button</span>
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
<div
class="alert alert-small alert-info alert-dismissible with-icon mb-0"
role="alert"
>
<svg
class="icon icon-small text-primary-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-alert-circle" />
</svg>
<span>I'm smaller and also have a close button</span>
<button type="button" class="btn-close" aria-label="Close"></button>
</div>
</div>

Icons

Icons must be added manually for Bootstrap, see the icons page for details.

live

<div class="vstack gap-400">
<div class="alert alert-info with-icon mb-0" role="alert">
<svg
class="icon icon-medium text-primary-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-info" />
</svg>
<span>An informational alert</span>
</div>
<div class="alert alert-warning with-icon mb-0" role="alert">
<svg
class="icon icon-medium text-warning-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-alert-circle" />
</svg>
<span>An alert that serves as a warning</span>
</div>
<div class="alert alert-danger with-icon mb-0" role="alert">
<svg
class="icon icon-medium text-danger-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-alert-circle" />
</svg>
<span>An alert indicating an error</span>
</div>
<div class="alert alert-success with-icon mb-0" role="alert">
<svg
class="icon icon-medium text-success-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-check-circle" />
</svg>
<span>A successful alert</span>
</div>
<div class="alert alert-light with-icon mb-0" role="alert">
<svg
class="icon icon-medium text-neutral-500 m-0 spin-500"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#h-loader" />
</svg>
<span>A pending alert</span>
</div>
</div>

Size

A smaller alert is available by adding the .alert-small class. The smaller size works well inline in forms.

live

<div class="vstack gap-400">
<div class="alert alert-danger with-icon mb-0" role="alert">
<svg
class="icon icon-medium text-danger-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-alert-circle" />
</svg>
<span>Something broke</span>
</div>
<div class="alert alert-small alert-danger with-icon mb-0" role="alert">
<svg
class="icon icon-small text-danger-base m-0"
xmlns="http://www.w3.org/2000/svg"
>
<use xlink:href="/icons/all.svg#i-alert-circle" />
</svg>
<span>Something broke</span>
</div>
</div>