Skip to content

Commit

Permalink
Merge pull request #125 from shoonia/Use-dialog-element-instead-react…
Browse files Browse the repository at this point in the history
…-modal

Use dialog element instead react modal
  • Loading branch information
shoonia authored Jul 9, 2024
2 parents e615b19 + 56b5d4a commit a19815d
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 348 deletions.
431 changes: 192 additions & 239 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@
"cron-validator": "^1.3.1",
"cronstrue": "^2.50.0",
"parse-json": "^8.1.0",
"preact": "^10.22.0",
"preact": "^10.22.1",
"react-hint": "^3.2.1",
"react-modal": "^3.16.1",
"storeon": "^3.1.5",
"strip-json-comments": "^5.0.1"
},
"devDependencies": {
"@babel/plugin-transform-react-jsx": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@evilmartians/lefthook": "^1.6.17",
"@evilmartians/lefthook": "^1.7.1",
"@types/css-modules": "^1.0.5",
"@types/node": "^20.14.6",
"@types/node": "^20.14.10",
"@types/react-hint": "^3.2.3",
"@types/react-modal": "^3.16.3",
"@types/wicg-file-system-access": "^2023.10.5",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@typescript-eslint/eslint-plugin": "^7.16.0",
"@typescript-eslint/parser": "^7.16.0",
"autoprefixer": "^10.4.19",
"babel-loader": "^9.1.3",
"babel-plugin-transform-remove-polyfill": "^0.24.1",
Expand All @@ -47,17 +46,17 @@
"html-webpack-plugin": "^5.6.0",
"mini-css-class-name": "^0.15.1",
"mini-css-extract-plugin": "^2.9.0",
"postcss": "^8.4.38",
"postcss": "^8.4.39",
"postcss-import": "^16.1.0",
"postcss-loader": "^8.1.1",
"postcss-simple-vars": "^7.0.1",
"style-loader": "^4.0.0",
"stylelint": "^16.6.1",
"stylelint-config-css-modules": "^4.4.0",
"stylelint-config-standard": "^36.0.0",
"stylelint-config-standard": "^36.0.1",
"terser-webpack-plugin": "^5.3.10",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript": "^5.5.3",
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4"
Expand Down
37 changes: 0 additions & 37 deletions plugins/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,6 @@ const isMatch = (node, pattern) => {
return Object.is(node, pattern);
};

const components = new Set([
'Modal',
'ModalPortal',
]);

/**
* @type {import('@babel/types').AssignmentExpression}
* @example
* ```
* Name.propTypes =
* ```
*/
const propTypes = {
operator: '=',
right: { type: 'ObjectExpression' },
left: {
type: 'MemberExpression',
computed: false,
object: { type: 'Identifier' },
property: {
type: 'Identifier',
name: 'propTypes',
},
},
};

/**
* @type {import('@babel/types').CallExpression}
* @example
Expand Down Expand Up @@ -101,17 +75,6 @@ const plugin = () => {
return {
name: 'minimizer',
visitor: {
AssignmentExpression(path) {
const { node } = path;

if (
isMatch(node, propTypes) &&
components.has(node.left.object.name)
) {
path.remove();
}
},

CallExpression(path) {
const { node } = path;

Expand Down
2 changes: 2 additions & 0 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Header } from './Header';
import { Tooltips } from './Tooltip';
import { UploadModal } from './UploadModal';
import { useLazyRouter } from '../hooks/useLazyRouter';

export const App: FC = () => {
Expand All @@ -10,6 +11,7 @@ export const App: FC = () => {
<Header />
<Page />
<Tooltips />
<UploadModal />
</>
);
};
23 changes: 5 additions & 18 deletions src/components/Builder/Builder.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import s from './styles.css';
import { useStoreon } from '../../store';
import { ROUTER } from '../../constants';
import { Editor } from '../Editor';
import { Preview } from '../Preview';
import { UploadModal } from '../UploadModal';

export const Builder: FC = () => {
const { path } = useStoreon('path');

const uploadModal = path === ROUTER.UPLOAD && (
<UploadModal />
);

return (
<div className={s.box}>
<Editor />
<Preview />
{uploadModal}
</div>
);
};
export const Builder: FC = () =>
<div className={s.box}>
<Editor />
<Preview />
</div>;
2 changes: 0 additions & 2 deletions src/components/Jobs/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
box-shadow: 0 0 25px 0 rgb(0 0 0 / 8%);
position: relative;
transition: box-shadow 0.2s ease-out;
z-index: 1;
}

.item:hover {
box-shadow: 0 4px 30px 0 rgb(0 0 0 / 16%);
z-index: 2;
}

.item:invalid {
Expand Down
41 changes: 20 additions & 21 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import type { ComponentClass } from 'preact';
import ReactModal from 'react-modal';

import { useEffect, useRef } from 'preact/hooks';
import s from './styles.css';

interface Props {
label: string;
close: () => void;
open: boolean;
}

ReactModal.setAppElement('#app');
export const Modal: FC<Props> = ({ open, children }) => {
const ref = useRef<HTMLDialogElement>(null);

// @ts-expect-error @typescript-eslint/ban-ts-comment
const ReactModalPreactTyped: ComponentClass<ReactModal.Props> = ReactModal;
useEffect(() => {
if (open) {
ref.current?.showModal();
} else {
ref.current?.close();
}
}, [open]);

export const Modal: FC<Props> = ({ close, label, children }) => (
<ReactModalPreactTyped
isOpen
onRequestClose={close}
contentLabel={label}
overlayClassName={s.overlay}
className={s.modal}
bodyOpenClassName={s.bodyOpen}
htmlOpenClassName={s.rootOpen}
>
{children as []}
</ReactModalPreactTyped>
);
return (
<dialog
ref={ref}
className={s.modal}
>
{children}
</dialog>
);
};
25 changes: 9 additions & 16 deletions src/components/Modal/styles.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
.overlay {
background-color: rgb(22 45 61 / 66%);
position: fixed;
inset: 0;
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
z-index: 10;
}

.bodyOpen,
.rootOpen {
overflow: hidden;
}
@import url('../../styles/vars.css');

.modal {
outline: none;
border-radius: 8px;
max-height: 100%;
padding: 0;
border: none;
color: $color-font;
overflow-x: hidden;
}

.modal::backdrop {
background-color: rgb(22 45 61 / 66%);
}
5 changes: 4 additions & 1 deletion src/components/UploadModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { JSX } from 'preact';
import { useRef } from 'preact/hooks';
import { useStoreon } from 'storeon/preact';

import s from './styles.css';
import { dispatch } from '../../store';
Expand Down Expand Up @@ -41,6 +42,7 @@ const onLoad = (val: string) => {
};

export const UploadModal: FC = () => {
const { path } = useStoreon('path');
const ref = useRef<string>('');

const onInput: JSX.InputEventHandler<HTMLTextAreaElement> = (event) => {
Expand All @@ -53,8 +55,9 @@ export const UploadModal: FC = () => {
};

return (
<Modal label="Upload form" close={close}>
<Modal open={path === ROUTER.UPLOAD}>
<form
method="dialog"
onSubmit={onSubmit}
className={s.box}
>
Expand Down
5 changes: 0 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ const buildConfig = ({ NODE_ENV }) => {
// parse-json
'@babel/highlight': '{shouldHighlight(){}}',
'picocolors': '{}',
// react-modal
'react-lifecycles-compat': '{polyfill(){}}',
'exenv': '{canUseDOM:true}',
'prop-types': '{}',
'warning': 'e=>e',
},
module: {
parser: {
Expand Down

0 comments on commit a19815d

Please sign in to comment.