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/notification.md.

Notification

Present notifications and actions in a page corner.

Basic usage

basic.tsx
import { Button, useNotification } from '@ifhover/leaf-ui';

export function NotificationBasic() {
  const notification = useNotification();
  return (
    <Button
      onClick={() =>
        notification.open({
          title: 'Report ready',
          description: 'Your monthly report is ready to download.',
          actions: (
            <Button size="sm" onClick={() => notification.close()}>
              Got it
            </Button>
          ),
        })
      }
    >
      Show notification
    </Button>
  );
}

More examples

advanced.tsx
import { Button, Space, useNotification } from '@ifhover/leaf-ui';

export function NotificationOptions() {
  const notification = useNotification();
  return (
    <Space wrap>
      <Button
        variant="outline"
        onClick={() =>
          notification.success({
            title: 'Saved successfully',
            description: 'All changes were saved.',
            placement: 'bottom-right',
          })
        }
      >
        Success
      </Button>
      <Button
        variant="outline"
        danger
        onClick={() =>
          notification.error({
            key: 'sync',
            title: 'Sync failed',
            description: 'Check your connection and retry.',
            duration: 0,
          })
        }
      >
        Persistent error
      </Button>
      <Button
        variant="soft"
        onClick={() => notification.open({ key: 'sync', title: 'Syncing again', duration: 2 })}
      >
        Update notification
      </Button>
    </Space>
  );
}

Usage

Place ConfigProvider at the root and call useNotification() in descendants. Use NotificationProvider for a standalone scope. Matching keys update notifications; duration={0} persists.

Types

Import these types for data, callbacks and refs.

import type { NotificationApi, NotificationOptions, NotificationProps, NotificationProviderProps } from '@ifhover/leaf-ui';

NotificationApi API

PropertyTypeDefaultDescription
open(options: NotificationOptions) => stringRequiredOpen a notification and return its key
success(options: Omit<NotificationOptions, 'type'>) => stringRequiredShow success
info(options: Omit<NotificationOptions, 'type'>) => stringRequiredShow information
warning(options: Omit<NotificationOptions, 'type'>) => stringRequiredShow warning
error(options: Omit<NotificationOptions, 'type'>) => stringRequiredShow an error notification
close(key?: string) => voidRequiredClose a key, or all when omitted

NotificationOptions API

PropertyTypeDefaultDescription
keystring—Unique stable identifier
titleReactNodeRequiredTitle content
descriptionReactNode—Supporting description
type'success' | 'info' | 'warning' | 'error''info'Visual or item type
iconReactNode—Custom icon
actionsReactNode—Notification actions
durationnumber4.5Seconds before dismissal; 0 persists
placement'top-right' | 'top-left' | 'bottom-right' | 'bottom-left''top-right'Placement
closablebooleantrueShow close action
onClose() => void—Called when closed

NotificationProps API

PropertyTypeDefaultDescription
titleReactNodeRequiredTitle content
descriptionReactNode—Supporting description
type'success' | 'info' | 'warning' | 'error''info'Visual or item type
iconReactNode—Custom icon
actionsReactNode—Notification actions
durationnumber4.5Seconds before dismissal; 0 persists
placement'top-right' | 'top-left' | 'bottom-right' | 'bottom-left''top-right'Placement
closablebooleantrueShow close action
onClose() => void—Called when closed
openbooleanRequiredControlled visibility
afterClose() => void—Closing animation completes

NotificationProviderProps API

PropertyTypeDefaultDescription
childrenReactNode—Content or child items
maxCountnumber5Maximum number of notifications