Skip to content

Commit 677ad88

Browse files
subhajit20kylemh
andauthored
Coverted all the css into Tailwind css of Modal component (#1743)
Co-authored-by: Kyle Holmberg <[email protected]> Co-authored-by: Kyle Holmberg <[email protected]>
1 parent 8b25439 commit 677ad88

File tree

12 files changed

+305
-82
lines changed

12 files changed

+305
-82
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ module.exports = {
167167
'implicit-arrow-linebreak': 'off',
168168
'multiline-ternary': 'off',
169169
'no-console': 'warn',
170+
'no-extra-boolean-cast': 'off',
170171
'no-promise-executor-return': 'off',
171172
'no-restricted-imports': [
172173
'error',

.storybook/main.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ const svgoConfig = require('../common/config/svgo');
33
const config = {
44
stories: ['../components/**/__stories__/*.stories.js'],
55
staticDirs: ['../public'],
6-
addons: ['@storybook/addon-essentials'],
6+
addons: [
7+
'@storybook/addon-essentials',
8+
{
9+
name: '@storybook/addon-styling',
10+
/** @see https://storybook.js.org/recipes/tailwindcss#:~:text=then%20leave%20the%20options%20object%20empty. */
11+
options: {},
12+
},
13+
],
714
webpackFinal: async config => {
815
// Find the Storybook Webpack rule relevant to SVG files.
916
const imageRule = config.module.rules.find(rule => {

components/Cards/Card/Card.module.css

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
padding: 1.5rem;
1313
}
1414

15-
.CardModal {
16-
background-color: var(--secondary);
17-
color: var(--white);
18-
}
19-
20-
.CardModal a {
21-
color: var(--primary);
22-
}
23-
24-
.CardModal h2 {
25-
font-size: 1.5em;
26-
}
27-
2815
.Card svg {
2916
fill: var(--secondary);
3017
}

components/Modal/Modal.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ import { node, string, bool, func } from 'prop-types';
22
import classNames from 'classnames';
33
import * as Dialog from '@radix-ui/react-dialog';
44
import { gtag } from 'common/utils/thirdParty/gtag';
5-
import CardStyles from 'components/Cards/Card/Card.module.css';
65
import CloseButton from 'components/Buttons/CloseButton/CloseButton';
76
import { MODAL_CONTENT, MODAL_OVERLAY } from 'common/constants/testIDs';
8-
import ModalStyles from './Modal.module.css';
97

108
Modal.propTypes = {
119
children: node.isRequired,
1210
className: string,
1311
isOpen: bool,
1412
onRequestClose: func.isRequired,
1513
screenReaderLabel: string.isRequired, // basically a summarizing title
16-
shouldCloseOnOverlayClick: bool,
14+
canClose: bool,
1715
childrenClassName: string,
1816
};
1917

2018
Modal.defaultProps = {
2119
className: undefined,
2220
isOpen: false,
23-
shouldCloseOnOverlayClick: true,
21+
canClose: true,
2422
childrenClassName: undefined,
2523
};
2624

@@ -30,27 +28,56 @@ function Modal({
3028
isOpen,
3129
onRequestClose,
3230
screenReaderLabel,
33-
shouldCloseOnOverlayClick,
31+
canClose,
3432
childrenClassName,
3533
}) {
3634
if (isOpen) {
3735
gtag.modalView(screenReaderLabel);
3836
}
3937

38+
const portalContainer =
39+
typeof window !== 'undefined' ? document.querySelector('#__next') ?? undefined : undefined;
40+
4041
return (
4142
<Dialog.Root defaultOpen={false} open={isOpen}>
42-
<Dialog.Portal>
43+
<Dialog.Portal container={portalContainer}>
4344
<Dialog.Overlay
44-
className={ModalStyles.overlay}
45-
onClick={shouldCloseOnOverlayClick ? onRequestClose : undefined}
45+
className="inset-0 fixed bg-white/50 z-[2]"
46+
onClick={canClose ? onRequestClose : undefined}
4647
data-testid={MODAL_OVERLAY}
4748
>
48-
<Dialog.Close asChild>
49-
<CloseButton theme="secondary" onClick={onRequestClose} />
50-
</Dialog.Close>
49+
{canClose && (
50+
<Dialog.Close asChild>
51+
<CloseButton theme="secondary" onClick={onRequestClose} />
52+
</Dialog.Close>
53+
)}
5154
</Dialog.Overlay>
55+
5256
<Dialog.Content
53-
className={classNames(CardStyles.Card, className, ModalStyles.modalContent)}
57+
className={classNames(
58+
'outline-none',
59+
'bg-white',
60+
'text-secondary',
61+
'flex',
62+
'flex-col',
63+
'flex-nowrap',
64+
'm-4',
65+
'min-h-[100px]',
66+
'min-w-[100px]',
67+
'p-6',
68+
'fixed',
69+
'items-center',
70+
'justify-center',
71+
'overflow-hidden',
72+
'w-[80%]',
73+
'top-1/2',
74+
'left-1/2',
75+
'-translate-x-1/2',
76+
'-translate-y-1/2',
77+
'z-[2]',
78+
'shadow-md',
79+
className,
80+
)}
5481
>
5582
<div className={childrenClassName} data-testid={MODAL_CONTENT}>
5683
{children}

components/Modal/Modal.module.css

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,78 @@
11
import { useState } from 'react';
2+
import isChromatic from 'chromatic/isChromatic';
3+
24
import { descriptions } from 'common/constants/descriptions';
5+
import Button from 'components/Buttons/Button/Button';
36
import Modal from '../Modal';
47

58
export const Default = {
69
render: args => {
710
const [isDemoModalOpen, setIsDemoModalOpen] = useState(args.isOpen);
811

912
return (
10-
<Modal
11-
{...args}
12-
isOpen={isDemoModalOpen}
13-
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
14-
/>
13+
<>
14+
<Button onClick={() => setIsDemoModalOpen(true)}>Open Modal</Button>
15+
16+
<Modal
17+
{...args}
18+
isOpen={isDemoModalOpen}
19+
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
20+
/>
21+
</>
1522
);
1623
},
1724
args: {
18-
isOpen: true,
25+
isOpen: !!isChromatic(),
1926
children: descriptions.medium,
2027
screenReaderLabel: 'You have completed the form.',
2128
},
2229
};
2330

24-
export const NoCloseOnOverlayClick = {
31+
export const NonDismissableModal = {
2532
render: args => {
2633
const [isDemoModalOpen, setIsDemoModalOpen] = useState(args.isOpen);
2734

2835
return (
29-
<Modal
30-
{...args}
31-
isOpen={isDemoModalOpen}
32-
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
33-
/>
36+
<>
37+
<Button onClick={() => setIsDemoModalOpen(true)}>Open Modal</Button>
38+
39+
<Modal
40+
{...args}
41+
isOpen={isDemoModalOpen}
42+
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
43+
/>
44+
</>
3445
);
3546
},
3647
args: {
37-
shouldCloseOnOverlayClick: false,
38-
isOpen: true,
39-
children: descriptions.medium,
48+
canClose: false,
49+
isOpen: false,
50+
children: (
51+
<>
52+
<p>
53+
This modal will not close once opened. You must reload the page to reset the state in
54+
Storybook.
55+
</p>
56+
<p>{descriptions.medium}</p>
57+
</>
58+
),
4059
screenReaderLabel: 'You have completed the form.',
4160
},
4261
};
4362

4463
const meta = {
4564
title: 'Modal',
4665
component: Modal,
66+
parameters: {
67+
previewTabs: {
68+
'storybook/docs/panel': { hidden: true },
69+
},
70+
docs: {
71+
autodocs: false,
72+
disable: true,
73+
page: null,
74+
},
75+
},
4776
};
4877

4978
export default meta;

components/Modal/__tests__/__snapshots__/Modal.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports[`Modal should render with many props assigned 1`] = `
1717
/>
1818
<div
1919
aria-hidden="true"
20-
class="overlay"
20+
class="inset-0 fixed bg-white/50 z-[2]"
2121
data-aria-hidden="true"
2222
data-state="open"
2323
data-testid="MODAL_OVERLAY"
@@ -42,7 +42,7 @@ exports[`Modal should render with many props assigned 1`] = `
4242
<div
4343
aria-describedby="radix-:r5:"
4444
aria-labelledby="radix-:r4:"
45-
class="Card test-class modalContent"
45+
class="outline-none bg-white text-secondary flex flex-col flex-nowrap m-4 min-h-[100px] min-w-[100px] p-6 fixed items-center justify-center overflow-hidden w-[80%] top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[2] shadow-md test-class"
4646
data-state="open"
4747
id="radix-:r3:"
4848
role="dialog"

components/UpgradeBrowserOverlay/UpgradeBrowserOverlay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function UpgradeBrowserOverlay() {
3737
screenReaderLabel="Upgrade Your Browser"
3838
isOpen
3939
overlayClassName={styles.overlay}
40-
shouldCloseOnOverlayClick={false}
40+
canClose={false}
4141
>
4242
<WarningSign className={styles.warningLogo} />
4343
<h1>Please Upgrade Your Browser</h1>

components/UpgradeBrowserOverlay/__tests__/__snapshots__/UpgradeBrowserOverlay.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
exports[`UpgradeBrowserOverlay should render with no props passed 1`] = `
44
<Modal
5+
canClose={false}
56
className="UpgradeBrowserOverlay"
67
isOpen={true}
78
onRequestClose={[Function]}
89
overlayClassName="overlay"
910
screenReaderLabel="Upgrade Your Browser"
10-
shouldCloseOnOverlayClick={false}
1111
>
1212
<Svg
1313
className="warningLogo"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"@storybook/addon-essentials": "^7.4.1",
9191
"@storybook/addon-links": "^7.4.1",
9292
"@storybook/addon-postcss": "^2.0.0",
93+
"@storybook/addon-styling": "^1.3.7",
9394
"@storybook/addons": "^7.4.1",
9495
"@storybook/nextjs": "^7.4.1",
9596
"@storybook/react": "^7.4.1",

0 commit comments

Comments
 (0)