Skip to content

Commit

Permalink
fix(form-ux): create smoothness between nested dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ngyngcphu committed Oct 1, 2023
1 parent c9e391b commit 96b899a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/components/home/ChooseFileBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { Dialog, DialogBody } from '@material-tailwind/react';
import { useUploadDocumentBox } from './UploadDocumentBox';

// Loc's task in here.
// This style is using custom hook. See ../common/SidebarMenu.tsx
// This hook is used in ./src/pages/HomePage.tsx

export function useChooseFileBox() {
const { openUploadDocumentBox, UploadDocumentBox } = useUploadDocumentBox();

const [openBox, setOpenBox] = useState<boolean>(false);

const ChooseFileBox = useMemo(
Expand All @@ -17,7 +15,14 @@ export function useChooseFileBox() {
return (
<>
<Dialog open={openBox} handler={handleOpenBox}>
<DialogBody onClick={openUploadDocumentBox}>A</DialogBody>
<DialogBody
onClick={() => {
setOpenBox(false);
openUploadDocumentBox();
}}
>
A
</DialogBody>
</Dialog>
{<UploadDocumentBox />}
</>
Expand Down
17 changes: 11 additions & 6 deletions src/components/home/UploadDocumentBox.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { useState } from 'react';
import { useMemo, useState } from 'react';
import { Dialog, DialogBody } from '@material-tailwind/react';

export function useUploadDocumentBox() {
const [openBox, setOpenBox] = useState<boolean>(false);
const handleOpenBox = () => setOpenBox(!openBox);

const UploadDocumentBox = () => (
<Dialog open={openBox} handler={handleOpenBox} size='xxl'>
<DialogBody>A</DialogBody>
</Dialog>
const UploadDocumentBox = useMemo(
() => () => {
const handleOpenBox = () => setOpenBox(!openBox);
return (
<Dialog open={openBox} handler={handleOpenBox} size='xxl'>
<DialogBody>A</DialogBody>
</Dialog>
);
},
[openBox]
);

return {
Expand Down

0 comments on commit 96b899a

Please sign in to comment.