Alerts
Use the SuccessAlert
, ErrorAlert
, InfoAlert
, and WarningAlert
components to alert the user of some change in state.
For example, here are alerts for various outcomes of uploading a file:
To allow the user to hide the alert after reading it, set the dismissable
prop to add a clickable close icon:
To perform some action when the user dismisses an alert, set the onDismiss
prop:
Use the withIcon
prop to add an icon to the alert:
Alerts can contain any content. To have links within this content styled correctly, apply the pui-alert-link
class to any <a>
tag that appears inside the alert.
By default, alerts maintain their dismissed/not dismissed state internally. To hold this state at a higher level (in a parent component), pass the show
prop to the alert.
Props
The SuccessAlert
, ErrorAlert
, InfoAlert
, and WarningAlert
components all take the following props:
Property | Required | Type | Default | Description |
---|---|---|---|---|
closeLabel | no | Node | 'Close alert' | Screen reader label attached to close button |
dismissable | no | Boolean | false | If true, render a close button |
onDismiss | no | Function | Callback that is called when the user clicks the close button | |
show | no | Boolean | If set, overrides the close button. True shows the alert, false hides the alert. | |
withIcon | no | Boolean | false | If true, render alert with an icon |
Imports
Import React components (including CSS):
import {SuccessAlert, InfoAlert, WarningAlert, ErrorAlert} from 'pivotal-ui/react/alerts';
Import CSS only:
import 'pivotal-ui/css/alerts';