Debian Codegraph @

node/@patternfly/react-table/src/components/Table/HeaderCellInfoWrapper.tsx

raw
1 import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon';
2 import { css } from '@patternfly/react-styles';
3 import styles from '@patternfly/react-styles/css/components/Table/table';
4 import { Tooltip, TooltipProps } from '@patternfly/react-core/dist/esm/components/Tooltip';
5 import { Popover, PopoverProps } from '@patternfly/react-core/dist/esm/components/Popover';
6 import { Button } from '@patternfly/react-core/dist/esm/components/Button';
7 import { TableText } from './TableText';
8
9 export interface ColumnHelpWrapperProps {
10 /**
11 * The header cell that is wrapped
12 */
13 children: React.ReactNode;
14 /**
15 * The information that is presented in the tooltip/popover
16 */
17 info: React.ReactNode;
18 /**
19 * Optional classname to add to the tooltip/popover
20 */
21 className?: string;
22 /**
23 * The info variant
24 */
25 variant?: 'tooltip' | 'popover';
26 /**
27 * Additional props forwarded to the Popover component
28 */
29 popoverProps?: Omit<PopoverProps, 'bodyContent'>;
30 /**
31 * Additional props forwarded to the tooltip component
32 */
33 tooltipProps?: Omit<TooltipProps, 'content'>;
34 /**
35 * Aria label of the info button
36 */
37 ariaLabel?: string;
38 }
39
40 export const HeaderCellInfoWrapper: React.FunctionComponent<ColumnHelpWrapperProps> = ({
41 children,
42 info,
43 className,
44 variant = 'tooltip',
45 popoverProps,
46 tooltipProps,
47 ariaLabel
48 }: ColumnHelpWrapperProps) => (
49 <div className={css(styles.tableColumnHelp, className)}>
50 {typeof children === 'string' ? <TableText>{children}</TableText> : children}
51 <span className={css(styles.tableColumnHelpAction)}>
52 {variant === 'tooltip' ? (
53 <Tooltip content={info} {...tooltipProps}>
54 <Button
55 variant="plain"
56 hasNoPadding
57 aria-label={ariaLabel || (typeof info === 'string' && info) || 'More info'}
58 icon={<HelpIcon />}
59 />
60 </Tooltip>
61 ) : (
62 <Popover bodyContent={info} {...popoverProps}>
63 <Button
64 variant="plain"
65 hasNoPadding
66 aria-label={ariaLabel || (typeof info === 'string' && info) || 'More info'}
67 icon={<HelpIcon />}
68 />
69 </Popover>
70 )}
71 </span>
72 </div>
73 );
74 HeaderCellInfoWrapper.displayName = 'HeaderCellInfoWrapper';