React Cool Portal
🚧 This library is in-progress. Milestone as below:
💡 My Idea
The following example shows you how to create your own modal component by react-cool-portal
.
import React from 'react';
import usePortal from 'react-cool-portal';
const App = () => {
const { Portal, isShow, show, hide, toggle } = usePortal({
containerId: 'my-portal-root',
defaultShow: false,
clickOutsideToHide: true,
escToHide: true,
onShow: e => {
},
onHide: e => {
}
});
return (
<div>
<button onClick={show}>Open Modal</button>
<button onClick={hide}>Close Modal</button>
<button onClick={toggle}>Toggle Modal</button>
<Portal>
{/* The "isShow" can be used to control CSS transition, animation */}
<div class={`modal ${isShow ? 'fade-in' : 'fade-out'}`} role="dialog">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
</div>
<div class="modal-body">
<p>Modal body text goes here.</p>
</div>
</div>
</Portal>
</div>
);
};