Skip to content

Commit f20c1fa

Browse files
AlsasaAmmarandrentkeszthoff
authored
feat(Dialog): update dialog design specs (#1288)
--------- Co-authored-by: André Nogueira <[email protected]> Co-authored-by: Eszter <[email protected]>
1 parent 56e7cc3 commit f20c1fa

File tree

22 files changed

+709
-333
lines changed

22 files changed

+709
-333
lines changed

package-lock.json

Lines changed: 122 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"react-popper": "2.3.0",
7373
"react-virtualized": "9.22.5",
7474
"remove-accents": "0.5.0",
75-
"tippy.js": "6.3.7"
75+
"tippy.js": "6.3.7",
76+
"use-resize-observer": "9.1.0"
7677
},
7778
"peerDependencies": {
7879
"react": ">=16.8.6",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export class ResizeObserverMock {
2+
observe = jest.fn();
3+
4+
unobserve = jest.fn();
5+
6+
disconnect = jest.fn();
7+
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import * as React from 'react';
2-
import { Dialog, DialogProps } from '../Dialog';
2+
import { Dialog, ButtonProps, DialogProps } from '../Dialog';
33

4-
export interface AlertProps extends DialogProps {
4+
export interface Props {
55
/** Alerts do not have cancel button */
66
cancelButton?: never;
7+
/** Properties of the accept button */
8+
acceptButton: ButtonProps;
79
}
810

9-
export const Alert: React.FC<AlertProps> = (props) => <Dialog {...props} />;
11+
export const Alert: React.FC<Props & DialogProps> = ({ acceptButton, onRequestClose, ...rest }) => (
12+
<Dialog acceptButton={acceptButton} onRequestClose={acceptButton.onClick} {...rest} />
13+
);
1014

1115
Alert.displayName = 'Alert';

src/components/Dialogs/Alert/__tests__/Alert.spec.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import { render, RenderResult, screen } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import '@testing-library/jest-dom';
55
import { Alert } from '../Alert';
6+
import { ResizeObserverMock } from '../../../../__mocks__/resizeObserverMock';
67

78
describe('Alert', () => {
89
const mockOnAccept = jest.fn();
10+
const mockOnClose = jest.fn();
911
let view: RenderResult;
1012

1113
beforeEach(() => {
14+
global.ResizeObserver = ResizeObserverMock;
15+
1216
view = render(
1317
<Alert
1418
isOpen
@@ -32,6 +36,7 @@ describe('Alert', () => {
3236
<Alert
3337
isOpen
3438
acceptButton={{ onClick: mockOnAccept, label: 'OK' }}
39+
closeButton={{ onClick: mockOnClose, label: 'Close' }}
3540
ariaHideApp={false}
3641
contentLabel="Content label"
3742
title="Title"
@@ -46,7 +51,7 @@ describe('Alert', () => {
4651

4752
it('should call onAccept cb when button is clicked', async () => {
4853
const user = userEvent.setup();
49-
await user.click(screen.getByRole('button'));
54+
await user.click(screen.getByRole('button', { name: /OK/i }));
5055

5156
expect(mockOnAccept).toHaveBeenCalledTimes(1);
5257
});

src/components/Dialogs/Alert/__tests__/__snapshots__/Alert.spec.tsx.snap

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ exports[`Alert should render correctly 1`] = `
3030
>
3131
<div
3232
class="Dialog__content"
33-
role="alert"
3433
>
3534
Body of the alert
3635
</div>
@@ -82,14 +81,41 @@ exports[`Alert should render correctly with title 1`] = `
8281
tabindex="-1"
8382
>
8483
<div
85-
class="Dialog__content"
84+
class="Dialog__header"
8685
role="alert"
8786
>
88-
<h2
89-
class="Heading Heading--level_h2 Dialog__title"
87+
<h3
88+
class="Heading Heading--level_h3 Dialog__title"
9089
>
9190
Title
92-
</h2>
91+
</h3>
92+
<button
93+
aria-label="Close"
94+
class="Button Button--variant_ghost Button--context_secondary Dialog__closeButton"
95+
type="button"
96+
>
97+
<svg
98+
fill="currentColor"
99+
height="1em"
100+
stroke="currentColor"
101+
stroke-width="0"
102+
viewBox="0 0 24 24"
103+
width="1em"
104+
xmlns="http://www.w3.org/2000/svg"
105+
>
106+
<path
107+
d="M0 0h24v24H0z"
108+
fill="none"
109+
/>
110+
<path
111+
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
112+
/>
113+
</svg>
114+
</button>
115+
</div>
116+
<div
117+
class="Dialog__content"
118+
>
93119
Body of the alert
94120
</div>
95121
<div
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { Alert, AlertProps } from './Alert';
1+
export { Alert, Props as AlertProps } from './Alert';
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import * as React from 'react';
22
import { Dialog, DialogProps, ButtonProps } from '../Dialog';
33

4-
export interface ConfirmProps extends DialogProps {
4+
export interface Props {
55
/** Properties of the cancel button */
66
cancelButton: ButtonProps;
77
}
88

9-
export const Confirm: React.FC<ConfirmProps> = (props) => <Dialog {...props} />;
9+
export const Confirm: React.FC<Props & DialogProps> = ({
10+
cancelButton,
11+
onRequestClose,
12+
...rest
13+
}) => (
14+
<Dialog
15+
cancelButton={cancelButton}
16+
shouldCloseOnEsc
17+
shouldCloseOnOverlayClick={false}
18+
onRequestClose={cancelButton.onClick}
19+
{...rest}
20+
/>
21+
);
1022

1123
Confirm.displayName = 'Confirm';

src/components/Dialogs/Confirm/__tests__/Confirm.spec.tsx renamed to src/components/Dialogs/Confirm/__test__/Confirm.spec.tsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import '@testing-library/jest-dom';
55
import { Confirm } from '../Confirm';
66

77
describe('Confirm', () => {
8-
const mockOnAccept = jest.fn();
9-
const mockOnCancel = jest.fn();
8+
let mockOnAccept: jest.Mock;
9+
let mockOnCancel: jest.Mock;
10+
let mockOnClose: jest.Mock;
1011
let view: RenderResult;
1112

1213
beforeEach(() => {
14+
mockOnAccept = jest.fn();
15+
mockOnCancel = jest.fn();
16+
mockOnClose = jest.fn();
17+
1318
view = render(
1419
<Confirm
1520
isOpen
@@ -35,6 +40,7 @@ describe('Confirm', () => {
3540
isOpen
3641
acceptButton={{ onClick: mockOnAccept, label: 'OK' }}
3742
cancelButton={{ onClick: mockOnCancel, label: 'Cancel' }}
43+
closeButton={{ onClick: mockOnClose, label: 'Close' }}
3844
ariaHideApp={false}
3945
contentLabel="Content Label"
4046
title="Title"
@@ -47,16 +53,38 @@ describe('Confirm', () => {
4753
expect(screen.getAllByRole('heading')).toHaveLength(1);
4854
});
4955

50-
it('should call onCancel callback when button is clicked', async () => {
56+
it('should call onAccept callback when OK button is clicked', async () => {
5157
const user = userEvent.setup();
52-
await user.click(screen.getAllByRole('button')[1]);
58+
await user.click(screen.getByRole('button', { name: 'OK' }));
5359

5460
expect(mockOnAccept).toHaveBeenCalledTimes(1);
5561
});
56-
it('should call onCancel callback when button is clicked', async () => {
62+
63+
it('should call onCancel callback when cancel button is clicked', async () => {
5764
const user = userEvent.setup();
58-
await user.click(screen.getAllByRole('button')[0]);
65+
await user.click(screen.getByRole('button', { name: 'Cancel' }));
5966

6067
expect(mockOnCancel).toHaveBeenCalledTimes(1);
6168
});
69+
70+
it('should call onCancel callback when close button is clicked', async () => {
71+
view.rerender(
72+
<Confirm
73+
isOpen
74+
acceptButton={{ onClick: mockOnAccept, label: 'OK' }}
75+
cancelButton={{ onClick: mockOnCancel, label: 'Cancel' }}
76+
closeButton={{ onClick: mockOnClose, label: 'Close' }}
77+
ariaHideApp={false}
78+
contentLabel="Content Label"
79+
title="Title"
80+
>
81+
Body of the confirm
82+
</Confirm>
83+
);
84+
85+
const user = userEvent.setup();
86+
await user.click(screen.getByLabelText('Close'));
87+
88+
expect(mockOnClose).toHaveBeenCalledTimes(1);
89+
});
6290
});

src/components/Dialogs/Confirm/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)