Alert
Display important messages and notifications to users with status indicators
Usage
import { Alert } from '@lenso/ui';"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Alert, Button, CloseButton, Spinner } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
export function Basic() { return ( <div {...stylex.props(s.alertStack)}> <Alert> <Alert.Indicator /> <Alert.Content> <Alert.Title>New features available</Alert.Title> <Alert.Description> Check out our latest updates including dark mode support and improved accessibility features. </Alert.Description> </Alert.Content> </Alert> <Alert status="accent"> <Alert.Indicator /> <Alert.Content> <Alert.Title>Update available</Alert.Title> <Alert.Description> A new version of the application is available. Please refresh to get the latest features and bug fixes. </Alert.Description> <Button xstyle={s.mobile2} size="sm" variant="primary"> Refresh </Button> </Alert.Content> <Button xstyle={s.desktopBlock} size="sm" variant="primary"> Refresh </Button> </Alert> <Alert status="danger"> <Alert.Indicator /> <Alert.Content> <Alert.Title>Unable to connect to server</Alert.Title> <Alert.Description> We're experiencing connection issues. Please try the following: <ul {...stylex.props(s.list)}> <li>Check your internet connection</li> <li {...stylex.props(s.space1)}>Refresh the page</li> <li {...stylex.props(s.space1)}>Clear your browser cache</li> </ul> </Alert.Description> <Button xstyle={s.mobile2} size="sm" variant="danger"> Retry </Button> </Alert.Content> <Button xstyle={s.desktopBlock} size="sm" variant="danger"> Retry </Button> </Alert> <Alert status="success"> <Alert.Indicator /> <Alert.Content> <Alert.Title>Profile updated successfully</Alert.Title> </Alert.Content> <CloseButton /> </Alert> <Alert status="accent"> <Alert.Indicator> <Spinner size="sm" /> </Alert.Indicator> <Alert.Content> <Alert.Title>Processing your request</Alert.Title> <Alert.Description> Please wait while we sync your data. This may take a few moments. </Alert.Description> </Alert.Content> </Alert> <Alert status="warning"> <Alert.Indicator /> <Alert.Content> <Alert.Title>Scheduled maintenance</Alert.Title> <Alert.Description> Our services will be unavailable on Sunday, March 15th from 2:00 AM to 6:00 AM UTC for scheduled maintenance. </Alert.Description> </Alert.Content> </Alert> </div> );}Local adaptation source above. Derived from HeroUI v3.2.6 source.
Anatomy
import { Alert } from '@lenso/ui';
export default () => ( <Alert> <Alert.Indicator /> <Alert.Content> <Alert.Title /> <Alert.Description /> </Alert.Content> </Alert>)Customization
Tailwind CSS
"use client";// Adapted from HeroUI v3.2.6 (e385ac202b2cdb94b1bf6fa76d32c31c8259cc5e), Apache-2.0.import { Alert, Button, CloseButton } from "@lenso/ui";import * as stylex from "@stylexjs/stylex";import { s } from "../card/display.stylex";
const styles = stylex.create({ alert: { position: "relative", overflow: "hidden", borderRadius: 12, borderWidth: 1, borderStyle: "solid", borderColor: { default: "color-mix(in oklab, var(--warning) 20%, transparent)", ':is([data-theme="dark"] *)': "color-mix(in oklab, var(--warning) 30%, transparent)", }, backgroundImage: { default: "linear-gradient(to bottom right in oklab, color-mix(in oklab, var(--warning) 10%, transparent), var(--surface), var(--surface-secondary))", ':is([data-theme="dark"] *)': "linear-gradient(to bottom right in oklab, color-mix(in oklab, var(--warning) 15%, transparent), var(--surface), color-mix(in oklab, var(--warning) 5%, transparent))", }, boxShadow: "0 1px 2px 0 rgb(0 0 0 / 0.05)", }, glow: { pointerEvents: "none", position: "absolute", top: -32, right: -32, width: 112, height: 112, borderRadius: 9999, backgroundColor: { default: "color-mix(in oklab, var(--warning) 15%, transparent)", ':is([data-theme="dark"] *)': "color-mix(in oklab, var(--warning) 25%, transparent)", }, filter: "blur(40px)", },});export function CustomStyles() { return ( <div {...stylex.props(s.maxXl)}> <Alert xstyle={styles.alert} status="warning"> <div aria-hidden="true" {...stylex.props(styles.glow)} /> <Alert.Indicator xstyle={[s.relative, s.warning]} /> <Alert.Content xstyle={s.relative}> <Alert.Title>Payment method expires soon</Alert.Title> <Alert.Description> Your Visa ending in 4242 expires on March 28. Update billing to avoid interrupting your Pro subscription. </Alert.Description> <Button xstyle={s.mobile3} size="sm" variant="tertiary"> Update billing </Button> </Alert.Content> <Button xstyle={s.desktopInline} size="sm" variant="tertiary"> Update billing </Button> <CloseButton xstyle={s.relative} /> </Alert> </div> );}Local adaptation source above. Derived from HeroUI v3.2.6 source.
Global CSS
To customize the Alert component classes, you can use the @layer components directive.
Learn more.
@layer components { .alert { @apply rounded-2xl shadow-lg; }
.alert__title { @apply font-bold text-lg; }
.alert--danger { @apply border-l-4 border-red-600; }}Styling Reference
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
CSS Classes
The Alert component uses these CSS classes (View source styles):
Base Classes [!toc]
.alert- Base alert container.alert__indicator- Icon/indicator container.alert__content- Content wrapper for title and description.alert__title- Alert title text.alert__description- Alert description text
Status Variant Classes [!toc]
.alert--default- Default gray status.alert--accent- Accent blue status.alert--success- Success green status.alert--warning- Warning yellow/orange status.alert--danger- Danger red status
Interactive States
The Alert component is primarily informational and doesn't have interactive states on the base component. However, it can contain interactive elements like buttons or close buttons.
API Reference
Alert
| Prop | Type | Default | Description |
|---|---|---|---|
status | "default" | "accent" | "success" | "warning" | "danger" | "default" | The visual status of the alert |
className | string | - | Additional CSS classes |
children | ReactNode | - | The alert content |
Alert.Indicator
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | ReactNode | - | Custom indicator icon (defaults to status icon) |
Alert.Content
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | ReactNode | - | Content (typically Title and Description) |
Alert.Title
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | ReactNode | - | The alert title text |
Alert.Description
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
children | ReactNode | - | The alert description text |