| 1 |
import { css } from '@patternfly/react-styles'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/NotificationDrawer/notification-drawer'; |
| 3 |
import RhMicronsCloseIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-close-icon'; |
| 4 |
import { Button, ButtonVariant } from '../Button'; |
| 5 |
|
| 6 |
export interface NotificationDrawerHeaderProps extends React.HTMLProps<HTMLDivElement> { |
| 7 |
/** Content rendered inside the drawer */ |
| 8 |
children?: React.ReactNode; |
| 9 |
/** Additional classes for notification drawer header. */ |
| 10 |
className?: string; |
| 11 |
/** Adds custom accessible text to the notification drawer close button. */ |
| 12 |
closeButtonAriaLabel?: string; |
| 13 |
/** Notification drawer heading count */ |
| 14 |
count?: number; |
| 15 |
/** Notification drawer heading custom text which can be used instead of providing count/unreadText */ |
| 16 |
customText?: string; |
| 17 |
/** Callback for when close button is clicked */ |
| 18 |
onClose?: (event: KeyboardEvent | React.MouseEvent) => void; |
| 19 |
/** Notification drawer heading title */ |
| 20 |
title?: string; |
| 21 |
/** Notification drawer heading unread text used in combination with a count */ |
| 22 |
unreadText?: string; |
| 23 |
} |
| 24 |
|
| 25 |
export const NotificationDrawerHeader: React.FunctionComponent<NotificationDrawerHeaderProps> = ({ |
| 26 |
children, |
| 27 |
className = '', |
| 28 |
count, |
| 29 |
closeButtonAriaLabel = 'Close', |
| 30 |
customText, |
| 31 |
onClose, |
| 32 |
title = 'Notifications', |
| 33 |
unreadText = 'unread', |
| 34 |
...props |
| 35 |
}: NotificationDrawerHeaderProps) => ( |
| 36 |
<div {...props} className={css(styles.notificationDrawerHeader, className)}> |
| 37 |
<h1 className={css(styles.notificationDrawerHeaderTitle)}>{title}</h1> |
| 38 |
{(customText !== undefined || count !== undefined) && ( |
| 39 |
<span className={css(styles.notificationDrawerHeaderStatus)} aria-live="polite"> |
| 40 |
{customText || `${count} ${unreadText}`} |
| 41 |
</span> |
| 42 |
)} |
| 43 |
{(children || onClose) && ( |
| 44 |
<div className={css(styles.notificationDrawerHeaderAction)}> |
| 45 |
{children} |
| 46 |
{onClose && ( |
| 47 |
<div> |
| 48 |
<Button |
| 49 |
variant={ButtonVariant.plain} |
| 50 |
aria-label={closeButtonAriaLabel} |
| 51 |
onClick={(event) => onClose(event)} |
| 52 |
icon={<RhMicronsCloseIcon />} |
| 53 |
/> |
| 54 |
</div> |
| 55 |
)} |
| 56 |
</div> |
| 57 |
)} |
| 58 |
</div> |
| 59 |
); |
| 60 |
NotificationDrawerHeader.displayName = 'NotificationDrawerHeader'; |