Skip to content

Sample application showing how to use responsive modal popup in react.

License

Notifications You must be signed in to change notification settings

CMARIXTechnolabs/react-modal-popup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-modal-popup

license : MIT framework : react npm: modal

A responsive and simple react modals which will be compatible with all latest react versions and other more features. Read documentation on react responsive modal

Installation

npm install react-responsive-modal --save

Simple modal

import React, { Component } from 'react';
import Modal from 'react-responsive-modal';

class App extends Component extends React.Component {

    constructor() {
        super();
        this.state = {
            IsShowMeModalOpen: false,            
        }
    }

    openShowMeModal = () => {
        this.setState({ IsShowMeModalOpen: true });
    }

    closeShowMeModal = (e) => {
        this.setState({ IsShowMeModalOpen: false });
    }

    render() {
        return (
            <div className="App">
                <div className="row">
                    <div className="col-sm-3">
                        <button className="btn btn-default clearfix" onClick={this.openShowMeModal}>Show Me !</button>
                    </div>                    
                </div>

                <Modal open={this.state.IsShowMeModalOpen} center showCloseIcon={false} onClose={this.closeShowMeModal} >
                    <label className="clearfix">Hi there !</label>
                    <button className="btn btn-default pull-right" onClick={this.closeShowMeModal}>Close me !</button>
                </Modal>
            </div>
        );
    }
}

ReactDOM.render(<App />, document.getElementById('app'));

Confirmation modal

import React, { Component } from 'react';
import Modal from 'react-responsive-modal';

class App extends Component extends React.Component {

    constructor() {
        super();
        this.state = {
            IsConfirmationModalOpen: false
        }
    }
        
    openConfirmationModal = () => {
        this.setState({ IsConfirmationModalOpen: true });
    }

    closeConfirmationModal = (e) => {
        if (e.target.dataset.msg !== undefined)
            alert(e.target.dataset.msg);
        this.setState({ IsConfirmationModalOpen: false });
    }

    render() {
        return (
            <div className="App">
                <div className="row">
                    <div className="col-sm-3">
                        <button className="btn btn-primary clearfix" onClick={this.openConfirmationModal}>Show Confirmation !</button>
                    </div>                    
                </div>

                <Modal open={this.state.IsConfirmationModalOpen} center showCloseIcon={false} onClose={this.closeConfirmationModal} >
                    <label className="clearfix">Confirm your message !</label>
                    <button className="btn btn-default" data-msg="you clicked Cancel !" onClick={this.closeConfirmationModal}>Cancel</button>
                    <button className="btn btn-primary pull-right" data-msg="you clicked Ok !" onClick={this.closeConfirmationModal}>Ok</button>
                </Modal>
            </div>
        );
    }
}

ReactDOM.render(<App />, document.getElementById('app'));

Let us know!

We’d be really happy if you sent us links of your projects where you use our component. For this simple endeavor you can email us to biz@cmarix.com and on the same email do share your queries, questions or suggestions you have regarding react.

P.S. We’re going to publish more awesome examples on third party libraries, coding standards, plugins and more for all technologies. Stay tuned!

Stay Socially Connected

Get more familiar with our work by visiting few of our portfolio links.

Portfolio | Facebook | Twitter | Linkedin | Behance | Instagram | Dribbble | Uplabs

Please don’t forget to follow them.

License

MIT License

Copyright © 2019 CMARIX TechnoLabs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.