-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Close modal on backdrop/overlay click or on Esc keydown (#403)
* added feature to close overlay on backdrop click * added escape event listener to close modal
- Loading branch information
1 parent
d4eaca2
commit 5ec34ff
Showing
6 changed files
with
59 additions
and
30 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
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 |
---|---|---|
@@ -1,22 +1,26 @@ | ||
import React from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
import { Box } from '../Box'; | ||
|
||
export const ModalBackdrop = ({ children }) => ( | ||
<Box | ||
style={{ | ||
position: 'fixed', | ||
zIndex: 10000, | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
background: '#333333B3', | ||
width: '100%', | ||
height: '100%', | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
); | ||
export const ModalBackdrop = forwardRef(({ children, onClick = () => { } }, ref) => { | ||
return ( | ||
<Box | ||
ref={ref} | ||
onClick={onClick} | ||
style={{ | ||
position: 'fixed', | ||
zIndex: 10000, | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
background: '#333333B3', | ||
width: '100%', | ||
height: '100%', | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
) | ||
}); |
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