Skip to content

Commit 203dd08

Browse files
authored
feat(modal): add medium variant (#4678)
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
1 parent e42f427 commit 203dd08

File tree

6 files changed

+121
-4
lines changed

6 files changed

+121
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface ModalProps extends React.HTMLProps<HTMLDivElement>, OUIAProps {
4040
/** Description of the modal */
4141
description?: React.ReactNode;
4242
/** Variant of the modal */
43-
variant?: 'small' | 'large' | 'default';
43+
variant?: 'small' | 'medium' | 'large' | 'default';
4444
/** Flag indicating if modal content should be placed in a modal box body wrapper */
4545
hasNoBodyWrapper?: boolean;
4646
/** An ID to use for the ModalBox container */
@@ -51,6 +51,7 @@ export interface ModalProps extends React.HTMLProps<HTMLDivElement>, OUIAProps {
5151

5252
export enum ModalVariant {
5353
small = 'small',
54+
medium = 'medium',
5455
large = 'large',
5556
default = 'default'
5657
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface ModalBoxProps extends React.HTMLProps<HTMLDivElement> {
88
/** Additional classes added to the ModalBox */
99
className?: string;
1010
/** Variant of the modal */
11-
variant?: 'small' | 'large' | 'default';
11+
variant?: 'small' | 'medium' | 'large' | 'default';
1212
/** Id to use for Modal Box label */
1313
'aria-labelledby'?: string;
1414
/** Accessible descriptor of modal */
@@ -37,7 +37,8 @@ export const ModalBox: React.FunctionComponent<ModalBoxProps> = ({
3737
styles.modalBox,
3838
className,
3939
variant === 'large' && styles.modifiers.lg,
40-
variant === 'small' && styles.modifiers.sm
40+
variant === 'small' && styles.modifiers.sm,
41+
variant === 'medium' && styles.modifiers.md
4142
)}
4243
>
4344
{children}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface ModalContentProps extends OUIAProps {
2020
/** Additional classes added to the button */
2121
className?: string;
2222
/** Variant of the modal */
23-
variant?: 'small' | 'large' | 'default';
23+
variant?: 'small' | 'medium' | 'large' | 'default';
2424
/** Flag to show the modal */
2525
isOpen?: boolean;
2626
/** Complex header (more than just text), supersedes title for header content */

packages/react-core/src/components/Modal/examples/Modal.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,58 @@ class SmallModal extends React.Component {
167167
}
168168
```
169169

170+
### Medium
171+
```js
172+
import React from 'react';
173+
import { Modal, ModalVariant, Button } from '@patternfly/react-core';
174+
175+
class MediumModal extends React.Component {
176+
constructor(props) {
177+
super(props);
178+
this.state = {
179+
isModalOpen: false
180+
};
181+
this.handleModalToggle = () => {
182+
this.setState(({ isModalOpen }) => ({
183+
isModalOpen: !isModalOpen
184+
}));
185+
};
186+
}
187+
188+
render() {
189+
const { isModalOpen } = this.state;
190+
191+
return (
192+
<React.Fragment>
193+
<Button variant="primary" onClick={this.handleModalToggle}>
194+
Show Medium Modal
195+
</Button>
196+
<Modal
197+
variant={ModalVariant.medium}
198+
title="Medium modal header"
199+
isOpen={isModalOpen}
200+
onClose={this.handleModalToggle}
201+
actions={[
202+
<Button key="confirm" variant="primary" onClick={this.handleModalToggle}>
203+
Confirm
204+
</Button>,
205+
<Button key="cancel" variant="link" onClick={this.handleModalToggle}>
206+
Cancel
207+
</Button>
208+
]}
209+
>
210+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
211+
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
212+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
213+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
214+
est laborum.
215+
</Modal>
216+
</React.Fragment>
217+
);
218+
}
219+
}
220+
```
221+
170222
### Large
171223
```js
172224
import React from 'react';

packages/react-integration/cypress/integration/modal.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ describe('Modal Test', () => {
6262
});
6363
});
6464

65+
it('Verify Medium Modal', () => {
66+
cy.get('#showMediumModalButton').then((modalButton: JQuery<HTMLButtonElement>) => {
67+
cy.wrap(modalButton).click();
68+
cy.get('.pf-c-modal-box.pf-m-md')
69+
.then(() => {
70+
cy.get('.pf-c-modal-box .pf-c-button[aria-label="Close"]').then(closeButton => {
71+
cy.wrap(closeButton).click();
72+
cy.get('.pf-c-modal-box').should('not.exist');
73+
});
74+
})
75+
.then(() => {
76+
cy.wrap(modalButton).click();
77+
cy.get('.pf-c-modal-box').should('exist');
78+
cy.get('body').trigger('keydown', { keyCode: 27, which: 27 });
79+
cy.get('.pf-c-modal-box').should('not.exist');
80+
});
81+
});
82+
});
83+
6584
it('Verify Large Modal', () => {
6685
cy.get('#showLargeModalButton').then((modalButton: JQuery<HTMLButtonElement>) => {
6786
cy.wrap(modalButton).click();

packages/react-integration/demo-app-ts/src/components/demos/ModalDemo/ModalDemo.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface ModalDemoState {
66
isModalOpen: boolean;
77
isModalDescriptionOpen: boolean;
88
isSmallModalOpen: boolean;
9+
isMediumModalOpen: boolean;
910
isLargeModalOpen: boolean;
1011
isHalfWidthModalOpen: boolean;
1112
isCustomHeaderFooterModalOpen: boolean;
@@ -20,6 +21,7 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
2021
isModalOpen: false,
2122
isModalDescriptionOpen: false,
2223
isSmallModalOpen: false,
24+
isMediumModalOpen: false,
2325
isLargeModalOpen: false,
2426
isHalfWidthModalOpen: false,
2527
isCustomHeaderFooterModalOpen: false,
@@ -46,6 +48,12 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
4648
}));
4749
};
4850

51+
handleMediumModalToggle = () => {
52+
this.setState(({ isMediumModalOpen }) => ({
53+
isMediumModalOpen: !isMediumModalOpen
54+
}));
55+
};
56+
4957
handleLargeModalToggle = () => {
5058
this.setState(({ isLargeModalOpen }) => ({
5159
isLargeModalOpen: !isLargeModalOpen
@@ -162,6 +170,33 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
162170
);
163171
}
164172

173+
renderMediumModal() {
174+
const { isMediumModalOpen } = this.state;
175+
176+
return (
177+
<Modal
178+
variant={'medium'}
179+
title="Modal Header"
180+
isOpen={isMediumModalOpen}
181+
onClose={this.handleMediumModalToggle}
182+
actions={[
183+
<Button key="cancel" variant="secondary" onClick={this.handleMediumModalToggle}>
184+
Cancel
185+
</Button>,
186+
<Button key="confirm" variant="primary" onClick={this.handleMediumModalToggle}>
187+
Confirm
188+
</Button>
189+
]}
190+
>
191+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
192+
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
193+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
194+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
195+
laborum.
196+
</Modal>
197+
);
198+
}
199+
165200
renderLargeModal() {
166201
const { isLargeModalOpen } = this.state;
167202

@@ -330,6 +365,14 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
330365
<Button style={buttonStyle} variant="primary" onClick={this.handleSmallModalToggle} id="showSmallModalButton">
331366
Show Small Modal
332367
</Button>
368+
<Button
369+
style={buttonStyle}
370+
variant="primary"
371+
onClick={this.handleMediumModalToggle}
372+
id="showMediumModalButton"
373+
>
374+
Show Medium Modal
375+
</Button>
333376
<Button style={buttonStyle} variant="primary" onClick={this.handleLargeModalToggle} id="showLargeModalButton">
334377
Show Large Modal
335378
</Button>
@@ -377,6 +420,7 @@ export class ModalDemo extends React.Component<React.HTMLProps<HTMLDivElement>,
377420
</div>
378421
{this.renderModal()}
379422
{this.renderSmallModal()}
423+
{this.renderMediumModal()}
380424
{this.renderLargeModal()}
381425
{this.renderHalfWidthModal()}
382426
{this.renderCustomHeaderFooterModal()}

0 commit comments

Comments
 (0)