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, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/alert.md.

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
import { Alert } from '@ifhover/leaf-ui';

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

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
Danger
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>
  );
}

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
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
    />
  );
}

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
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>
  );
}

Icons

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

Custom icon
Access permissions updated
Hidden icon
Access permissions updated
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>
  );
}

API

Alert API

Configuration for alert content, feedback type and dismissal.

PropertyTypeDefaultDescription
titleReactNodeRequiredMain content
descriptionReactNode—Additional details
extraReactNode—Trailing content.
typeFeedbackType | 'error''info'Feedback type; error is a compatibility alias
iconReactNode—Icon content.
showIconbooleantrueShow the feedback icon
closablebooleanfalseAllow dismissal
onClose() => void—Called when the close button is activated.