Skip to content

Commit c4b1386

Browse files
authored
Merge pull request #95 from patternfly/add-removemodal
add RemoveModal
2 parents 221c94d + 5227df7 commit c4b1386

7 files changed

Lines changed: 119 additions & 34 deletions

File tree

packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModal.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,21 @@ You can customize the contents of the modal to fit your use cases. To adjust the
2828
```js file="./WarningModalExample.tsx"
2929

3030
```
31+
32+
### Warning Modal with danger button variant
33+
34+
You can customize the modal to have a confirm button with a danger color
35+
36+
```js file="./WarningModalDangerExample.tsx"
37+
38+
```
39+
40+
41+
### Warning Modal with checkbox
42+
43+
You can customize the Warning Modal to include a checkbox to double check the user wants to use the selected action.
44+
45+
```js file="./WarningModalCheckboxExample.tsx"
46+
47+
```
48+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import WarningModal from '@patternfly/react-component-groups/dist/dynamic/WarningModal';
3+
import { Button } from '@patternfly/react-core';
4+
5+
export const BasicExample: React.FunctionComponent = () => {
6+
const [ isOpen, setIsOpen ] = React.useState(false);
7+
return <>
8+
<Button onClick={() => setIsOpen(true)}>Open modal</Button>
9+
<WarningModal
10+
isOpen={isOpen}
11+
title='Unsaved changes'
12+
onClose={() => setIsOpen(false)}
13+
onConfirm={() => setIsOpen(false)}
14+
withCheckbox
15+
checkboxLabel='Are you sure?'
16+
confirmButtonVariant
17+
>
18+
Your page contains unsaved changes. Do you want to leave?
19+
</WarningModal>
20+
</>
21+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import WarningModal from '@patternfly/react-component-groups/dist/dynamic/WarningModal';
3+
import { Button } from '@patternfly/react-core';
4+
5+
export const BasicExample: React.FunctionComponent = () => {
6+
const [ isOpen, setIsOpen ] = React.useState(false);
7+
return <>
8+
<Button onClick={() => setIsOpen(true)}>Open modal</Button>
9+
<WarningModal
10+
isOpen={isOpen}
11+
title='Unsaved changes'
12+
confirmButtonVariant
13+
onClose={() => setIsOpen(false)}
14+
onConfirm={() => setIsOpen(false)}>
15+
Your page contains unsaved changes. Do you want to leave?
16+
</WarningModal>
17+
</>
18+
};

packages/module/patternfly-docs/content/extensions/component-groups/examples/WarningModal/WarningModalExample.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const BasicExample: React.FunctionComponent = () => {
99
<WarningModal
1010
isOpen={isOpen}
1111
title='Unsaved changes'
12+
confirmButtonLabel='Yes'
13+
cancelButtonLabel='No'
1214
onClose={() => setIsOpen(false)}
1315
onConfirm={() => setIsOpen(false)}>
1416
Your page contains unsaved changes. Do you want to leave?

packages/module/src/WarningModal/WarningModal.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('WarningModal component', () => {
77
title: 'Unsaved changes',
88
onClose: () => null,
99
onConfirm: () => null,
10+
confirmCheckMessage: 'hi there',
1011
};
1112

1213
it('should render', () => {
Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import React from 'react';
2-
import { Button, ModalProps, Modal, ModalVariant, ButtonVariant } from '@patternfly/react-core';
1+
import React, { useState } from 'react';
2+
import { Button, ModalProps, Modal, ModalVariant, ButtonVariant, Checkbox } from '@patternfly/react-core';
33

44
export interface WarningModalProps extends Omit<ModalProps, 'ref'> {
55
/** Callback for the confirm action button. */
66
onConfirm?: () => void;
77
/** Custom label for the confirm action button */
8-
confirmButtonLabel? : string;
8+
confirmButtonLabel?: string;
99
/** Custom label for the cancel action button */
10-
cancelButtonLabel? : string;
10+
cancelButtonLabel?: string;
11+
/** Whether modal requires a checkbox before confirming */
12+
withCheckbox?: boolean;
13+
/** Custom checkbox label */
14+
checkboxLabel?: string;
15+
/** Visual variant of the confirm button */
16+
confirmButtonVariant?: boolean;
1117
}
1218

1319
const WarningModal: React.FunctionComponent<WarningModalProps> = ({
@@ -19,37 +25,55 @@ const WarningModal: React.FunctionComponent<WarningModalProps> = ({
1925
cancelButtonLabel = 'Cancel',
2026
variant = ModalVariant.small,
2127
titleIconVariant = 'warning',
28+
withCheckbox = false,
29+
checkboxLabel='I understand that this action cannot be undone',
30+
confirmButtonVariant = false,
2231
...props
23-
}: WarningModalProps) => (
24-
<Modal
25-
variant={variant}
26-
isOpen={isOpen}
27-
onClose={onClose}
28-
onEscapePress={onClose}
29-
titleIconVariant={titleIconVariant}
30-
actions={[
31-
<Button
32-
ouiaId="primary-confirm-button"
33-
key="confirm"
34-
variant={ButtonVariant.primary}
35-
onClick={onConfirm}
36-
>
37-
{confirmButtonLabel}
38-
</Button>,
39-
<Button
40-
ouiaId="secondary-cancel-button"
41-
key="cancel"
42-
variant={ButtonVariant.link}
43-
onClick={onClose}
44-
>
45-
{cancelButtonLabel}
46-
</Button>,
47-
]}
48-
{...props}
49-
>
50-
{children}
51-
</Modal>
52-
);
32+
}: WarningModalProps) => {
33+
const [ checked, setChecked ] = useState(false);
34+
35+
return (
36+
<Modal
37+
variant={variant}
38+
isOpen={isOpen}
39+
onClose={onClose}
40+
onEscapePress={onClose}
41+
titleIconVariant={titleIconVariant}
42+
actions={[
43+
<Button
44+
ouiaId="primary-confirm-button"
45+
key="confirm"
46+
variant={confirmButtonVariant ? ButtonVariant.danger : ButtonVariant.primary}
47+
onClick={onConfirm}
48+
isDisabled={withCheckbox && !checked}
49+
>
50+
{confirmButtonLabel}
51+
</Button>,
52+
<Button
53+
ouiaId="secondary-cancel-button"
54+
key="cancel"
55+
variant={ButtonVariant.link}
56+
onClick={onClose}
57+
>
58+
{cancelButtonLabel}
59+
</Button>,
60+
]}
61+
{...props}
62+
>
63+
{children}
64+
{withCheckbox ? (
65+
<Checkbox
66+
isChecked={checked}
67+
onChange={() => setChecked(!checked)}
68+
label={checkboxLabel}
69+
id="warning-modal-check"
70+
className="pf-v5-u-mt-lg"
71+
/>
72+
) : null}
73+
</Modal>
74+
)
75+
76+
};
5377

5478

5579
export default WarningModal;

packages/module/src/WarningModal/__snapshots__/WarningModal.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ exports[`WarningModal component should render 1`] = `
9292
</header>
9393
<div
9494
class="pf-v5-c-modal-box__body"
95+
confirmcheckmessage="hi there"
9596
id="pf-modal-part-2"
9697
>
9798
Warning modal content

0 commit comments

Comments
 (0)