Alert

free

Alert keeps important feedback visible near the workflow it affects.

motion
Preview
Dark
Subscription updated
The new billing owner will receive future invoices and renewal notices.
import Alert from '@/components/ui/Alert';

export default function UsageDemo() {
  return (
    <div className="w-full max-w-md">
      <Alert showIcon variant="info" title="Subscription updated">
        The new billing owner will receive future invoices and renewal notices.
      </Alert>
    </div>
  );
}

Installation

Add this component with the NateUI CLI.

npx nateui@latest add Alert

Examples

Basic

Preview
Dark
Review the details before continuing.
import Alert from '@/components/ui/Alert';

export default function BasicDemo() {
  return (
    <div className="w-full max-w-md">
      <Alert>Review the details before continuing.</Alert>
    </div>
  );
}

Types

Preview
Dark
A new export is ready to download.
Your changes were saved successfully.
This plan is close to its seat limit.
This action cannot be undone.
import Alert from '@/components/ui/Alert';

const alerts = [
  {
    variant: 'info',
    message: 'A new export is ready to download.',
  },
  {
    variant: 'success',
    message: 'Your changes were saved successfully.',
  },
  {
    variant: 'warning',
    message: 'This plan is close to its seat limit.',
  },
  {
    variant: 'destructive',
    message: 'This action cannot be undone.',
  },
] as const;

export default function TypesDemo() {
  return (
    <div className="flex w-full max-w-md flex-col gap-4">
      {alerts.map((alert) => (
        <Alert key={alert.variant} showIcon variant={alert.variant}>
          {alert.message}
        </Alert>
      ))}
    </div>
  );
}

Icons

Preview
Dark
The alert can render without an icon.
Add `showIcon` to include the status icon.
import Alert from '@/components/ui/Alert';

export default function IconDemo() {
  return (
    <div className="flex w-full max-w-md flex-col gap-4">
      <Alert variant="info">The alert can render without an icon.</Alert>
      <Alert showIcon variant="info">
        Add `showIcon` to include the status icon.
      </Alert>
    </div>
  );
}

Custom Icon

Preview
Dark
Automation complete
The workflow ran successfully with the custom status icon.
import { PiSparkle } from 'react-icons/pi'
import Alert from '@/components/ui/Alert';

export default function CustomIconDemo() {
  return (
    <div className="w-full max-w-md">
      <Alert
        showIcon
        variant="success"
        customIcon={<PiSparkle />}
        title="Automation complete"
      >
        The workflow ran successfully with the custom status icon.
      </Alert>
    </div>
  );
}

Title

Preview
Dark
Seats almost full
Upgrade the workspace or remove unused members before inviting more people.
import Alert from '@/components/ui/Alert';

export default function TitleDemo() {
  return (
    <div className="w-full max-w-md">
      <Alert showIcon variant="warning" title="Seats almost full">
        Upgrade the workspace or remove unused members before inviting more people.
      </Alert>
    </div>
  );
}

Closable

Preview
Dark
Invite sent. Close this alert when you are done reviewing it.
import Alert from '@/components/ui/Alert';

export default function ClosableDemo() {
  return (
    <div className="w-full max-w-md">
      <Alert closable showIcon variant="success">
        Invite sent. Close this alert when you are done reviewing it.
      </Alert>
    </div>
  );
}

API

Alert accepts the props below plus motion-enabled props for the root div.

PropDescriptionTypeDefault
childrenMain alert message content.ReactNode-
classNameClass names applied to the root alert.string-
closableShows the close control and lets the alert fade when clicked.booleanfalse
customCloseReplaces the default close button content.ReactNode | string-
customIconReplaces the status icon when showIcon is enabled.ReactNode | string-
contentClassClass names applied to the inner content row.string-
durationDelay before the timeout helper calls onClose. Pass 0 to disable the scheduled callback.number3000
onCloseCalled when the close control is clicked, and by the timeout helper when enabled.AlertCloseHandler-
refRef forwarded to the root alert element.Ref<HTMLDivElement>-
showIconDisplays the status icon for the resolved variant.booleanfalse
titleOptional title rendered above the message.ReactNode | stringnull
triggerByToastToast integration flag accepted by the component prop type.boolean-
variantStatus palette used by the alert. Invalid values fall back to warning.AlertVariant'warning'
...motionDivPropsMotion-enabled props for the root alert element, excluding type and children.NativeAlertMotionProps-

Types

type AlertVariant = 'success' | 'warning' | 'destructive' | 'info';
type AlertCloseHandler = (event?: MouseEvent<HTMLDivElement>) => void;
type NativeAlertMotionProps = Omit<HTMLMotionProps<'div'>, 'type' | 'children'>;