Skip to content

Commit 36f7af0

Browse files
MartinSchoelerdougfabris
authored andcommitted
chore: new secondary-danger generic modal variant (#37223)
Co-authored-by: Douglas Fabris <[email protected]>
1 parent 038948e commit 36f7af0

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

packages/ui-client/src/components/Modal/GenericModal/GenericModal.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useSetModal } from '@rocket.chat/ui-contexts';
22
import { act, screen, renderHook } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
4+
import { axe } from 'jest-axe';
45
import type { ReactElement } from 'react';
56
import { Suspense } from 'react';
67

@@ -25,6 +26,21 @@ const renderModal = (modalElement: ReactElement) => {
2526
return { setModal };
2627
};
2728

29+
describe('renders', () => {
30+
it('should render a modal without crashing', async () => {
31+
renderModal(<GenericModal title='Modal' />);
32+
33+
expect(await screen.findByRole('dialog', { name: 'Modal' })).toMatchSnapshot();
34+
});
35+
36+
it('should have no accessibility violations when rendered', async () => {
37+
renderModal(<GenericModal title='Modal' />);
38+
39+
const results = await axe(screen.getByRole('dialog', { name: 'Modal' }));
40+
expect(results).toHaveNoViolations();
41+
});
42+
});
43+
2844
describe('callbacks', () => {
2945
it('should call onClose callback when dismissed', async () => {
3046
const handleClose = jest.fn();

packages/ui-client/src/components/Modal/GenericModal/GenericModal.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ Warning.args = { variant: 'warning' };
4646
export const Success = Template.bind({});
4747
Success.args = { variant: 'success' };
4848

49+
export const DangerSecondary = Template.bind({});
50+
DangerSecondary.args = { variant: 'secondary-danger' };
51+
4952
export const WithDontAskAgain: StoryFn<typeof GenericModalDoNotAskAgain> = (args) => <GenericModalDoNotAskAgain {...args} />;
5053
WithDontAskAgain.args = {
5154
dontAskAgain: {

packages/ui-client/src/components/Modal/GenericModal/GenericModal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { RequiredModalProps } from './withDoNotAskAgain';
2222
import { withDoNotAskAgain } from './withDoNotAskAgain';
2323
import { modalStore } from '../../../providers/ModalProvider/ModalStore';
2424

25-
type VariantType = 'danger' | 'warning' | 'info' | 'success' | 'upsell';
25+
type VariantType = 'danger' | 'secondary-danger' | 'warning' | 'info' | 'success' | 'upsell';
2626

2727
type GenericModalProps = RequiredModalProps & {
2828
variant?: VariantType;
@@ -50,6 +50,8 @@ const getButtonProps = (variant: VariantType): ComponentProps<typeof Button> =>
5050
switch (variant) {
5151
case 'danger':
5252
return { danger: true };
53+
case 'secondary-danger':
54+
return { secondary: true, danger: true };
5355
case 'warning':
5456
case 'upsell':
5557
return { primary: true };
@@ -59,7 +61,7 @@ const getButtonProps = (variant: VariantType): ComponentProps<typeof Button> =>
5961
};
6062

6163
const renderIcon = (icon: GenericModalProps['icon'], variant: VariantType): ReactNode => {
62-
if (icon === null) {
64+
if (icon === null || iconMap[variant] === undefined) {
6365
return null;
6466
}
6567

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`renders should render a modal without crashing 1`] = `
4+
<dialog
5+
aria-labelledby=":r0:-title"
6+
aria-modal="true"
7+
class="rcx-box rcx-box--full rcx-modal"
8+
open=""
9+
>
10+
<div
11+
class="rcx-box rcx-box--full rcx-modal__inner rcx-css-1e2ego0"
12+
>
13+
<header
14+
class="rcx-box rcx-box--full rcx-modal__header"
15+
>
16+
<div
17+
class="rcx-box rcx-box--full rcx-modal__header-inner"
18+
>
19+
<div
20+
class="rcx-box rcx-box--full rcx-css-trljwa rcx-css-3k19uf"
21+
>
22+
<i
23+
aria-hidden="true"
24+
class="rcx-box rcx-box--full rcx-icon--name-info rcx-icon rcx-css-zozvgz"
25+
>
26+
27+
</i>
28+
</div>
29+
<div
30+
class="rcx-box rcx-box--full rcx-modal__header-text rcx-css-trljwa rcx-css-lma364"
31+
>
32+
<h2
33+
class="rcx-box rcx-box--full rcx-modal__title"
34+
id=":r0:-title"
35+
>
36+
Modal
37+
</h2>
38+
</div>
39+
</div>
40+
</header>
41+
<div
42+
class="rcx-box rcx-box--full rcx-modal__content rcx-css-1vw7itl"
43+
>
44+
<div
45+
class="rcx-box rcx-box--full rcx-modal__content-wrapper rcx-css-r1bpeb"
46+
/>
47+
</div>
48+
<div
49+
class="rcx-box rcx-box--full rcx-modal__footer rcx-css-17mu816"
50+
>
51+
<div
52+
class="rcx-button-group rcx-button-group--align-end"
53+
role="group"
54+
/>
55+
</div>
56+
</div>
57+
</dialog>
58+
`;

0 commit comments

Comments
 (0)