Alert

Alerts are used to indicate user-driven notifications.


React Component

Alert colors

Alerts can be implemented in a few different colors. These also determine the icon that will appear by default.

A default alert

Make sure you know how these changes affect you.

An informative alert

Make sure you know how these changes affect you.

An informative alert

Make sure you know how these changes affect you.

Uh, oh! Here's a warning alert

Make sure you know how these changes affect you.

Look out! This alert means there's an error

Make sure you know how these changes affect you.

Alert actions

Alerts can include buttons and links for users to take further action. These include a single primary action button and one or more additional secondary actions.

  • The primary action implements a single hash that allows value and attributes similar to SageButton.
  • The secondary actions implements an array of hashes that each allow a value and a url.

Alert with all actions

Make sure you know how these changes affect you.

Dismissable Alerts

Alerts can be implemented in a few different colors. These also determine the icon that will appear by default.

Alerts emit a custom event, sage.alert.dismiss when the dismiss button is clicked. You can listen for this event as it bubbles and respond as you see fit.

This nifty alert can be dismissed

Make sure you know how these changes affect you.

Small Alerts

The small variant of Alert can be used for smaller spaces or a more minimal presence. They support all other properties with the exception of primary_action; only secondary_actions are allowed.

Make sure you know how these changes affect you.

Sage Component

SageAlert
<%
  sage_link = sage_component(SageLink, {
    url: "#",
    label: "Link",
    launch: false,
    help_link: false,
    show_label: true,
    style: "secondary",
    remove_underline: true,
  })
  demo_description =  "Make sure you know how these changes affect you."
  demo_primary_action = {
    value: "Primary action",
    attributes: {
      href: "#href-for-primary-action"
    },
  }
%>

<%= md("
### Alert colors

Alerts can be implemented in a few different colors.
These also determine the icon that will appear by default.
", use_sage_type: true) %>
<%= sage_component SageAlert, {
  color: "default",
  title: "A default alert",
  desc: demo_description,
  icon_name: "sage-icon-info-circle-filled",
  primary_action: demo_primary_action,
} %>
<%= sage_component SageAlert, {
  color: "info",
  title: "An informative alert",
  desc: demo_description,
  icon_name: "sage-icon-info-circle-filled",
  primary_action: demo_primary_action,
} %>
<%= sage_component SageAlert, {
  color: "success",
  title: "An informative alert",
  desc: demo_description,
  icon_name: "sage-icon-check-circle-filled",
  primary_action: demo_primary_action,
} %>
<%= sage_component SageAlert, {
  color: "warning",
  title: "Uh, oh! Here's a warning alert",
  desc: demo_description,
  icon_name: "sage-icon-danger-filled",
  primary_action: demo_primary_action,
} %>
<%= sage_component SageAlert, {
  color: "danger",
  title: "Look out! This alert means there's an error",
  desc: demo_description,
  icon_name: "sage-icon-warning-filled",
  primary_action: demo_primary_action,
} %>

<%= md("
### Alert actions

Alerts can include buttons and links for users to take further action.
These include a single primary action button and one or more additional secondary actions.

- The primary action implements a single hash that allows `value` and `attributes` similar to SageButton.
- The secondary actions implements an array of hashes that each allow a `value` and a `url`.
", use_sage_type: true) %>
<%= sage_component SageAlert, {
  color: "published",
  title: "Alert with all actions",
  desc: demo_description,
  icon_name: "sage-icon-check-circle-filled",
  primary_action: demo_primary_action,
  secondary_actions: [
    {
      value: "Link 1",
      url: "#href-for-link-1"
    },
    {
      value: "Link 2",
      url: "#href-for-link-1"
    },
  ],
} %>


<%= md("
### Dismissable Alerts

Alerts can be implemented in a few different colors.
These also determine the icon that will appear by default.

Alerts emit a custom event, `sage.alert.dismiss` when the dismiss button is clicked.
You can listen for this event as it bubbles and respond as you see fit.
", use_sage_type: true) %>
<%= sage_component SageAlert, {
  color: "info",
  title: "This nifty alert can be dismissed",
  desc: demo_description,
  dismissable: true,
  icon_name: "sage-icon-info-circle-filled",
  primary_action: demo_primary_action,
} %>

<%= md("
### Small Alerts

The `small` variant of Alert can be used for smaller spaces or a more minimal presence.
They support all other properties with the exception of `primary_action`; only `secondary_actions` are allowed.
", use_sage_type: true) %>

<%= sage_component SageAlert, {
  color: "default",
  desc: demo_description,
  small: true,
  dismissable: true,
  icon_name: "sage-icon-info-circle-filled",
  secondary_actions: [
    {
      value: "Link 1",
      url: "#href-for-link-1"
    },
    {
      value: "Link 2",
      url: "#href-for-link-1"
    },
  ],
} %>


<script>
(function() {
  window.addEventListener("sage.alert.dismiss", function (evt) {
    console.log("local dismiss click", evt);
  });
})();
</script>
Property Description Type Default

color

Applies a color theme and a corresponding default icon.

"default", "info", "success", "warning", "danger", "approaching", "exceeded", "reached"

"default"

desc

Description text to be displayed.

String

nil

dismissable

Adds close icon and functionality to allow alert to be closed.

Boolean

nil

icon_name

Icon defaults are provided. Icons can also be customized with this property.

String

See Sage Icons.

primary_action

Creates a primary action for the alert. See SageButton.

primary_action: {
  value: String,
  test_id: String,
  attributes: Hash,
}

nil

secondary_actions

An array of optional secondary actions. See SageLink.

Array<{
  value: String,
  url: String,
}>

nil

small

This property allows for a small variation of the Alert component. Per design specs, do not include a title, title_addon, or any actions.

Boolean

false

title

Title text to be displayed.

String

nil

title_addon

Allows text to be displayed along side the title, in body-small type spec.

String

nil

Sections

Element

sage_alert_actions

This area holds additional action links for the component. This should be used only if more than a primary and secondary button is needed. See properties primary_action and secondary_action.

link_to(s)

Events
Global/window events

sage.alert.dismiss

Fires when an alert's dismiss button is clicked.

Do
  • Use the primary_action property to create a custom button that aligns with design specs.

Don't
  • For small Alerts, do not include a title, title_addon, or any actions: primary_actions, secondary_actions, or content_for.

  • Do not use the content_for :sage_alert_actions unless needing 3 or more Alert actions.