CodePen
codepen.io › focuswish › pen › ENJjzL
React Modal Example
const display = { display: 'block' }; const hide = { display: 'none' }; class Modal extends React.Component { constructor(props) { super(props); this.toggle = this.toggle.bind(this); this.state = { toggle: false } } toggle(event) { this.setState((prevState) => ({ toggle: !prevState.toggle })); } render() { var modal = []; modal.push( <div className="modal" style={this.state.toggle ?
CodePen
codepen.io › ph1p › pen › XjNONb
Easy react modal
class Modal extends React.Component { static propTypes = { isModalOpen: React.PropTypes.bool.isRequired, closeModal: React.PropTypes.func.isRequired, style: React.PropTypes.shape({ modal: React.PropTypes.object, overlay: React.PropTypes.object }) }; constructor(props) { super(props); this.outerStyle = { position: "fixed", top: 0, left: 0, width: "100%", height: "100%", overflow: "auto", zIndex: 1 }; // default style this.style = { modal: { position: "relative", width: 500, padding: 20, boxSizing: "border-box", backgroundColor: "#fff", margin: "40px auto", borderRadius: 3, zIndex: 2, textAlign:
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 › 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 › carloluis › pen › owQoQr
react-modal
#app { height: 2000px; background: pink; } .no-overflow { overflow: hidden; } * { box-sizing: border-box; } .backdrop { overflow: auto; position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 11; background-color: rgba(36, 45, 52, 0.5); .modal { position: relative; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 12; height: 250px; width: 400px; animation: in 0.4s ease-out; border-radius: 6px; background-color: white; box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.2); padding: 24px; &.out { animation: out 0.4s ease-out; animation-fill-mode: forwa
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() {