Debian Codegraph @

node/@patternfly/react-core/src/components/DataList/DataListToggle.tsx

raw
1 import { css } from '@patternfly/react-styles';
2 import RhMicronsCaretDownIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-down-icon';
3 import styles from '@patternfly/react-styles/css/components/DataList/data-list';
4 import { Button, ButtonProps, ButtonVariant } from '../Button';
5
6 export interface DataListToggleProps extends React.HTMLProps<HTMLDivElement> {
7 /** Additional classes added to the data list cell */
8 className?: string;
9 /** Flag to show if the expanded content of the data list item is visible */
10 isExpanded?: boolean;
11 /** Identify the data list toggle number */
12 id: string;
13 /** Id for the row */
14 rowid?: string;
15 /** Adds accessible text to the data list toggle */
16 'aria-labelledby'?: string;
17 /** Adds accessible text to the data list toggle */
18 'aria-label'?: string;
19 /** Allows users of some screen readers to shift focus to the controlled element. Should be used when the controlled contents are not adjacent to the toggle that controls them. */
20 'aria-controls'?: string;
21 /** Additional properties spread to the toggle button */
22 buttonProps?: ButtonProps;
23 }
24
25 export const DataListToggle: React.FunctionComponent<DataListToggleProps> = ({
26 className = '',
27 isExpanded = false,
28 'aria-controls': ariaControls = '',
29 'aria-label': ariaLabel = 'Details',
30 rowid = '',
31 id,
32 buttonProps,
33 ...props
34 }: DataListToggleProps) => (
35 <div className={css(styles.dataListItemControl, className)} {...props}>
36 <div className={css(styles.dataListToggle)}>
37 <Button
38 id={id}
39 variant={ButtonVariant.plain}
40 aria-controls={ariaControls !== '' && ariaControls}
41 aria-label={ariaLabel}
42 aria-labelledby={ariaLabel !== 'Details' ? null : `${rowid} ${id}`}
43 aria-expanded={isExpanded}
44 {...buttonProps}
45 icon={
46 <div className={css(styles.dataListToggleIcon)}>
47 <RhMicronsCaretDownIcon />
48 </div>
49 }
50 />
51 </div>
52 </div>
53 );
54 DataListToggle.displayName = 'DataListToggle';