mirror of
https://github.com/morten-olsen/react-native-debug-console.git
synced 2026-02-08 00:36:26 +01:00
V2 (#1)
This commit is contained in:
41
packages/lib/src/components/base/Modal/index.web.js
Normal file
41
packages/lib/src/components/base/Modal/index.web.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
position: fixed;
|
||||
background: #fff;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
`;
|
||||
|
||||
const Modal = ({
|
||||
visible,
|
||||
children
|
||||
}) => {
|
||||
const [root, setRoot] = useState();
|
||||
useEffect(() => {
|
||||
const elm = document.createElement('div');
|
||||
document.body.appendChild(elm);
|
||||
setRoot(elm);
|
||||
}, []);
|
||||
|
||||
const elm = visible ? (
|
||||
<Wrapper>{children}</Wrapper>
|
||||
) : null;
|
||||
|
||||
if (!root) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createPortal(
|
||||
elm,
|
||||
root,
|
||||
);
|
||||
};
|
||||
|
||||
export default Modal;
|
||||
Reference in New Issue
Block a user