Theme

PlaygroundBeta

npm_versionnpm Paragon package page

Alert

The Alert component displays a short, important message in a way that attracts the user's attention. Alerts offer four severity levels that set a distinctive icon and color:

  • Info: used to convey general information or actions that aren't critical, note that info variant should not contain any icons in it
  • Warning: used to display information that needs attention
  • Success: used for success messages
  • Danger: used to communicate problems that have to be resolved immediately

This component utilizes and extends the Alert component from react-bootstrap.
See React-Bootstrap for additional documentation.

Basic Usage

Any Paragon component or export may be added to the code example.

<>
<Alert variant="success">
This is a "success" alert with{' '}
<Alert.Link href="#">an example link</Alert.Link>. Give it a click if you
like.
</Alert>
<Alert variant="info">
This is a "info" alert with{' '}
<Alert.Link href="#">an example link</Alert.Link>. Give it a click if you
like.
</Alert>
<Alert variant="danger">
This is a "danger" alert with{' '}
<Alert.Link href="#">an example link</Alert.Link>. Give it a click if you
like.
</Alert>
<Alert variant="warning">
This is a "warning" alert with{' '}
<Alert.Link href="#">an example link</Alert.Link>. Give it a click if you
like.
</Alert>
</>

With Action Buttons

The Alert component supports a dismissible button and a custom call-to-action button, via the dismissible and button props respectively. The buttons may be right aligned or stacked. On extra small screen widths, the buttons will be stacked.

The stacked variant should be used for:

  • Placement in sidebars or small container
  • Extra-small breakpoint and below

Any Paragon component or export may be added to the code example.

<>
<Alert
variant="info"
actions={[
<Button>Hello</Button>,
]}
dismissible
closeLabel="Dismiss"
onClose={(e) => { console.log('closed', e); } }
>
This is a "info" alert with{' '}
<Alert.Link href="#">an example link</Alert.Link>. Give it a click if you
like.
</Alert>
<Alert variant="warning" dismissible>
This is a "info" alert with{' '}
<Alert.Link href="#">an example link</Alert.Link>. Give it a click if you
like.
</Alert>
<Alert
variant="success"
icon={CheckCircle}
dismissible
actions={[
<Button>Hello</Button>,
]}
>
<Alert.Heading>Hey, nice to see you</Alert.Heading>
<p>
Aww yeah, you successfully read this important alert message. This example
text is going to run a bit longer so that you can see how spacing within an
alert works with this kind of content.
</p>
</Alert>
<Alert
variant="danger"
icon={Info}
actions={[
<Button>Hello</Button>,
]}
dismissible
onClose={(e) => { console.log('closed', e); } }
stacked
>
<Alert.Heading>Hey, nice to see you</Alert.Heading>
<p>
Aww yeah, you successfully read this important alert message. This example
text is going to run a bit longer so that you can see how spacing within an
alert works with this kind of content.
</p>
</Alert>
</>

Variants

Any Paragon component or export may be added to the code example.

<>
<Alert variant="success" dismissible icon={CheckCircle}>
<Alert.Heading>Hey, nice to see you</Alert.Heading>
<p>
Aww yeah, you successfully read this important alert message. This example
text is going to run a bit longer so that you can see how spacing within an
alert works with this kind of content.
</p>
</Alert>
<Alert variant="warning" dismissible icon={WarningFilled}>
<Alert.Heading>Hey, nice to see you</Alert.Heading>
<p>
Aww yeah, you successfully read this important alert message. This example
text is going to run a bit longer so that you can see how spacing within an
alert works with this kind of content.
</p>
</Alert>
<Alert variant="danger" dismissible icon={Info}>
<Alert.Heading>Hey, nice to see you</Alert.Heading>
<p>
Aww yeah, you successfully read this important alert message. This example
text is going to run a bit longer so that you can see how spacing within an
alert works with this kind of content.
</p>
</Alert>
</>

Kitchen Sink

Any Paragon component or export may be added to the code example.

<Alert
variant="success"
actions={[
<Button>Hello</Button>
]}
dismissible
stacked
>
<Alert.Heading>Hey, nice to see you</Alert.Heading>
<p>
Aww yeah, you successfully read this important alert message. This example
text is going to run a bit longer so that you can see how spacing within an
alert works with this kind of content.
</p>
<hr />
<p className="mb-0">
Whenever you need to, be sure to use margin utilities to keep things nice
and tidy.
</p>
</Alert>

Theme Variables (SCSS)#

$alert-padding-y: 1.5rem !default;
$alert-padding-x: 1.5rem !default;
$alert-margin-bottom: 1rem !default;
$alert-border-radius: $border-radius !default;
$alert-link-font-weight: $font-weight-normal !default;
$alert-border-width: 0 !default;
$alert-title-color: #000000 !default;
$alert-box-shadow: 0 1px 2px rgba(0, 0, 0, .15), 0 1px 4px rgba(0, 0, 0, .15) !default;
$alert-bg-level: -10 !default;
$alert-border-level: -9 !default;
$alert-color-level: 6 !default;
$alert-icon-space: .8rem !default;
$alert-font-size: .875rem !default;
$alert-line-height: 1.5rem !default;
$alert-content-color: $gray-700 !default;
$alert-actions-gap: map-get($spacers, 3);

Props API#

Alert Props API
  • children node

    Docstring for the children prop

  • icon func

    Docstring for the icon prop... Icon that will be shown in the alert

  • show bool

    Whether the alert is shown.

    Defaulttrue
  • dismissible bool

    Whether the alert is dismissible. Defaults to true.

    Defaultfalse
  • onClose func

    Optional callback function for when the alert it dismissed.

    Default() => {}
  • actions element[]

    Optional list of action elements. May include, at most, 2 actions, or 1 if dismissible is true.

  • stacked bool

    Position of the dismiss and call-to-action buttons. Defaults to false.

    Defaultfalse
  • closeLabel string | element

    Sets the text for alert close button, defaults to 'Dismiss'.

AlertHeading Props API
  • as elementType

    Specifies the base element

    DefaultdivWithClassName('h4')
  • bsPrefix string

    Overrides underlying component base CSS class name

    Default'alert-heading'

Usage Insights#

Alert

Project NameParagon VersionInstance Count
credentials19.19.17
edx-ora220.9.22
frontend-app-account20.36.08
frontend-app-admin-portal20.26.344
frontend-app-authn20.36.29
frontend-app-communications20.30.13
frontend-app-course-authoring20.32.012
frontend-app-discussions20.15.03
frontend-app-ecommerce20.35.01
frontend-app-enterprise-public-catalog20.29.02
frontend-app-gradebook19.25.45
frontend-app-learner-dashboard20.32.04
frontend-app-learner-portal-enterprise20.36.021
frontend-app-learner-portal-programs20.28.45
frontend-app-learner-record20.32.04
frontend-app-learning20.28.423
frontend-app-library-authoring20.30.17
frontend-app-ora-grading20.30.05
frontend-app-payment20.30.11
frontend-app-profile20.32.05
frontend-app-program-console20.32.05
frontend-app-publisher20.28.525
frontend-app-support-tools20.26.014
frontend-lib-content-components20.34.05
frontend-lib-special-exams20.22.44
prospectus20.32.32

AlertHeading

Project NameParagon VersionInstance Count
credentials19.19.16
frontend-app-account20.36.02
frontend-app-admin-portal20.26.332
frontend-app-authn20.36.28
frontend-app-communications20.30.11
frontend-app-course-authoring20.32.01
frontend-app-ecommerce20.35.01
frontend-app-enterprise-public-catalog20.29.01
frontend-app-learner-portal-enterprise20.36.04
frontend-app-learner-record20.32.02
frontend-app-learning20.28.43
frontend-app-library-authoring20.30.11
frontend-app-ora-grading20.30.04
frontend-app-profile20.32.03
frontend-app-publisher20.28.54
frontend-lib-content-components20.34.02
frontend-lib-special-exams20.22.42

AlertLink

Project NameParagon VersionInstance Count
frontend-app-account20.36.01
frontend-app-authn20.36.24
frontend-app-course-authoring20.32.010
frontend-app-enterprise-public-catalog20.29.01
frontend-app-learner-portal-enterprise20.36.02
frontend-app-learner-portal-programs20.28.41
frontend-app-profile20.32.01
frontend-lib-special-exams20.22.43