# Alert

shadcn alert as a 1-bit message box.

Source: https://www.ui95.dev/ui/alert

## Examples

```tsx
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
import { CheckGlyph, CloseGlyph } from "@/components/ui/pixel-glyphs"

import type { ShowcaseDemo } from "../types"

export const demo: ShowcaseDemo = {
  span: "wide",
  variants: [
    {
      label: "default",
      render: () => (
        <Alert>
          <AlertTitle>Disk check complete</AlertTitle>
          <AlertDescription>No bad sectors were found on drive C:.</AlertDescription>
        </Alert>
      ),
    },
    {
      label: "with icon",
      render: () => (
        <Alert>
          <CheckGlyph />
          <AlertTitle>Saved</AlertTitle>
          <AlertDescription>untitled.bmp was written to A:.</AlertDescription>
        </Alert>
      ),
    },
    {
      label: "destructive",
      render: () => (
        <Alert variant="destructive">
          <CloseGlyph />
          <AlertTitle>General protection fault</AlertTitle>
          <AlertDescription>The application performed an illegal operation.</AlertDescription>
        </Alert>
      ),
    },
    {
      label: "with action",
      render: () => (
        <Alert>
          <AlertTitle>Update ready</AlertTitle>
          <AlertDescription>Restart to finish installing.</AlertDescription>
          <AlertAction>
            <Button size="xs">Restart</Button>
          </AlertAction>
        </Alert>
      ),
    },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/alert.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn class-variance-authority
```

`components/ui/alert.tsx`

```tsx
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import * as React from "react"

const alertVariants = cva(
  "group/alert relative grid w-full gap-1 pixel-border border-border px-3 py-2.5 text-left text-xl leading-tight offset-shadow-2 has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-24 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-3 *:[svg]:row-span-2 *:[svg:not([class*='size-'])]:size-3.5",
  {
    variants: {
      variant: {
        default: "bg-card text-card-foreground",
        destructive:
          "bg-destructive text-card *:data-[slot=alert-description]:text-card",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
)

function Alert({
  className,
  variant,
  ...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
  return (
    <div
      data-slot="alert"
      role="alert"
      className={cn(alertVariants({ variant }), className)}
      {...props}
    />
  )
}

function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-title"
      className={cn(
        "font-pixel text-[16px] leading-none uppercase group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3",
        className
      )}
      {...props}
    />
  )
}

function AlertDescription({
  className,
  ...props
}: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-description"
      className={cn(
        "text-xl leading-tight text-balance md:text-pretty [&_a]:underline [&_a]:decoration-(length:--pixel) [&_a]:underline-offset-3 [&_p:not(:last-child)]:mb-4",
        className
      )}
      {...props}
    />
  )
}

function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="alert-action"
      className={cn("absolute top-2 right-2", className)}
      {...props}
    />
  )
}

export { Alert, AlertAction, AlertDescription, AlertTitle }
```

## API reference

### Alert

| Prop | Type | Default |
| --- | --- | --- |
| `variant` | `"default" \| "destructive"` | `"default"` |

### AlertAction

No props of its own. It forwards the props of the element or primitive it wraps.

### AlertDescription

No props of its own. It forwards the props of the element or primitive it wraps.

### AlertTitle

No props of its own. It forwards the props of the element or primitive it wraps.
