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