Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Modal Dialogs in React

import React from 'react';

class Modal extends React.Component {
  render() {
    // Render nothing if the "show" prop is false
    if(!this.props.show) {
      return null;
    }
    
    // The gray background
    const backdropStyle = {
      position: 'fixed',
      top: 0,
      bottom: 0,
      left: 0,
      right: 0,
      backgroundColor: 'rgba(0,0,0,0.3)',
      padding: 50
    };

    // The modal "window"
    const modalStyle = {
      backgroundColor: '#fff',
      borderRadius: 5,
      maxWidth: 500,
      minHeight: 300,
      margin: '0 auto',
      padding: 30
    };

    return (
      <div className="backdrop" style={backdropStyle}>
        <div className="modal" style={modalStyle}>
          {this.props.children}

          <div className="footer">
            <button onClick={this.props.onClose}>
              Close
            </button>
          </div>
        </div>
      </div>
    );
  }
}

Modal.propTypes = {
  onClose: React.PropTypes.func.isRequired,
  show: React.PropTypes.bool,
  children: React.PropTypes.node
};

export default Modal;
Comment

PREVIOUS NEXT
Code Example
Javascript :: document get child element by id 
Javascript :: replace characters form array 
Javascript :: every() method 
Javascript :: node save wav base64 
Javascript :: array length in javascript 
Javascript :: how to use findoneandupdate 
Javascript :: onfocus 
Javascript :: node js add new object to object array json 
Javascript :: pass data between pages react 
Javascript :: change module name react native android studio 
Javascript :: rest api full form 
Javascript :: start animation with javascript 
Javascript :: datatable on change event jquery 
Javascript :: react-query dependent query 
Javascript :: how to run node js with proxy 
Javascript :: electron ipc from main to renderer 
Javascript :: vue date filter component 
Javascript :: javascript set style attribute 
Javascript :: angular.toJson 
Javascript :: hostlistener 
Javascript :: async function in variable 
Javascript :: javascript number if .00 truncate 
Javascript :: open ai gym 
Javascript :: how to add icons in angular 
Javascript :: js match img 
Javascript :: material ui react card 
Javascript :: how to split by words and punctuation in javascript 
Javascript :: expo dependencies 
Javascript :: setCenter: not a LatLng or LatLngLiteral with finite coordinates: in property lat: not a number 
Javascript :: connect to existing collection mongoose 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =