| 1 |
import { useContext } from 'react'; |
| 2 |
import { Button, ButtonProps, ButtonVariant } from '../Button'; |
| 3 |
import { AlertContext } from './AlertContext'; |
| 4 |
import RhMicronsCaretDownIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-down-icon'; |
| 5 |
import { css } from '@patternfly/react-styles'; |
| 6 |
import styles from '@patternfly/react-styles/css/components/Alert/alert'; |
| 7 |
|
| 8 |
export interface AlertToggleExpandButtonProps extends ButtonProps { |
| 9 |
/** Accessible label for the toggle button. */ |
| 10 |
'aria-label'?: string; |
| 11 |
/** Flag to indicate if the content is expanded. */ |
| 12 |
isExpanded?: boolean; |
| 13 |
/** A callback for when the toggle button is clicked. */ |
| 14 |
onToggleExpand?: () => void; |
| 15 |
/** Variant label for the toggle button. */ |
| 16 |
variantLabel?: string; |
| 17 |
} |
| 18 |
|
| 19 |
export const AlertToggleExpandButton: React.FunctionComponent<AlertToggleExpandButtonProps> = ({ |
| 20 |
'aria-label': ariaLabel = '', |
| 21 |
variantLabel, |
| 22 |
onToggleExpand, |
| 23 |
isExpanded = false, |
| 24 |
...props |
| 25 |
}: AlertToggleExpandButtonProps) => { |
| 26 |
const { title, variantLabel: alertVariantLabel } = useContext(AlertContext); |
| 27 |
return ( |
| 28 |
<Button |
| 29 |
variant={ButtonVariant.plain} |
| 30 |
onClick={onToggleExpand} |
| 31 |
aria-expanded={isExpanded} |
| 32 |
aria-label={ariaLabel === '' ? `Toggle ${variantLabel || alertVariantLabel} alert: ${title}` : ariaLabel} |
| 33 |
{...props} |
| 34 |
icon={ |
| 35 |
<span className={css(styles.alertToggleIcon)}> |
| 36 |
<RhMicronsCaretDownIcon /> |
| 37 |
</span> |
| 38 |
} |
| 39 |
/> |
| 40 |
); |
| 41 |
}; |
| 42 |
AlertToggleExpandButton.displayName = 'AlertToggleExpandButton'; |