-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Client] Back Button component #160: Added BackButton component and a…
…dd related files
- Loading branch information
1 parent
93ce8f1
commit 1bcb906
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useState, useEffect, useRef, Fragment, MouseEvent } from 'react' | ||
import { m } from 'framer-motion' | ||
import { useNavigate, useLocation } from 'react-router-dom' | ||
import { ICON_NAME, useIcon } from 'hook' | ||
import { useSettingContext } from 'component/setting' | ||
import { Typography } from '@mui/material' | ||
import { useTheme } from '@mui/material/styles' | ||
import { KEY, LABEL, TYPOGRAPHY, VARIANT } from 'constant' | ||
import { SPopover, SBackIconButton } from 'component/button' | ||
|
||
const BackButton = () => { | ||
const [open, setOpen] = useState(false) | ||
const [anchorEl, setAnchorEl] = useState<EventTarget | null>(null) | ||
|
||
const { themeMode } = useSettingContext() | ||
const { pathname } = useLocation() | ||
const navigate = useNavigate() | ||
const navRef = useRef(null) | ||
const theme = useTheme() | ||
|
||
const { Icon, iconSrc: backIconSrc } = useIcon(ICON_NAME.BACK) | ||
|
||
const handleClick = (event: MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget) | ||
navigate(-1) | ||
} | ||
|
||
useEffect(() => { | ||
if (open) { | ||
handleClose() | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [pathname]) | ||
|
||
useEffect(() => { | ||
const appBarEl = Array.from(document.querySelectorAll('.MuiAppBar-root')) as HTMLElement[] | ||
|
||
const styles = () => { | ||
document.body.style.overflow = '' | ||
document.body.style.padding = '' | ||
|
||
appBarEl.forEach((elem) => { | ||
elem.style.padding = '' | ||
}) | ||
} | ||
|
||
if (open) { | ||
styles() | ||
} else { | ||
styles() | ||
} | ||
}, [open]) | ||
|
||
const handleOpen = (event: MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget) | ||
setOpen(true) | ||
} | ||
|
||
const handleClose = () => { | ||
setOpen(false) | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<SBackIconButton onClick={handleClick} aria-label={LABEL.GO_BACK} onMouseEnter={handleOpen} onMouseLeave={handleClose}> | ||
<Icon icon={backIconSrc} width={50} /> | ||
</SBackIconButton> | ||
<SPopover | ||
open={open} | ||
anchorEl={anchorEl as Element} | ||
anchorOrigin={{ vertical: KEY.CENTER, horizontal: KEY.RIGHT }} | ||
transformOrigin={{ vertical: KEY.CENTER, horizontal: KEY.LEFT }} | ||
sx={{ | ||
marginLeft: 3 | ||
}}> | ||
<m.div> | ||
<Typography variant={TYPOGRAPHY.BODY1} color={themeMode === KEY.LIGHT ? theme.palette.grey[700] : theme.palette.grey[400]}> | ||
{LABEL.GO_BACK} | ||
</Typography> | ||
</m.div> | ||
</SPopover> | ||
</Fragment> | ||
) | ||
} | ||
|
||
export default BackButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as BackButton } from './back' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { default as Button } from './button' | ||
export { default as BackButton } from './back/back' | ||
export { default as AnimatedButton } from './button-animated' | ||
export * from './style' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters