| 1 |
import { css } from '@patternfly/react-styles'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/Popover/popover'; |
| 3 |
import { PopoverHeaderIcon } from './PopoverHeaderIcon'; |
| 4 |
import { PopoverHeaderText } from './PopoverHeaderText'; |
| 5 |
|
| 6 |
export interface PopoverHeaderProps extends Omit<React.HTMLProps<HTMLHeadingElement>, 'size'> { |
| 7 |
/** Content of the popover header. */ |
| 8 |
children: React.ReactNode; |
| 9 |
/** Indicates the header contains an icon. */ |
| 10 |
icon?: React.ReactNode; |
| 11 |
/** Class to be applied to the header. */ |
| 12 |
className?: string; |
| 13 |
/** Heading level of the header title */ |
| 14 |
titleHeadingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; |
| 15 |
/** Severity variants for an alert popover. This modifies the color of the header to match the severity. */ |
| 16 |
alertSeverityVariant?: 'custom' | 'info' | 'warning' | 'success' | 'danger'; |
| 17 |
/** Id of the header */ |
| 18 |
id?: string; |
| 19 |
/** Text announced by screen reader when alert severity variant is set to indicate severity level */ |
| 20 |
alertSeverityScreenReaderText?: string; |
| 21 |
} |
| 22 |
|
| 23 |
export const PopoverHeader: React.FunctionComponent<PopoverHeaderProps> = ({ |
| 24 |
children, |
| 25 |
icon, |
| 26 |
className, |
| 27 |
titleHeadingLevel = 'h6', |
| 28 |
alertSeverityVariant, |
| 29 |
id, |
| 30 |
alertSeverityScreenReaderText, |
| 31 |
...props |
| 32 |
}: PopoverHeaderProps) => ( |
| 33 |
<header className={css(styles.popoverHeader, className)} {...props}> |
| 34 |
<div className={css(styles.popoverTitle)} id={id}> |
| 35 |
{icon && <PopoverHeaderIcon>{icon}</PopoverHeaderIcon>} |
| 36 |
<PopoverHeaderText headingLevel={titleHeadingLevel}> |
| 37 |
{alertSeverityVariant && alertSeverityScreenReaderText && ( |
| 38 |
<span className="pf-v6-screen-reader">{alertSeverityScreenReaderText}</span> |
| 39 |
)} |
| 40 |
{children} |
| 41 |
</PopoverHeaderText> |
| 42 |
</div> |
| 43 |
</header> |
| 44 |
); |
| 45 |
PopoverHeader.displayName = 'PopoverHeader'; |