-
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.
Merge pull request #406 from devtron-labs/feat/confirmation-modal
feat: add new confirmation modal
- Loading branch information
Showing
19 changed files
with
550 additions
and
66 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,45 @@ | ||
import { useEffect } from 'react' | ||
import { createPortal } from 'react-dom' | ||
import { motion } from 'framer-motion' | ||
import { useRegisterShortcut } from '@Common/Hooks' | ||
import { preventBodyScroll, preventOutsideFocus } from '@Shared/Helpers' | ||
import { DEVTRON_BASE_MAIN_ID } from '@Shared/constants' | ||
import { BackdropProps } from './types' | ||
|
||
const Backdrop = ({ children, onEscape }: BackdropProps) => { | ||
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 | ||
preventOutsideFocus({ identifier: DEVTRON_BASE_MAIN_ID, preventFocus: true }) | ||
|
||
return () => { | ||
preventBodyScroll(false) | ||
preventOutsideFocus({ identifier: DEVTRON_BASE_MAIN_ID, preventFocus: false }) | ||
} | ||
}, []) | ||
|
||
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('animated-dialog-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 @@ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ReactNode } from 'react' | ||
|
||
export interface BackdropProps { | ||
children: ReactNode | ||
/** | ||
* @param onEscape: please wrap in a useCallback, with respective dependencies or [] | ||
*/ | ||
onEscape: () => void | ||
} |
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.