Skip to content

#Alert

The Alert component informs users of change in the underlying system; user interaction or a change in application state can surface the component.

Alert has three variations ensure it covers multiple interaction patterns: success, warning, and error.

#Usage

Import the Alert component into a React component in your project:

import {Alert} from 'hello-next-js'

Use Alert by passing children:

import React from 'react'
import {Alert} from 'hello-next-js'
export const MyComponent: React.FC<any> = () => {
return (
<div>
<p>Uh-oh<p>
<Alert>
<strong>Warning:</strong>
This is a cautionary alert.
</Alert>
</div>
)
}

#Variants

Alert comes with three variations, which are set via the variant property.

#Success

Use to signify a positive or successful interaction.

#Warning

Use to indicate bring awareness of a non-critical, potentially negative information. This is the default Alert.

#Error

Use to convey a negative or errorful interaction or state.

#Closeable

Pass an onClose property to the Alert to display a close button:

The Alert component has a focusButton method that will call HTMLElement.focus() on the button.

#Accessibility

The Alert component has a role="alert" property, which covers the WCAG requirement.

#Component API

#Props

NameTypeDefaultDescriptionRequired
onClose(event: MouseEvent<HTMLButtonElement, MouseEvent>) => void The Alert's close function. Passing this function will cause the Alert to render a close 'x' button.
variantAlertVariant 'warning'The Alert's appearance variation.

#Methods

No methods found