Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverted all the css into Tailwind css of Modal component #1743

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
42bf6db
Converted all the css to tailwind css of ErrorDisplay page
subhajit20 Sep 18, 2023
827b21d
Converted all the css to tailwind css of ErrorDisplay page
subhajit20 Sep 18, 2023
dc7b10e
Converted all css to tailwind css
subhajit20 Sep 18, 2023
23a6499
Replace all styling with Tailwind
subhajit20 Sep 18, 2023
1055b07
Replace all styling with Tailwind
subhajit20 Sep 18, 2023
1299eac
Converted all the css into tailwind css of Badge component
subhajit20 Sep 19, 2023
71a9b5c
Merge branch 'main' into subhajit20/Replace-all-styling-with-Tailwind
subhajit20 Sep 19, 2023
46f136d
Converted all the css into Tailwind css of Badge component
subhajit20 Sep 19, 2023
be04445
Merge branch 'main' into subhajit20/Replace-all-styling-with-Tailwind
subhajit20 Sep 19, 2023
7462502
Update components/Badge/Badge.js
subhajit20 Sep 19, 2023
e67dbca
Fixed syntax error
subhajit20 Sep 19, 2023
b7ec44a
Merge remote-tracking branch 'origin/main' into subhajit20/Replace-al…
kylemh Sep 20, 2023
d371d87
resolve styling problems
kylemh Sep 20, 2023
44f4e1b
Convert all the css into tailwind css of SocialMedia component
subhajit20 Sep 21, 2023
1339530
Convert all the css into tailwind css of SocialMedia component
subhajit20 Sep 21, 2023
96d04fc
Merge branch 'main' into subhajit20/Replace-all-styling-with-Tailwind
subhajit20 Sep 21, 2023
116d86b
Update components/SocialMedia/SocialMediaItem/SocialMediaItem.js
subhajit20 Sep 22, 2023
0e2a6d0
Convert all the css into tailwind css of SocialMedia component
subhajit20 Sep 22, 2023
b59594e
Converted all the css into tailwind css of Modal component
subhajit20 Sep 23, 2023
c377581
Merge branch 'main' into subhajit20/Replace-all-styling-with-Tailwind
subhajit20 Sep 23, 2023
71dbf56
Converted all the css into tailwind css of Modal compononent
subhajit20 Sep 23, 2023
db5f1b7
Converted all the css into tailwind css of Modal compononent
subhajit20 Sep 23, 2023
cd9ceca
Converted all the css into tailwind css of Modal compononent
subhajit20 Sep 23, 2023
ed3a348
remove dumb lint rule
kylemh Sep 23, 2023
310f33d
integrate tailwind into Storybook
kylemh Sep 23, 2023
75d204b
update modal API and fix issue where modal would not render
kylemh Sep 23, 2023
b518d21
update snapshot tests
kylemh Sep 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ module.exports = {
'implicit-arrow-linebreak': 'off',
'multiline-ternary': 'off',
'no-console': 'warn',
'no-extra-boolean-cast': 'off',
'no-promise-executor-return': 'off',
'no-restricted-imports': [
'error',
Expand Down
9 changes: 8 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ const svgoConfig = require('../common/config/svgo');
const config = {
stories: ['../components/**/__stories__/*.stories.js'],
staticDirs: ['../public'],
addons: ['@storybook/addon-essentials'],
addons: [
'@storybook/addon-essentials',
{
name: '@storybook/addon-styling',
/** @see https://storybook.js.org/recipes/tailwindcss#:~:text=then%20leave%20the%20options%20object%20empty. */
options: {},
},
],
webpackFinal: async config => {
// Find the Storybook Webpack rule relevant to SVG files.
const imageRule = config.module.rules.find(rule => {
Expand Down
13 changes: 0 additions & 13 deletions components/Cards/Card/Card.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
padding: 1.5rem;
}

.CardModal {
background-color: var(--secondary);
color: var(--white);
}

.CardModal a {
color: var(--primary);
}

.CardModal h2 {
font-size: 1.5em;
}

.Card svg {
fill: var(--secondary);
}
Expand Down
51 changes: 39 additions & 12 deletions components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ import { node, string, bool, func } from 'prop-types';
import classNames from 'classnames';
import * as Dialog from '@radix-ui/react-dialog';
import { gtag } from 'common/utils/thirdParty/gtag';
import CardStyles from 'components/Cards/Card/Card.module.css';
import CloseButton from 'components/Buttons/CloseButton/CloseButton';
import { MODAL_CONTENT, MODAL_OVERLAY } from 'common/constants/testIDs';
import ModalStyles from './Modal.module.css';

Modal.propTypes = {
children: node.isRequired,
className: string,
isOpen: bool,
onRequestClose: func.isRequired,
screenReaderLabel: string.isRequired, // basically a summarizing title
shouldCloseOnOverlayClick: bool,
canClose: bool,
childrenClassName: string,
};

Modal.defaultProps = {
className: undefined,
isOpen: false,
shouldCloseOnOverlayClick: true,
canClose: true,
childrenClassName: undefined,
};

Expand All @@ -30,27 +28,56 @@ function Modal({
isOpen,
onRequestClose,
screenReaderLabel,
shouldCloseOnOverlayClick,
canClose,
childrenClassName,
}) {
if (isOpen) {
gtag.modalView(screenReaderLabel);
}

const portalContainer =
Copy link
Member

@kylemh kylemh Sep 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @subhajit20 ! I dove into this one rather than spend more of your time than you bargained for...

The issue where the modal was not rendering is explained because we use '#__next' in the "important" config. Radix's Dialog component uses React Portal to render as a direct child of body rather than the div with the #__next ID (as screenshotted). We needed to specifiy the container prop on the Dialog.Portal component so that Tailwind's styles actually applied!

Screenshot 2023-09-23 at 11 38 34 PM

I also made it so Tailwind works in Storybook.

I made some other changes, but nothing you need to worry about! Great work again.

typeof window !== 'undefined' ? document.querySelector('#__next') ?? undefined : undefined;

return (
<Dialog.Root defaultOpen={false} open={isOpen}>
<Dialog.Portal>
<Dialog.Portal container={portalContainer}>
<Dialog.Overlay
className={ModalStyles.overlay}
onClick={shouldCloseOnOverlayClick ? onRequestClose : undefined}
className="inset-0 fixed bg-white/50 z-[2]"
onClick={canClose ? onRequestClose : undefined}
data-testid={MODAL_OVERLAY}
>
<Dialog.Close asChild>
<CloseButton theme="secondary" onClick={onRequestClose} />
</Dialog.Close>
{canClose && (
<Dialog.Close asChild>
<CloseButton theme="secondary" onClick={onRequestClose} />
</Dialog.Close>
)}
</Dialog.Overlay>

<Dialog.Content
className={classNames(CardStyles.Card, className, ModalStyles.modalContent)}
className={classNames(
'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',
className,
)}
>
<div className={childrenClassName} data-testid={MODAL_CONTENT}>
{children}
Expand Down
34 changes: 0 additions & 34 deletions components/Modal/Modal.module.css

This file was deleted.

59 changes: 44 additions & 15 deletions components/Modal/__stories__/Modal.stories.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,78 @@
import { useState } from 'react';
import isChromatic from 'chromatic/isChromatic';

import { descriptions } from 'common/constants/descriptions';
import Button from 'components/Buttons/Button/Button';
import Modal from '../Modal';

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

return (
<Modal
{...args}
isOpen={isDemoModalOpen}
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
/>
<>
<Button onClick={() => setIsDemoModalOpen(true)}>Open Modal</Button>

<Modal
{...args}
isOpen={isDemoModalOpen}
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
/>
</>
);
},
args: {
isOpen: true,
isOpen: !!isChromatic(),
children: descriptions.medium,
screenReaderLabel: 'You have completed the form.',
},
};

export const NoCloseOnOverlayClick = {
export const NonDismissableModal = {
render: args => {
const [isDemoModalOpen, setIsDemoModalOpen] = useState(args.isOpen);

return (
<Modal
{...args}
isOpen={isDemoModalOpen}
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
/>
<>
<Button onClick={() => setIsDemoModalOpen(true)}>Open Modal</Button>

<Modal
{...args}
isOpen={isDemoModalOpen}
onRequestClose={prevValue => setIsDemoModalOpen(!prevValue)}
/>
</>
);
},
args: {
shouldCloseOnOverlayClick: false,
isOpen: true,
children: descriptions.medium,
canClose: false,
isOpen: false,
children: (
<>
<p>
This modal will not close once opened. You must reload the page to reset the state in
Storybook.
</p>
<p>{descriptions.medium}</p>
</>
),
screenReaderLabel: 'You have completed the form.',
},
};

const meta = {
title: 'Modal',
component: Modal,
parameters: {
previewTabs: {
'storybook/docs/panel': { hidden: true },
},
docs: {
autodocs: false,
disable: true,
page: null,
},
},
};

export default meta;
4 changes: 2 additions & 2 deletions components/Modal/__tests__/__snapshots__/Modal.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`Modal should render with many props assigned 1`] = `
/>
<div
aria-hidden="true"
class="overlay"
class="inset-0 fixed bg-white/50 z-[2]"
data-aria-hidden="true"
data-state="open"
data-testid="MODAL_OVERLAY"
Expand All @@ -42,7 +42,7 @@ exports[`Modal should render with many props assigned 1`] = `
<div
aria-describedby="radix-:r5:"
aria-labelledby="radix-:r4:"
class="Card test-class modalContent"
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"
data-state="open"
id="radix-:r3:"
role="dialog"
Expand Down
2 changes: 1 addition & 1 deletion components/UpgradeBrowserOverlay/UpgradeBrowserOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function UpgradeBrowserOverlay() {
screenReaderLabel="Upgrade Your Browser"
isOpen
overlayClassName={styles.overlay}
shouldCloseOnOverlayClick={false}
canClose={false}
>
<WarningSign className={styles.warningLogo} />
<h1>Please Upgrade Your Browser</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

exports[`UpgradeBrowserOverlay should render with no props passed 1`] = `
<Modal
canClose={false}
className="UpgradeBrowserOverlay"
isOpen={true}
onRequestClose={[Function]}
overlayClassName="overlay"
screenReaderLabel="Upgrade Your Browser"
shouldCloseOnOverlayClick={false}
>
<Svg
className="warningLogo"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@storybook/addon-essentials": "^7.4.1",
"@storybook/addon-links": "^7.4.1",
"@storybook/addon-postcss": "^2.0.0",
"@storybook/addon-styling": "^1.3.7",
"@storybook/addons": "^7.4.1",
"@storybook/nextjs": "^7.4.1",
"@storybook/react": "^7.4.1",
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
extend: {
colors: {
themeGray: '#121212',
secondary: '#252e3e',
},
},
},
Expand Down
Loading