Back to Prisma

Alert

apps/eclipse/content/design-system/components/alert.mdx

latest9.6 KB
Original Source

import { Alert } from "@prisma/eclipse";

Usage

Basic Alert

The Alert component displays important information with a default circle-exclamation icon and the PPG variant.

tsx
import { Alert } from "@prisma/eclipse";

export function BasicAlert() {
  return (
    <Alert>
      This is a basic alert message with regular content.
    </Alert>
  );
}
<div className="not-prose my-6"> <p className="text-sm font-semibold mb-4">Live Example:</p> </div> <Alert> This is a basic alert message with regular content. </Alert>

Alert Variants

The Alert component supports four variants: ppg, error, success, and warning.

tsx
import { Alert } from "@prisma/eclipse";

export function AlertVariants() {
  return (
    <>
      <Alert variant="ppg">
        PPG variant - for general information and tips.
      </Alert>

      <Alert variant="success">
        Success variant - for positive confirmations.
      </Alert>

      <Alert variant="warning">
        Warning variant - for important notices.
      </Alert>

      <Alert variant="error">
        Error variant - for errors and critical information.
      </Alert>
    </>
  );
}
<div className="not-prose my-6 space-y-4"> <p className="text-sm font-semibold mb-4">Live Examples:</p> <Alert variant="ppg"> PPG variant - for general information and tips. </Alert> <Alert variant="success"> Success variant - for positive confirmations. </Alert> <Alert variant="warning"> Warning variant - for important notices. </Alert> <Alert variant="error"> Error variant - for errors and critical information. </Alert> </div>

Custom Icons

You can customize the icon by passing a custom icon component or pass null to hide the icon.

tsx
import { Alert } from "@prisma/eclipse";

export function CustomIconAlerts() {
  return (
    <>
      <Alert variant="ppg" icon={<i className="fa-regular fa-terminal h-4 w-4 mt-0.5" />}>
        Alert with a custom terminal icon.
      </Alert>

      <Alert variant="error" icon={<i className="fa-regular fa-circle-exclamation h-4 w-4 mt-0.5" />}>
        Alert with a custom error icon.
      </Alert>

      <Alert variant="success" icon={<i className="fa-regular fa-check h-4 w-4 mt-0.5" />}>
        Alert with a custom success icon.
      </Alert>

      <Alert variant="warning" icon={<i className="fa-regular fa-triangle-exclamation h-4 w-4 mt-0.5" />}>
        Alert with a custom warning icon.
      </Alert>

      <Alert variant="ppg" icon={null}>
        Alert without an icon.
      </Alert>
    </>
  );
}
<div className="not-prose my-6 space-y-4"> <p className="text-sm font-semibold mb-4">Live Examples:</p> <Alert variant="ppg" icon={<i className="fa-regular fa-terminal h-4 w-4 mt-0.5" />}> Alert with a custom terminal icon. </Alert>
<Alert variant="error" icon={<i className="fa-regular fa-circle-exclamation h-4 w-4 mt-0.5" />}>
  Alert with a custom error icon.
</Alert>

<Alert variant="success" icon={<i className="fa-regular fa-check h-4 w-4 mt-0.5" />}>
  Alert with a custom success icon.
</Alert>

<Alert variant="warning" icon={<i className="fa-regular fa-triangle-exclamation h-4 w-4 mt-0.5" />}>
  Alert with a custom warning icon.
</Alert>

<Alert variant="ppg" icon={null}>
  Alert without an icon.
</Alert>
</div>

Rich MDX Content

The Alert component accepts and renders any MDX content including headings, paragraphs, lists, links, and code.

tsx
import { Alert } from "@prisma/eclipse";

export function RichContentAlert() {
  return (
    <Alert variant="ppg">
      **Getting Started**

      Follow these steps to get started:

      1. Install the package: `npm install @prisma/client`
      2. Initialize Prisma: `npx prisma init`
      3. Define your schema and run migrations

      For more information, visit the [documentation](https://prisma.io/docs).
    </Alert>
  );
}

:::ppg Getting Started

Follow these steps to get started:

  1. Install the package: npm install @prisma/client
  2. Initialize Prisma: npx prisma init
  3. Define your schema and run migrations

For more information, visit the documentation. :::

Complex Content Examples

tsx
import { Alert } from "@prisma/eclipse";

export function ComplexAlerts() {
  return (
    <>
      <Alert variant="warning">
        ### Important Update

        This feature will be deprecated in version 6.0. Please migrate to the new API:

        - Old: `prisma.user.findMany()`
        - New: `prisma.user.findMany({ where: {} })`
      </Alert>

      <Alert variant="error">
        **Connection Error**

        Unable to connect to the database. Please check:

        - Database credentials in `.env`
        - Database server is running
        - Network connectivity
      </Alert>

      <Alert variant="success">
        Your migration was successful! The following changes were applied:

        - Created table `User`
        - Added index on `email` column
        - Updated foreign key constraints
      </Alert>
    </>
  );
}
<div className="not-prose my-6 space-y-4"> <p className="text-sm font-semibold mb-4">Live Examples:</p> <Alert variant="warning"> <div> <h3 className="text-base font-semibold mb-2">Important Update</h3> <p className="mb-2">This feature will be deprecated in version 6.0. Please migrate to the new API:</p> <ul className="list-disc list-inside space-y-1"> <li>Old: <code>prisma.user.findMany()</code></li> <li>New: <code>prisma.user.findMany({`{ where: {} }`})</code></li> </ul> </div> </Alert> <Alert variant="error"> <div> <p className="font-bold mb-2">Connection Error</p> <p className="mb-2">Unable to connect to the database. Please check:</p> <ul className="list-disc list-inside space-y-1"> <li>Database credentials in <code>.env</code></li> <li>Database server is running</li> <li>Network connectivity</li> </ul> </div> </Alert> <Alert variant="success"> <div> <p className="mb-2">Your migration was successful! The following changes were applied:</p> <ul className="list-disc list-inside space-y-1"> <li>Created table <code>User</code></li> <li>Added index on <code>email</code> column</li> <li>Updated foreign key constraints</li> </ul> </div> </Alert> </div>

Alert Props

  • variant - Visual style: "ppg", "error", "success", or "warning" (optional, default: "ppg")
  • icon - Custom icon component or null to hide icon (ReactNode | null, optional, default: circle-exclamation icon)
  • className - Additional CSS classes (optional)
  • children - Alert content (any valid MDX/React content) (ReactNode, required)
  • Standard HTML div attributes

Features

  • ✅ Four semantic variants: ppg, error, success, warning
  • ✅ Default circle-exclamation icon with customization support
  • ✅ Accepts any MDX content (headings, paragraphs, lists, code, etc.)
  • ✅ Supports rich formatting and links
  • ✅ Accessible with proper ARIA roles
  • ✅ Dark mode support for all variants
  • ✅ Fully customizable with className prop
  • ✅ Built with class-variance-authority for type-safe variants

Best Practices

  • Use variant="ppg" for general information, tips, and product-specific notes
  • Use variant="success" for positive confirmations and successful operations
  • Use variant="warning" for important notices that require attention
  • Use variant="error" for errors, failures, and critical information
  • Choose icons that match the message type and variant
  • Pass icon={null} if the message is self-explanatory without an icon
  • Use headings (##, ###) to structure complex alert content
  • Include actionable information or next steps when appropriate
  • Keep alerts concise but informative
  • Don't overuse alerts - reserve them for important information

Common Use Cases

The Alert component is perfect for:

  • Documentation callouts - Highlight important information in docs
  • Feature announcements - Announce new or beta features
  • Deprecation notices - Warn about deprecated features
  • Prerequisites - List requirements before proceeding
  • Success confirmations - Confirm successful actions or operations
  • Error messages - Display error details and troubleshooting steps
  • Warning messages - Alert users to important considerations
  • Tips and notes - Provide helpful tips and additional context

MDX Alert Syntax

This Alert component is automatically used for MDX alert blocks when configured in your MDX components. The following syntaxes are supported:

mdx
:::ppg
This is a PPG alert using MDX alert syntax.

## You can use any MDX content

Including lists, code, and more!
:::

:::error
This is an error alert.
:::

:::success
This is a success alert.
:::

:::warning
This is a warning alert.
:::

:::info
Maps to PPG variant.
:::

:::note
Maps to PPG variant.
:::

:::tip
Maps to success variant.
:::

:::danger
Maps to error variant.
:::
<div className="not-prose my-6 space-y-4"> <p className="text-sm font-semibold mb-4">Live Example:</p> </div>

:::ppg

This demonstrates how the :::ppg syntax renders as an Alert component.

You can include:

  • Lists
  • Bold text
  • inline code
  • And more!

:::

Accessibility

  • The Alert component includes role="alert" for screen readers
  • Icons are decorative and don't convey meaning alone - always include descriptive text
  • Color is not the only indicator of alert type (icons and context provide additional cues)
  • All variants maintain appropriate color contrast ratios
  • Alert content is keyboard accessible and screen reader friendly