> Leaf UI 0.17.3 · Package: @ifhover/leaf-ui · Source: c3221834f84f2f48481a2054026b713456f8e5dc
> Browser documentation: https://ifhover.github.io/leaf-ui/en/components/alert.html

> For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt.

# Alert

Show operation results or information that needs attention within a page.


## Basic usage

Use `title` for the message and `description` for additional details.


A new version is available

Refresh the page to use it.

basic.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/alert/basic.tsx"
import { Alert } from '@ifhover/leaf-ui';

export function AlertBasic() {
  return <Alert title="A new version is available" description="Refresh the page to use it." />;
}
```

Expand code


## Examples

### Feedback types

Use `type` for information, success, warning or danger messages. Use `danger` in new code; `error` remains a compatibility alias.


Information

A new version is available

Success

Project saved

Warning

Storage is almost full

Danger

Save failed. Try again later.

types.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/alert/types.tsx"
import { Alert, Flex, Text } from '@ifhover/leaf-ui';

export function AlertTypes() {
  return (
    <Flex direction="column" gap="lg">
      <Flex direction="column" gap="sm">
        <Text tone="muted">Information</Text>
        <Alert type="info" title="A new version is available" />
      </Flex>
      <Flex direction="column" gap="sm">
        <Text tone="muted">Success</Text>
        <Alert type="success" title="Project saved" />
      </Flex>
      <Flex direction="column" gap="sm">
        <Text tone="muted">Warning</Text>
        <Alert type="warning" title="Storage is almost full" />
      </Flex>
      <Flex direction="column" gap="sm">
        <Text tone="muted">Danger</Text>
        <Alert type="danger" title="Save failed. Try again later." />
      </Flex>
    </Flex>
  );
}
```

Expand code

### Trailing content

Use `extra` for buttons, links or other elements on the right. It can be combined with `closable` and appears before the close button.


Your draft is saved

View details

extra.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/alert/extra.tsx"
import { Alert, Button } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function AlertExtra() {
  const [showDetails, setShowDetails] = useState(false);

  return (
    <Alert
      title="Your draft is saved"
      description={showDetails ? 'Continue editing when you reopen the page.' : undefined}
      extra={
        <Button variant="link" onClick={() => setShowDetails((value) => !value)}>
          {showDetails ? 'Hide details' : 'View details'}
        </Button>
      }
      closable
    />
  );
}
```

Expand code

### Dismissible alerts

Set `closable` to show a close button. Remount the alert to show it again after dismissal; this example changes its `key`.


Your draft is saved

Show again

closable.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/alert/closable.tsx"
import { Alert, Button, Flex } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function AlertClosable() {
  const [version, setVersion] = useState(0);

  return (
    <Flex direction="column" gap="md">
      <Alert key={version} title="Your draft is saved" closable />
      <Flex>
        <Button onClick={() => setVersion((value) => value + 1)}>Show again</Button>
      </Flex>
    </Flex>
  );
}
```

Expand code

### Icons

Replace the icon with `icon`, or hide it with `showIcon={false}`.


Custom icon

Access permissions updated

Hidden icon

Access permissions updated

icons.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/alert/icons.tsx"
import { Alert, Flex, Text } from '@ifhover/leaf-ui';
import { ShieldCheck } from 'lucide-react';

export function AlertIcons() {
  return (
    <Flex direction="column" gap="lg">
      <Flex direction="column" gap="sm">
        <Text tone="muted">Custom icon</Text>
        <Alert type="success" title="Access permissions updated" icon={<ShieldCheck size={20} />} />
      </Flex>
      <Flex direction="column" gap="sm">
        <Text tone="muted">Hidden icon</Text>
        <Alert type="success" title="Access permissions updated" showIcon={false} />
      </Flex>
    </Flex>
  );
}
```

Expand code


## API

### Alert API

Configuration for alert content, feedback type and dismissal.

| Property      | Type                      | Default  | Description                                     |
| ------------- | ------------------------- | -------- | ----------------------------------------------- |
| `title`       | `ReactNode`               | Required | Main content                                    |
| `description` | `ReactNode`               | —        | Additional details                              |
| `extra`       | `ReactNode`               | —        | Trailing content.                               |
| `type`        | `FeedbackType \| 'error'` | `'info'` | Feedback type; `error` is a compatibility alias |
| `icon`        | `ReactNode`               | —        | Icon content.                                   |
| `showIcon`    | `boolean`                 | `true`   | Show the feedback icon                          |
| `closable`    | `boolean`                 | `false`  | Allow dismissal                                 |
| `onClose`     | `() => void`              | —        | Called when the close button is activated.      |
