# Alert: Controlled

> Pass `open` and `onOpenChange` to drive it from your own state. It animates both in and out.

Example: https://hextaui.com/docs/alert/examples/controlled
Component docs: https://hextaui.com/docs/alert.md

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/alert-controlled.json
```

This adds `components/examples/alert/controlled.tsx` with the Alert component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/alert/controlled.tsx"
"use client"

import * as React from "react"
import { IconCircleCheck } from "@tabler/icons-react"

import {
  Alert,
  AlertClose,
  AlertDescription,
  AlertTitle,
} from "@/components/ui/alert"
import { Button } from "@/components/ui/button"

export function AlertControlled() {
  const [open, setOpen] = React.useState(true)

  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <Button
        variant="outline"
        size="sm"
        className="self-start"
        onClick={() => setOpen(!open)}
      >
        {open ? "Hide" : "Show"} alert
      </Button>
      <Alert variant="success" open={open} onOpenChange={setOpen}>
        <IconCircleCheck />
        <AlertTitle>Deployment complete</AlertTitle>
        <AlertDescription>
          Your changes are live on production.
        </AlertDescription>
        <AlertClose />
      </Alert>
      <p className="text-sm text-muted-foreground">Content below slides up.</p>
    </div>
  )
}
```

## Props in this example

### Alert

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"default" \| "destructive" \| "success" \| "info" \| "warning"` | `"default"` | Colors the icon. destructive and warning are announced assertively. |
| `open` | `boolean` | – |  |
| `onOpenChange` | `(open: boolean) => void` | – | Called when the close button is pressed. |

## More Alert examples

- [Variants](https://hextaui.com/docs/alert/examples/variants.md)
- [Soft](https://hextaui.com/docs/alert/examples/soft.md)
- [Partial content](https://hextaui.com/docs/alert/examples/partial-content.md)
- [Actions](https://hextaui.com/docs/alert/examples/actions.md)
- [Dismissible](https://hextaui.com/docs/alert/examples/dismissible.md)
- [Cancel a dismiss](https://hextaui.com/docs/alert/examples/cancel-dismiss.md)
- [Inserted after load](https://hextaui.com/docs/alert/examples/inserted.md)
- [Rich content](https://hextaui.com/docs/alert/examples/rich-content.md)
- [Right to left](https://hextaui.com/docs/alert/examples/rtl.md)
