Documentation
Components
Alert

Alert

The Alert component displays a short message that attracts user's attention.

Usage

Basic Usage

import { Alert } from '@snipshot/particles';

export default function AlertDefault() {
  return (
    <Alert
      heading="Message sent"
      closeButtonLabel="Close alert"
      onClose={() => console.log('Close alert')}
    >
      Thank you, we will reply to you soon!
    </Alert>
  );
}

Colors

The color scheme of the Alert component also affects the default icon. There are four status colors: success, info, warning, and error, each of which has a corresponding informational icon.
In addition to these status colors, there are three base colors: primary, secondary, and tertiary. These last three color options use the info icon by default.

Variants

The Alert component comes with several variants to suit your design needs. Pass the variant prop with one of the values: 'filled', 'outlined', 'soft', or 'minimal'

Radiuses

You can choose from a one of the predefined border radius values by providing a radius prop value.

Action elements

In addition to the close button (or without it by default), you have the flexibility to include custom action elements on the right side of the Alert component:

Custom icons

The icon property lets ypu insert any icon or even emojis on the left side of the alert:

Accessibility

The Alert component prioritizes accessibility and adheres to best practices (opens in a new tab) to ensure that it can be used by all users. It achieves accessibility through the following key features:

  • Semantic HTML: The component is built using semantically structured HTML elements to ensure compatibility with screen readers and assistive technologies.
  • Role Attribute: By default, the role attribute is set to alert.
  • aria-labelledby: The aria-labelledby attribute is utilized, referencing the Alert component's heading.
  • aria-describedby: The aria-describedby attribute has a value of the Alert component's message text. This attribute offers additional context and information to assistive technologies.

API Reference

Alert component extends default <section> element props with the following props:

PropTypeDefaultDescription
actionElementReact.ReactNodeundefinedInteractive component on the right
closeButtonLabelstring'Close alert message'aria-label value for a close button
color'success' | 'info' | 'warning' | 'error' | 'primary' | 'secondary' | 'tertiary''success'Alert's color scheme
headingstring | React.ReactNodeundefinedAlert's message heading
headingPropsTextPropsundefinedText component properties for alert's heading
iconReact.ReactNode | booleantrueIcon component on the left
onClose() => voidundefinedonClick handler for a close button
radius'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'round' | 'none''sm'Border radius value
textPropsTextPropsundefinedText component properties for alert's message
variant'filled' | 'outlined' | 'soft' | 'minimal''soft'Styling variant