| 1 |
--- |
| 2 |
id: Notification badge |
| 3 |
section: components |
| 4 |
cssPrefix: pf-v6-c-notification-badge |
| 5 |
propComponents: ['NotificationBadge'] |
| 6 |
--- |
| 7 |
|
| 8 |
import { useEffect, useState } from 'react'; |
| 9 |
import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon'; |
| 10 |
|
| 11 |
## Examples |
| 12 |
|
| 13 |
### Basic |
| 14 |
|
| 15 |
The following example demonstrates the three variants of notification badge that are available: "read", "unread", and "attention". |
| 16 |
|
| 17 |
The `isExpanded` property is also passed in to: |
| 18 |
|
| 19 |
- set the `aria-expanded` attribute on the notification badge, |
| 20 |
- apply visual styling on the notification badge, and |
| 21 |
- to indicate that a notification drawer is expanded, for use-cases as seen in our [notification drawer react demos](/components/notification-drawer/react-demos). |
| 22 |
|
| 23 |
```ts file='./NotificationBadgeBasic.tsx' |
| 24 |
``` |
| 25 |
|
| 26 |
### With count |
| 27 |
|
| 28 |
You can display a number within the notification badge by passing in the `count` property, to indicate how many read, unread, or attention notifications there are. The `isExpanded` property is also passed in, similar to the [notification badge basic example](/components/notification-badge#basic). |
| 29 |
|
| 30 |
```ts file='./NotificationBadgeWithCount.tsx' |
| 31 |
``` |
| 32 |
|
| 33 |
### With animation |
| 34 |
|
| 35 |
To animate the icon within the notification badge, use the `shouldNotify` property. In this example, the notification badge icon will only animate if the notification count is greater than 0. |
| 36 |
|
| 37 |
```ts file='./NotificationBadgeWithAnimation.tsx' |
| 38 |
``` |