#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
| Property | Type | Default | Description |
|---|---|---|---|
open | (options: NotificationOptions) => string | Required | Open a notification and return its key |
success | (options: Omit<NotificationOptions, 'type'>) => string | Required | Show success |
info | (options: Omit<NotificationOptions, 'type'>) => string | Required | Show information |
warning | (options: Omit<NotificationOptions, 'type'>) => string | Required | Show warning |
error | (options: Omit<NotificationOptions, 'type'>) => string | Required | Show an error notification |
close | (key?: string) => void | Required | Close a key, or all when omitted |
#NotificationOptions API
| Property | Type | Default | Description |
|---|---|---|---|
key | string | — | Unique stable identifier |
title | ReactNode | Required | Title content |
description | ReactNode | — | Supporting description |
type | 'success' | 'info' | 'warning' | 'error' | 'info' | Visual or item type |
icon | ReactNode | — | Custom icon |
actions | ReactNode | — | Notification actions |
duration | number | 4.5 | Seconds before dismissal; 0 persists |
placement | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-right' | Placement |
closable | boolean | true | Show close action |
onClose | () => void | — | Called when closed |
#NotificationProps API
| Property | Type | Default | Description |
|---|---|---|---|
title | ReactNode | Required | Title content |
description | ReactNode | — | Supporting description |
type | 'success' | 'info' | 'warning' | 'error' | 'info' | Visual or item type |
icon | ReactNode | — | Custom icon |
actions | ReactNode | — | Notification actions |
duration | number | 4.5 | Seconds before dismissal; 0 persists |
placement | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-right' | Placement |
closable | boolean | true | Show close action |
onClose | () => void | — | Called when closed |
open | boolean | Required | Controlled visibility |
afterClose | () => void | — | Closing animation completes |
#NotificationProviderProps API
| Property | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Content or child items |
maxCount | number | 5 | Maximum number of notifications |