Skip to content

Commit 1827b2b

Browse files
committed
add custom classname property for modal header, body and footer
1 parent 05b0b6a commit 1827b2b

6 files changed

Lines changed: 114 additions & 3 deletions

File tree

packages/module/src/AttachmentEdit/AttachmentEdit.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { fireEvent, render, screen } from '@testing-library/react';
2+
import '@testing-library/jest-dom';
23
import AttachmentEdit, { AttachmentEditProps } from './AttachmentEdit';
34

45
describe('AttachmentEdit', () => {
@@ -69,4 +70,29 @@ describe('AttachmentEdit', () => {
6970
screen.getByText('Save');
7071
screen.getByText('Close');
7172
});
73+
74+
it('should render AttachmentEdit with custom classNames', async () => {
75+
render(
76+
<AttachmentEdit
77+
code="Hello world"
78+
fileName="greetings.txt"
79+
isModalOpen={true}
80+
onCancel={jest.fn()}
81+
onSave={jest.fn()}
82+
handleModalToggle={jest.fn()}
83+
primaryActionButtonText="Save"
84+
secondaryActionButtonText="Close"
85+
modalHeaderClassName="custom-header-class"
86+
modalBodyClassName="custom-body-class"
87+
modalFooterClassName="custom-footer-class"
88+
></AttachmentEdit>
89+
);
90+
91+
const modalHeader = document.querySelector('header.custom-header-class');
92+
expect(modalHeader).toBeInTheDocument();
93+
const modalBody = document.querySelector('.custom-body-class');
94+
expect(modalBody).toBeInTheDocument();
95+
const modalfooter = document.querySelector('.custom-footer-class');
96+
expect(modalfooter).toBeInTheDocument();
97+
});
7298
});

packages/module/src/AttachmentEdit/AttachmentEdit.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export interface AttachmentEditProps {
2828
primaryActionButtonText?: string;
2929
/** Secondary action button text */
3030
secondaryActionButtonText?: string;
31+
/** Class applied to modal header */
32+
modalHeaderClassName?: string;
33+
/** Class applied to modal body */
34+
modalBodyClassName?: string;
35+
/** Class applied to modal footer */
36+
modalFooterClassName?: string;
3137
}
3238

3339
export const AttachmentEdit: FunctionComponent<AttachmentEditProps> = ({
@@ -40,6 +46,9 @@ export const AttachmentEdit: FunctionComponent<AttachmentEditProps> = ({
4046
title = 'Edit attachment',
4147
displayMode = ChatbotDisplayMode.default,
4248
isCompact,
49+
modalHeaderClassName,
50+
modalBodyClassName,
51+
modalFooterClassName,
4352
primaryActionButtonText = 'Save',
4453
secondaryActionButtonText = 'Cancel'
4554
}: AttachmentEditProps) => {
@@ -66,6 +75,9 @@ export const AttachmentEdit: FunctionComponent<AttachmentEditProps> = ({
6675
title={title}
6776
displayMode={displayMode}
6877
isCompact={isCompact}
78+
modalHeaderClassName={modalHeaderClassName}
79+
modalBodyClassName={modalBodyClassName}
80+
modalFooterClassName={modalFooterClassName}
6981
/>
7082
);
7183
};

packages/module/src/CodeModal/CodeModal.test.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,31 @@ describe('ChatbotModal', () => {
2020
);
2121
expect(screen.getByRole('dialog')).toHaveClass('pf-m-compact');
2222
});
23+
24+
it('should render CodeModal with custom classNames', async () => {
25+
render(
26+
<CodeModal
27+
isCompact
28+
code="Hello world"
29+
fileName="greetings.txt"
30+
isModalOpen={true}
31+
handleModalToggle={jest.fn()}
32+
onPrimaryAction={jest.fn()}
33+
onSecondaryAction={jest.fn()}
34+
title="Preview attachment"
35+
primaryActionBtn="Submit"
36+
secondaryActionBtn="Cancel"
37+
modalHeaderClassName="custom-header-class"
38+
modalBodyClassName="custom-body-class"
39+
modalFooterClassName="custom-footer-class"
40+
></CodeModal>
41+
);
42+
43+
const modalHeader = document.querySelector('header.custom-header-class');
44+
expect(modalHeader).toBeInTheDocument();
45+
const modalBody = document.querySelector('.custom-body-class');
46+
expect(modalBody).toBeInTheDocument();
47+
const modalfooter = document.querySelector('.custom-footer-class');
48+
expect(modalfooter).toBeInTheDocument();
49+
});
2350
});

packages/module/src/CodeModal/CodeModal.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export interface CodeModalProps {
4343
displayMode?: ChatbotDisplayMode;
4444
/** Sets modal to compact styling. */
4545
isCompact?: boolean;
46+
/** Class applied to modal header */
47+
modalHeaderClassName?: string;
48+
/** Class applied to modal body */
49+
modalBodyClassName?: string;
50+
/** Class applied to modal footer */
51+
modalFooterClassName?: string;
4652
}
4753

4854
export const CodeModal: FunctionComponent<CodeModalProps> = ({
@@ -61,6 +67,9 @@ export const CodeModal: FunctionComponent<CodeModalProps> = ({
6167
title,
6268
displayMode = ChatbotDisplayMode.default,
6369
isCompact,
70+
modalHeaderClassName,
71+
modalBodyClassName,
72+
modalFooterClassName,
6473
...props
6574
}: CodeModalProps) => {
6675
const [newCode, setNewCode] = useState(code);
@@ -102,8 +111,8 @@ export const CodeModal: FunctionComponent<CodeModalProps> = ({
102111
displayMode={displayMode}
103112
isCompact={isCompact}
104113
>
105-
<ModalHeader title={title} labelId="code-modal-title" />
106-
<ModalBody id="code-modal-body">
114+
<ModalHeader className={modalHeaderClassName} title={title} labelId="code-modal-title" />
115+
<ModalBody className={modalBodyClassName} id="code-modal-body">
107116
<Stack className="pf-chatbot__code-modal-body">
108117
<StackItem className="pf-chatbot__code-modal-file-details">
109118
<FileDetails fileName={fileName} />
@@ -130,7 +139,7 @@ export const CodeModal: FunctionComponent<CodeModalProps> = ({
130139
</StackItem>
131140
</Stack>
132141
</ModalBody>
133-
<ModalFooter>
142+
<ModalFooter className={modalFooterClassName}>
134143
<Button isBlock key="code-modal-primary" variant="primary" onClick={handlePrimaryAction} form="code-modal-form">
135144
{primaryActionBtn}
136145
</Button>

packages/module/src/PreviewAttachment/PreviewAttachment.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { fireEvent, render, screen } from '@testing-library/react';
2+
import '@testing-library/jest-dom';
23
import { PreviewAttachment } from './PreviewAttachment';
34

45
describe('PreviewAttachment', () => {
@@ -64,4 +65,28 @@ describe('PreviewAttachment', () => {
6465
screen.getByText('Edit');
6566
screen.getByText('Close');
6667
});
68+
69+
it('should render PreviewAttachment with custom classNames', async () => {
70+
render(
71+
<PreviewAttachment
72+
code="Hello world"
73+
fileName="greetings.txt"
74+
isModalOpen={true}
75+
onEdit={jest.fn()}
76+
handleModalToggle={jest.fn()}
77+
primaryActionButtonText="Edit"
78+
secondaryActionButtonText="Close"
79+
modalHeaderClassName="custom-header-class"
80+
modalBodyClassName="custom-body-class"
81+
modalFooterClassName="custom-footer-class"
82+
></PreviewAttachment>
83+
);
84+
85+
const modalHeader = document.querySelector('header.custom-header-class');
86+
expect(modalHeader).toBeInTheDocument();
87+
const modalBody = document.querySelector('.custom-body-class');
88+
expect(modalBody).toBeInTheDocument();
89+
const modalfooter = document.querySelector('.custom-footer-class');
90+
expect(modalfooter).toBeInTheDocument();
91+
});
6792
});

packages/module/src/PreviewAttachment/PreviewAttachment.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export interface PreviewAttachmentProps {
2828
primaryActionButtonText?: string;
2929
/** Secondary action button text */
3030
secondaryActionButtonText?: string;
31+
/** Class applied to modal header */
32+
modalHeaderClassName?: string;
33+
/** Class applied to modal body */
34+
modalBodyClassName?: string;
35+
/** Class applied to modal footer */
36+
modalFooterClassName?: string;
3137
}
3238

3339
export const PreviewAttachment: FunctionComponent<PreviewAttachmentProps> = ({
@@ -41,6 +47,9 @@ export const PreviewAttachment: FunctionComponent<PreviewAttachmentProps> = ({
4147
primaryActionButtonText = 'Edit',
4248
secondaryActionButtonText = 'Dismiss',
4349
displayMode = ChatbotDisplayMode.default,
50+
modalHeaderClassName,
51+
modalBodyClassName,
52+
modalFooterClassName,
4453
isCompact
4554
}: PreviewAttachmentProps) => {
4655
const handleEdit = (_event: MouseEvent | MouseEvent | KeyboardEvent) => {
@@ -70,6 +79,9 @@ export const PreviewAttachment: FunctionComponent<PreviewAttachmentProps> = ({
7079
isReadOnly
7180
displayMode={displayMode}
7281
isCompact={isCompact}
82+
modalHeaderClassName={modalHeaderClassName}
83+
modalBodyClassName={modalBodyClassName}
84+
modalFooterClassName={modalFooterClassName}
7385
/>
7486
);
7587
};

0 commit comments

Comments
 (0)