CodePen
codepen.io › dav3evans › pen › VgGVGb
React Modal Example
state = { show: false }; // Method to show modal, activated when you clicky the OPEN button showModal = () => { this.setState({ show: true }); }; // Method to hide modal, activated by handleClose prop on the <Modal> hideModal = () => { ...
CodePen
codepen.io › ph1p › pen › XjNONb
Easy react modal
"block" : "none" }} > <div style={this.style.overlay} onClick={this.props.closeModal} /> <div onClick={this.props.closeModal} /> <div style={this.style.modal}>{this.props.children}</div> </div> ); } } // overwrite style const modalStyle = { overlay: { backgroundColor: "rgba(0, 0, 0,0.5)" } }; const mainStyle = { app: { margin: "120px 0" }, button: { backgroundColor: "#408cec", border: 0, padding: "12px 20px", color: "#fff", margin: "0 auto", width: 150, display: "block", borderRadius: 3 } }; class App extends React.Component { constructor(props) { super(props); // set initial state this.state
CodePen
codepen.io › tag › react-modal
Pens tagged 'react-modal' on CodePen
CodePen doesn't work very well without JavaScript · We're all for progressive enhancement, but CodePen is a bit unique in that it's all about writing and showing front end code, including JavaScript. It's required to use most of the features of CodePen · Need to know how to enable it?
CodePen
codepen.io › carloluis › pen › owQoQr
react-modal
const { render } = ReactDOM; const noop = () => {}; function create(Component, props) { return new Promise((resolve, reject) => { const root = document.body; const wrapper = document.getElementById('modal'); const cleanup = () => { ReactDOM.unmountComponentAtNode(wrapper); root.classList.remove('no-overflow'); //wrapper.remove(); }; root.classList.add('no-overflow'); const response = func => response => { cleanup(); func(response); }; const viewProps = { accept: response(resolve), close: response(reject) }; ReactDOM.render(<Component {...props} {...viewProps} />, wrapper); }); } class Modal ex
CodePen
codepen.io › andreasmcdermott › pen › LQNpbg
Bootstrap modal example (React modal)
// Instead the component expects a onClose callback that will be called when user clicks "Close". function MediaModal({children, onClose}) { return ( <div className="modal show" style={{display: 'block'}} > <div className="modal-dialog" role="document"> <div className="modal-content"> <div className="modal-header"> <h5 className="modal-title">Modal title</h5> <button type="button" className="close" aria-label="Close" onClick={onClose} > <span aria-hidden="true">×</span> </button> </div> <div className="modal-body">{children}</div> <div className="modal-footer"> <button className="btn btn-secondary" onClick={onClose} >Close</button> </div> </div> </div> </div> ); } ReactDOM.render( <MediaModal> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
CodePen
codepen.io › deammer › pen › LoMBvp
React modal using hooks
</p> <button type="button" onClick={onRequestClose}> Close this modal </button> <div className="placeholder" /> <div className="placeholder" /> <div className="placeholder medium" /> <div className="placeholder" /> </div> </div> ); }; const App = () => { const [isModalOpen, setModalIsOpen] = useState(false); console.log(useState("hello")[1]) const toggleModal = () => { setModalIsOpen(!isModalOpen); }; return ( <main> {isModalOpen && <Modal onRequestClose={toggleModal} />} <h1>React modal</h1> <p> This Pen shows an example of a controlled modal component built using React hooks, specifically <c
CodePen
codepen.io › baranovxyz › pen › pojLjjB
Simple Modal in React - CodePen
.Modal { /* fixed position will always show modal in the top left corner */ position: fixed; top: 0; left: 0; /* z-index to show modal even if it is used before some other elements */ z-index: 5; /* make modal fill whole window */ width: 100vw; height: 100vh; /* add some background to blur content behind modal */ background: rgba(255, 255, 255, 0.8); /* center content inside modal */ display: flex; justify-content: center; align-items: center; } .Component { min-width: 200px; min-height: 100px; background-color: lightgreen; padding: 20px; } .App { width: 100vw; height: 100vh; text-align: cente
CodePen
codepen.io › jh3y › pen › RwNozBm
Basic Modal w/ React Portals
createPortal( <div className='modal'> <button onClick={onClose} className='modal__close'>×</button> {children} </div>, document.body) : null const App = () => { const [open, setOpen] = useState(false) return ( <Fragment> <button onClick={() => setOpen(!open)}>Show Modal?</button> <Modal open={open} onClose={() => setOpen(false)}> Test Modal </Modal> </Fragment> ) } render(<App/>, document.getElementById('app'))
CodePen
codepen.io › justen › pen › jVvQZP
React Custom Modal Component - CodePen
import * as reactDraggable from "https://cdn.skypack.dev/react-draggable@4.4.4"; class App extends React.Component { constructor(props) { super(props) this.state = { isModalOpen: false } } render() { return ( <div> <button onClick={() => this.openModal()}>Open modal</button> <Modal width={950} height={340} noBackdrop={true} isOpen={this.state.isModalOpen} onClose={() => this.closeModal()} > <h1>Content goes here.</h1> </Modal> </div> ) } openModal() { this.setState({ isModalOpen: true }) } closeModal() { this.setState({ isModalOpen: false }) } } class Modal extends React.Component { render() {