Skip to content

Commit 97eb9d8

Browse files
authored
feat(Modal): move description to separate component (#3897)
* feat(Modal): move description to separate component * feat(Modal): fix property descriptions
1 parent 4abb5b6 commit 97eb9d8

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react';
2+
import { css } from '@patternfly/react-styles';
3+
import styles from '@patternfly/react-styles/css/components/ModalBox/modal-box';
4+
5+
export interface ModalBoxDescriptionProps {
6+
/** Content rendered inside the description */
7+
children?: React.ReactNode;
8+
/** Additional classes added to the description */
9+
className?: string;
10+
/** ID of the description */
11+
id?: string;
12+
}
13+
14+
export const ModalBoxDescription: React.FunctionComponent<ModalBoxDescriptionProps> = ({
15+
children = null,
16+
className = '',
17+
id = '',
18+
...props
19+
}: ModalBoxDescriptionProps) => (
20+
<div {...props} id={id} className={css(styles.modalBoxDescription, className)}>
21+
{children}
22+
</div>
23+
);

packages/react-core/src/components/Modal/ModalContent.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const FocusTrap: any = require('focus-trap-react');
77

88
import styles from '@patternfly/react-styles/css/layouts/Bullseye/bullseye';
99
import titleStyles from '@patternfly/react-styles/css/components/Title/title';
10-
import modalStyles from '@patternfly/react-styles/css/components/ModalBox/modal-box';
1110
import { css } from '@patternfly/react-styles';
1211

1312
import { Backdrop } from '../Backdrop/Backdrop';
@@ -16,6 +15,7 @@ import { ModalBoxHeader } from './ModalBoxHeader';
1615
import { ModalBoxCloseButton } from './ModalBoxCloseButton';
1716
import { ModalBox } from './ModalBox';
1817
import { ModalBoxFooter } from './ModalBoxFooter';
18+
import { ModalBoxDescription } from './ModalBoxDescription';
1919

2020
export interface ModalContentProps {
2121
/** Content rendered inside the Modal. */
@@ -104,11 +104,7 @@ export const ModalContent: React.FunctionComponent<ModalContentProps> = ({
104104
>
105105
{showClose && <ModalBoxCloseButton onClose={onClose} />}
106106
{modalBoxHeader}
107-
{description && (
108-
<div className={css(modalStyles.modalBoxDescription)} id={id}>
109-
{description}
110-
</div>
111-
)}
107+
{description && <ModalBoxDescription id={id}>{description}</ModalBoxDescription>}
112108
<ModalBoxBody {...props} {...(!description && { id })}>
113109
{children}
114110
</ModalBoxBody>

packages/react-core/src/components/Modal/__tests__/__snapshots__/ModalContent.test.tsx.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ exports[`Modal Content Test description 1`] = `
3232
Test Modal Content title
3333
3434
</ModalBoxHeader>
35-
<div
36-
className="pf-c-modal-box__description"
35+
<ModalBoxDescription
3736
id="id"
3837
>
3938
This is a test description.
40-
</div>
39+
</ModalBoxDescription>
4140
<ModalBoxBody>
4241
This is a ModalBox header
4342
</ModalBoxBody>

0 commit comments

Comments
 (0)