Debian Codegraph @

node/@patternfly/react-core/src/components/Modal/ModalHeader.tsx

raw
1 import { css } from '@patternfly/react-styles';
2 import styles from '@patternfly/react-styles/css/components/ModalBox/modal-box';
3 import { ModalBoxDescription } from './ModalBoxDescription';
4 import { ModalBoxTitle } from './ModalBoxTitle';
5
6 /** Renders content in the header of the modal */
7
8 export interface ModalHeaderProps {
9 /** Custom content rendered inside the modal header. If children are supplied then the tile, tileIconVariant and titleScreenReaderText props are ignored. */
10 children?: React.ReactNode;
11 /** Additional classes added to the modal header. */
12 className?: string;
13 /** Description of the modal. */
14 description?: React.ReactNode;
15 /** Id of the modal description. */
16 descriptorId?: string;
17 /** Optional help section for the modal header. */
18 help?: React.ReactNode;
19 /** Id of the modal title. */
20 labelId?: string;
21 /** Content rendered inside the modal title. */
22 title?: React.ReactNode;
23 /** Optional alert icon (or other) to show before the title. When the predefined alert types
24 * are used the default styling will be automatically applied. */
25 titleIconVariant?: 'success' | 'danger' | 'warning' | 'info' | 'custom' | React.ComponentType<any>;
26 /** Optional title label text for screen readers. */
27 titleScreenReaderText?: string;
28 }
29
30 export const ModalHeader: React.FunctionComponent<ModalHeaderProps> = ({
31 children,
32 className,
33 descriptorId,
34 description,
35 labelId,
36 title,
37 titleIconVariant,
38 titleScreenReaderText,
39 help,
40 ...props
41 }: ModalHeaderProps) => {
42 const headerContent = children ? (
43 children
44 ) : (
45 <>
46 <ModalBoxTitle
47 title={title}
48 titleIconVariant={titleIconVariant}
49 titleScreenReaderText={titleScreenReaderText}
50 id={labelId}
51 />
52 {description && <ModalBoxDescription id={descriptorId}>{description}</ModalBoxDescription>}
53 </>
54 );
55
56 return (
57 <header className={css(styles.modalBoxHeader, help && styles.modifiers.help, className)} {...props}>
58 {help && (
59 <>
60 <div className={css(styles.modalBoxHeaderMain)}>{headerContent}</div>
61 <div className={`${styles.modalBoxHeader}-help`}>{help}</div>
62 </>
63 )}
64 {!help && headerContent}
65 </header>
66 );
67 };
68 ModalHeader.displayName = 'ModalHeader';