-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed6af97
commit 7c74924
Showing
12 changed files
with
408 additions
and
138 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,46 @@ | ||
import { ReactNode, useEffect } from 'react' | ||
import { motion } from 'framer-motion' | ||
import { useRegisterShortcut } from '@Common/Hooks' | ||
import { preventBodyScroll, toggleOutsideFocus } from '@Shared/Helpers' | ||
import './backdrop.scss' | ||
import { createPortal } from 'react-dom' | ||
import { ToggleFocusType } from '@Shared/types' | ||
import { DEVTRON_BASE_MAIN_ID } from '@Shared/constants' | ||
|
||
const Backdrop = ({ children, onEscape }: { children: ReactNode; onEscape: () => void }) => { | ||
const { registerShortcut, unregisterShortcut } = useRegisterShortcut() | ||
|
||
// useEffect on onEscape since onEscape might change based on conditions | ||
useEffect(() => { | ||
registerShortcut({ keys: ['Escape'], callback: onEscape }) | ||
|
||
return () => { | ||
unregisterShortcut(['Escape']) | ||
} | ||
}, [onEscape]) | ||
|
||
useEffect(() => { | ||
preventBodyScroll(true) | ||
// Setting main as inert to that focus is trapped inside the new portal | ||
toggleOutsideFocus({ identifier: DEVTRON_BASE_MAIN_ID, toggleFocus: ToggleFocusType.Disable }) | ||
|
||
return () => { | ||
preventBodyScroll(false) | ||
toggleOutsideFocus({ identifier: DEVTRON_BASE_MAIN_ID, toggleFocus: ToggleFocusType.Enable }) | ||
} | ||
}, []) | ||
|
||
return createPortal( | ||
<motion.div | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
exit={{ opacity: 0, transition: { duration: 0.35 } }} | ||
className="backdrop dc__position-fixed dc__top-0 dc__left-0 full-height-width flexbox dc__content-center dc__align-items-center dc__overflow-hidden" | ||
> | ||
{children} | ||
</motion.div>, | ||
document.getElementById('backdrop'), | ||
) | ||
} | ||
|
||
export default Backdrop |
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,5 @@ | ||
.backdrop { | ||
background: #000000bf; | ||
z-index: var(--modal-index); | ||
backdrop-filter: blur(1px); | ||
} |
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 Backdrop } from './Backdrop' |
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
Oops, something went wrong.