# Alert

An inline notice board with a glyph, a title and a line of detail.

Docs: https://cozy-ui.solo.engineer/docs/components/alert/

Install: `npx shadcn@latest add @cozy/alert`

### Usage

```tsx
import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"
```

### Props

| Prop | Type | Default | Description |
|---|---|---|---|
| variant | `"default" \| "success" \| "info" \| "destructive"` | `"default"` | Tint and glyph colour. |

### Example

```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { InfoGlyph, RainGlyph, RiceGlyph, CloseGlyph } from "@/components/ui/glyphs";

export default function AlertDemo() {
  return (
    <div className="grid w-full max-w-md gap-3">
      <Alert><InfoGlyph /><AlertTitle>Market day tomorrow</AlertTitle><AlertDescription>Prices for bananas go up by 10%.</AlertDescription></Alert>
      <Alert variant="success"><RiceGlyph /><AlertTitle>Good harvest</AlertTitle><AlertDescription>Your paddies produced 20% more grain this season.</AlertDescription></Alert>
      <Alert variant="info"><RainGlyph /><AlertTitle>Rain this afternoon</AlertTitle><AlertDescription>Bring the drying rice inside before 3 pm.</AlertDescription></Alert>
      <Alert variant="destructive"><CloseGlyph /><AlertTitle>Couldn’t save</AlertTitle><AlertDescription>You’re offline. We’ll try again when you’re back.</AlertDescription></Alert>
    </div>
  );
}
```

### Source (components/ui/alert.tsx)

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

const alertVariants = cva("cz-alert", {
  variants: {
    variant: { default: "", success: "cz-alert--success", info: "cz-alert--info", destructive: "cz-alert--destructive" },
  },
  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("cz-alert__title", className)} {...props} />;
}
function AlertDescription({ className, ...props }: React.ComponentProps<"div">) {
  return <div data-slot="alert-description" className={cn("cz-alert__description", className)} {...props} />;
}

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

npm: `import { Alert, AlertTitle, AlertDescription } from "@0xtrou/cozy-ui"` (after `npm install @0xtrou/cozy-ui` and `import "@0xtrou/cozy-ui/styles.css"`).
