Alerts ​

The alert component provides a set of classes to highlight messages that readers need to see, such as a warning or a change that affects their next step.

Base classes ​

Wrap the message in .alert and put its main content in .alert-body. Use .alert-header with .alert-title for an optional title, and .alert-footer for a follow-up action or additional information.

To make an alert dismissible, add a button with the .alert-dismisser class and an accessible name. Once initialized, the alert can be dismissed by clicking the button or pressing Enter or Space while it has focus.

Initialization ​

Run the alert generator after the markup is in the DOM.

js
import generateAlerts from "@graupl/core/alert/generator";

generateAlerts();

The alert is visible by default. To start with the alert hidden, add .hide and set data-graupl-alert-options='{"expanded":false}' on the alert. The component uses .show, .hide, and .transitioning to manage visibility and transitions.

Note

For urgent messages that appear while someone is using the page, add role="alert" to the message text so assistive technology can announce it. See the WAI-ARIA alert pattern.

Variants ​

There are three alert variants provided by default. Add .primary, .secondary, or .tertiary alongside .alert.

If you are compiling your own version of Graupl, you can set the alert module’s $themeable variable to false to skip generating theme variants.

Custom Properties ​

The following custom properties can be used to customize the alert component:

PropertyDescriptionDefault Value
--graupl-alert-padding-xThe horizontal padding of the alert.var(--graupl-spacer-5)
--graupl-alert-padding-yThe vertical padding of the alert.var(--graupl-spacer-5)
--graupl-alert-paddingThe padding of the alert.var(--graupl-alert-padding-y) var(--graupl-alert-padding-x)
--graupl-alert-column-gapThe gap between alert columns.var(--graupl-spacer-0)
--graupl-alert-row-gapThe gap between alert rows.var(--graupl-spacer-3)
--graupl-alert-gapThe gap between alert rows and columns.var(--graupl-alert-row-gap) var(--graupl-alert-column-gap)
--graupl-alert-backgroundThe background of the alert.var(--graupl-background)
--graupl-alert-colorThe color of the alert.var(--graupl-color)
--graupl-alert-link-colorThe color of links in the alert.var(--graupl-link-color)
--graupl-alert-link-visited-colorThe color of visited links in the alert.var(--graupl-alert-link-color)
--graupl-alert-link-focus-colorThe color of focused links in the alert.var(--graupl-alert-link-color)
--graupl-alert-link-hover-colorThe color of hovered links in the alert.var(--graupl-link-hover-color)
--graupl-alert-link-active-colorThe color of active links in the alert.var(--graupl-alert-link-hover-color)
--graupl-alert-link-disabled-colorThe color of disabled links in the alert.var(--graupl-link-disabled-color)
--graupl-alert-link-text-decoration-colorThe text decoration color of links in the alert.var(--graupl-alert-link-color)
--graupl-alert-link-visited-text-decoration-colorThe text decoration color of visited links in the alert.var(--graupl-alert-link-visited-color)
--graupl-alert-link-focus-text-decoration-colorThe text decoration color of focused links in the alert.var(--graupl-alert-link-focus-color)
--graupl-alert-link-hover-text-decoration-colorThe text decoration color of hovered links in the alert.var(--graupl-alert-link-hover-color)
--graupl-alert-link-active-text-decoration-colorThe text decoration color of active links in the alert.var(--graupl-alert-link-active-color)
--graupl-alert-link-disabled-text-decoration-colorThe text decoration color of disabled links in the alert.var(--graupl-alert-link-disabled-color)
--graupl-alert-link-backgroundThe background of links in the alert.var(--graupl-link-background)
--graupl-alert-link-visited-backgroundThe background of visited links in the alert.var(--graupl-alert-link-background)
--graupl-alert-link-focus-backgroundThe background of focused links in the alert.var(--graupl-alert-link-background)
--graupl-alert-link-hover-backgroundThe background of hovered links in the alert.var(--graupl-link-hover-background)
--graupl-alert-link-active-backgroundThe background of active links in the alert.var(--graupl-alert-link-hover-background)
--graupl-alert-link-disabled-backgroundThe background of disabled links in the alert.var(--graupl-link-disabled-background)
--graupl-alert-link-border-colorThe border color of links in the alert.var(--graupl-link-border-color)
--graupl-alert-link-visited-border-colorThe border color of visited links in the alert.var(--graupl-alert-link-border-color)
--graupl-alert-link-focus-border-colorThe border color of focused links in the alert.var(--graupl-alert-link-border-color)
--graupl-alert-link-hover-border-colorThe border color of hovered links in the alert.var(--graupl-link-hover-border-color)
--graupl-alert-link-active-border-colorThe border color of active links in the alert.var(--graupl-alert-link-hover-border-color)
--graupl-alert-link-disabled-border-colorThe border color of disabled links in the alert.var(--graupl-link-disabled-border-color)
--graupl-alert-border-colorThe border color of the alert.var(--graupl-alert-color)
--graupl-alert-border-top-left-radiusThe border top left radius of the alert.var(--graupl-border-top-left-radius)
--graupl-alert-border-top-right-radiusThe border top right radius of the alert.var(--graupl-border-top-right-radius)
--graupl-alert-border-bottom-left-radiusThe border bottom left radius of the alert.var(--graupl-border-bottom-left-radius)
--graupl-alert-border-bottom-right-radiusThe border bottom right radius of the alert.var(--graupl-border-bottom-right-radius)
--graupl-alert-border-radiusThe border radius of the alert.var(--graupl-alert-border-top-left-radius) var(--graupl-alert-border-top-right-radius) var(--graupl-alert-border-bottom-right-radius) var(--graupl-alert-border-bottom-left-radius)
--graupl-alert-border-top-widthThe border top width of the alert.var(--graupl-border-top-width)
--graupl-alert-border-right-widthThe border right width of the alert.var(--graupl-border-right-width)
--graupl-alert-border-bottom-widthThe border bottom width of the alert.var(--graupl-border-bottom-width)
--graupl-alert-border-left-widthThe border left width of the alert.var(--graupl-border-left-width)
--graupl-alert-border-widthThe border width of the alert.var(--graupl-alert-border-top-width) var(--graupl-alert-border-right-width) var(--graupl-alert-border-bottom-width) var(--graupl-alert-border-left-width)
--graupl-alert-border-top-styleThe border top style of the alert.var(--graupl-border-top-style)
--graupl-alert-border-right-styleThe border right style of the alert.var(--graupl-border-right-style)
--graupl-alert-border-bottom-styleThe border bottom style of the alert.var(--graupl-border-bottom-style)
--graupl-alert-border-left-styleThe border left style of the alert.var(--graupl-border-left-style)
--graupl-alert-border-styleThe border style of the alert.var(--graupl-alert-border-top-style) var(--graupl-alert-border-right-style) var(--graupl-alert-border-bottom-style) var(--graupl-alert-border-left-style)
--graupl-alert-transitionThe transition of the alert.opacity var(--graupl-transition-duration-fast) var(--graupl-transition-timing-function), transform var(--graupl-transition-duration-fast) var(--graupl-transition-timing-function)
--graupl-alert-transition-reduced-motionThe alert transition when reduced motion is enabled.opacity var(--graupl-transition-duration-fast) var(--graupl-transition-timing-function)
--graupl-alert-header-padding-xThe horizontal padding of the alert header.0
--graupl-alert-header-padding-yThe vertical padding of the alert header.0
--graupl-alert-header-paddingThe padding of the alert header.var(--graupl-alert-header-padding-y) var(--graupl-alert-header-padding-x)
--graupl-alert-dismisser-border-colorThe border color of the alert dismiss button.transparent
--graupl-alert-dismisser-visited-border-colorThe border color of the visited alert dismiss button.var(--graupl-alert-dismisser-border-color)
--graupl-alert-dismisser-focus-border-colorThe border color of the focused alert dismiss button.var(--graupl-alert-dismisser-border-color)
--graupl-alert-dismisser-hover-border-colorThe border color of the hovered alert dismiss button.transparent
--graupl-alert-dismisser-active-border-colorThe border color of the active alert dismiss button.var(--graupl-alert-dismisser-hover-border-color)
--graupl-alert-dismisser-disabled-border-colorThe border color of the disabled alert dismiss button.transparent
--graupl-alert-dismisser-backgroundThe default background of the alert dismiss button.var(--graupl-alert-background)
--graupl-alert-dismisser-visited-backgroundThe background of the visited alert dismiss button.var(--graupl-alert-dismisser-background)
--graupl-alert-dismisser-focus-backgroundThe background of the focused alert dismiss button.var(--graupl-alert-dismisser-background)
--graupl-alert-dismisser-hover-backgroundThe background of the hovered alert dismiss button.var(--graupl-button-hover-background)
--graupl-alert-dismisser-active-backgroundThe background of the active alert dismiss button.var(--graupl-alert-dismisser-hover-background)
--graupl-alert-dismisser-disabled-backgroundThe background of the disabled alert dismiss button.var(--graupl-button-disabled-background)
--graupl-alert-dismisser-colorThe default text color of the alert dismiss button.var(--graupl-alert-color)
--graupl-alert-dismisser-visited-colorThe text color of the visited alert dismiss button.var(--graupl-alert-dismisser-color)
--graupl-alert-dismisser-focus-colorThe text color of the focused alert dismiss button.var(--graupl-alert-dismisser-color)
--graupl-alert-dismisser-hover-colorThe text color of the hovered alert dismiss button.var(--graupl-button-hover-color)
--graupl-alert-dismisser-active-colorThe text color of the active alert dismiss button.var(--graupl-alert-dismisser-hover-color)
--graupl-alert-dismisser-disabled-colorThe text color of the disabled alert dismiss button.var(--graupl-button-disabled-color)
--graupl-alert-title-colorThe color of the alert title.var(--graupl-alert-color)
--graupl-alert-title-font-sizeThe font size of the alert title.var(--graupl-h4-font-size)
--graupl-alert-title-font-weightThe font weight of the alert title.var(--graupl-h4-font-weight)
--graupl-alert-title-font-familyThe font family of the alert title.var(--graupl-h4-font-family)
--graupl-alert-title-line-heightThe line height of the alert title.var(--graupl-h4-line-height)
--graupl-alert-title-marginThe margin of the alert title.0 0 0 0
--graupl-alert-body-padding-xThe horizontal padding of the alert body.0
--graupl-alert-body-padding-yThe vertical padding of the alert body.0
--graupl-alert-body-paddingThe padding of the alert body.var(--graupl-alert-body-padding-y) var(--graupl-alert-body-padding-x)
--graupl-alert-footer-padding-xThe horizontal padding of the alert footer.0
--graupl-alert-footer-padding-yThe vertical padding of the alert footer.0
--graupl-alert-footer-paddingThe padding of the alert footer.var(--graupl-alert-footer-padding-y) var(--graupl-alert-footer-padding-x)

Sass variables ​

The following Sass variables can be used to customize the generation of the alert component:

VariableDescriptionDefault Value
$selector-baseThe selector base for the component."."
$modifier-selector-baseThe selector base for component modifiers."."
$generate-base-theme-mapWhether to include the default alert theme mappings.true
$themeableWhether to generate theme variants for alerts.true
$alert-selector-baseThe selector base for the alert selector-base."."
$alert-selectorThe selector for the alert selector."alert"
$alert-theme-selector-baseThe selector base for alert theme variants."."
$alert-theme-selector-prefixThe selector prefix for alert theme variants.""
$alert-body-selector-baseThe selector base for the alert body."."
$alert-body-selectorThe selector for the alert body."alert-body"
$alert-header-selector-baseThe selector base for the alert header."."
$alert-header-selectorThe selector for the alert header."alert-header"
$alert-footer-selector-baseThe selector base for the alert footer."."
$alert-footer-selectorThe selector for the alert footer."alert-footer"
$alert-title-selector-baseThe selector base for the alert title."."
$alert-title-selectorThe selector for the alert title."alert-title"
$alert-dismisser-selector-baseThe selector base for the dismiss button."."
$alert-dismisser-selectorThe selector for the dismiss button."alert-dismisser"
$alert-hidden-selector-baseThe selector base for the hidden state."."
$alert-hidden-selectorThe selector for the hidden state."hide"
$alert-shown-selector-baseThe selector base for the shown state."."
$alert-shown-selectorThe selector for the shown state."show"
$alert-transition-selector-baseThe selector base for the transition state."."
$alert-transition-selectorThe selector for the transition state."transitioning"
$alert-theme-mappingsMap of alert properties and their theme shades.map.merge($-alert-theme-mappings, $alert-theme-mappings)
$alert-theme-mapMap of CSS custom property values for each alert variant.map.deep-merge($-alert-theme-map, $alert-theme-map)