| 1 |
import { Fragment } from 'react'; |
| 2 |
import RhMicronsCaretDownIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-down-icon'; |
| 3 |
import { css } from '@patternfly/react-styles'; |
| 4 |
import { Button } from '@patternfly/react-core/dist/esm/components/Button'; |
| 5 |
import styles from '@patternfly/react-styles/css/components/Table/table'; |
| 6 |
|
| 7 |
export interface CollapseColumnProps { |
| 8 |
id?: string; |
| 9 |
className?: string; |
| 10 |
children?: React.ReactNode; |
| 11 |
onToggle?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void; |
| 12 |
isOpen?: boolean; |
| 13 |
'aria-label'?: string; |
| 14 |
variant?: 'compact'; |
| 15 |
} |
| 16 |
|
| 17 |
export const CollapseColumn: React.FunctionComponent<CollapseColumnProps> = ({ |
| 18 |
className = '' as string, |
| 19 |
children = null as React.ReactNode, |
| 20 |
isOpen, |
| 21 |
onToggle, |
| 22 |
variant, |
| 23 |
...props |
| 24 |
}: CollapseColumnProps) => ( |
| 25 |
<Fragment> |
| 26 |
{isOpen !== undefined && ( |
| 27 |
<Button |
| 28 |
className={css(className, isOpen && styles.modifiers.expanded)} |
| 29 |
size={variant === 'compact' ? 'sm' : undefined} |
| 30 |
{...props} |
| 31 |
variant="plain" |
| 32 |
aria-label={props['aria-label'] || 'Details'} |
| 33 |
onClick={onToggle} |
| 34 |
aria-expanded={isOpen} |
| 35 |
icon={ |
| 36 |
<div className={css(styles.tableToggleIcon)}> |
| 37 |
<RhMicronsCaretDownIcon /> |
| 38 |
</div> |
| 39 |
} |
| 40 |
/> |
| 41 |
)} |
| 42 |
{children} |
| 43 |
</Fragment> |
| 44 |
); |
| 45 |
CollapseColumn.displayName = 'CollapseColumn'; |