Alert

A message that tells the user something important, such as an error, a warning, or a success.

A new version is available

Usage

Code
import { Alert } from '@leverui/components';
Code
<Alert.Root>
  <Alert.Indicator />
  <Alert.Content>
    <Alert.Title />
    <Alert.Description />
  </Alert.Content>
</Alert.Root>

For a single component, see the snippet below.

Examples

Description

Render Alert.Description to provide additional context to the alert.

Check the form
Two fields are empty. Fill them in and try again.

Status

Set status to error, success, warning, or info to change the palette and indicator.

We could not process your payment
Maintenance starts on Sunday at 2 am
Your trial ends in three days. Upgrade to keep your projects.
Your files were uploaded

Variants

Use variant to change the visual style of the alert: subtle, solid, outline, or surface.

Your files were uploaded
Your files were uploaded
Your files were uploaded
Your files were uploaded

With Close Button

Here's an example of composing the Alert with a close button.

Booking confirmed
Your table for four is booked for Friday at 7 pm. We sent the details to your email address.

With Spinner

Here's an example of composing the Alert with a spinner.

Loading your files

Custom Icon

Pass a child to Alert.Indicator to override the default status icon.

Your session ends in five minutes

Color Palette Override

The default colorPalette is inferred from status. Pass colorPalette to override it.

This info alert uses the teal palette

Customization

Style the Alert parts with authored CSS classes and variables.

Spring sale: 20% off
Upgrade your plan this week to get the discount.
Upgrade
Heads up: the spring sale takes 20% off

Closed Component

One component that wraps the parts and takes props.

Code
import { omit } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Alert, type AlertRootBaseProps } from '@leverui/components';

type ClosedAlertProps = AlertRootBaseProps &
  Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children' | 'title'> & {
    title?: JSX.Element;
    children?: JSX.Element;
    icon?: JSX.Element;
    startElement?: JSX.Element;
    endElement?: JSX.Element;
  };

export function ClosedAlert(props: ClosedAlertProps) {
  const root = omit(props, 'title', 'children', 'icon', 'startElement', 'endElement');

  return (
    <Alert.Root {...root}>
      {props.startElement ?? <Alert.Indicator>{props.icon}</Alert.Indicator>}
      {props.children ? (
        <Alert.Content>
          <Alert.Title>{props.title}</Alert.Title>
          <Alert.Description>{props.children}</Alert.Description>
        </Alert.Content>
      ) : (
        <Alert.Title style={{ flex: '1' }}>{props.title}</Alert.Title>
      )}
      {props.endElement}
    </Alert.Root>
  );
}

Takes the alert's appearance props and any native div attribute. Import the Lever UI stylesheet once in your app.

Style the parts with CSS classes or --leverui-* variables.

Props

Root

PropDefaultTypeDescription
colorPaletteInferred from statusstringColor palette. Replaces the one from status.
status'info''info' | 'warning' | 'success' | 'error' | 'neutral' or responsive valuesKind of alert. Sets the default icon.
variant'subtle''subtle' | 'surface' | 'outline' | 'solid' or responsive valuesAlert style.
size'md''sm' | 'md' | 'lg' or responsive valuesAlert size. Changes spacing and text size.
inlinefalseboolean or responsive valuesPut the title and description on one row.
as'div'Native element tagHTML tag to render.
asChild—Solid render callbackRender your own element with the alert's props.
unstyledfalsebooleanTurn off the Lever UI styles.

No ARIA role by default. Add role="alert" for an urgent message, or role="status" for one that can wait.

Alert.PropsProvider sets a default look for the alerts inside it. The defaults are reactive.

Class names on the root and the parts are stable.

Explorer

Hover over a part name to highlight it. Click to keep it selected.

Update available
Restart the app to install the new version.

Component Anatomy

Hover to highlight, click to select parts