Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

npm modal

import React from 'react';
import ReactDOM from 'react-dom';
import Modal from 'react-modal';

const customStyles = {
  content: {
    top: '50%',
    left: '50%',
    right: 'auto',
    bottom: 'auto',
    marginRight: '-50%',
    transform: 'translate(-50%, -50%)',
  },
};

// Make sure to bind modal to your appElement (https://reactcommunity.org/react-modal/accessibility/)
Modal.setAppElement('#yourAppElement');

function App() {
  let subtitle;
  const [modalIsOpen, setIsOpen] = React.useState(false);

  function openModal() {
    setIsOpen(true);
  }

  function afterOpenModal() {
    // references are now sync'd and can be accessed.
    subtitle.style.color = '#f00';
  }

  function closeModal() {
    setIsOpen(false);
  }

  return (
    <div>
      <button onClick={openModal}>Open Modal</button>
      <Modal
        isOpen={modalIsOpen}
        onAfterOpen={afterOpenModal}
        onRequestClose={closeModal}
        style={customStyles}
        contentLabel="Example Modal"
      >
        <h2 ref={(_subtitle) => (subtitle = _subtitle)}>Hello</h2>
        <button onClick={closeModal}>close</button>
        <div>I am a modal</div>
        <form>
          <input />
          <button>tab navigation</button>
          <button>stays</button>
          <button>inside</button>
          <button>the modal</button>
        </form>
      </Modal>
    </div>
  );
}

ReactDOM.render(<App />, appElement);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to link to certain section of a website in react 
Javascript :: put image in canvas with cover mode 
Javascript :: of rxjs 
Javascript :: create multiple buttons in javascript 
Javascript :: how to create a dynamic function in javascript 
Javascript :: server mail 
Javascript :: ternary operator nodejs 
Javascript :: js variable to string 
Javascript :: print stuff in console javascript 
Javascript :: two dimensional array in javascript 
Javascript :: js export options 
Javascript :: js ?. 
Javascript :: jquery is not defined error in wordpress 
Javascript :: how to search for react icons on vscode 
Javascript :: javascript fuzzy search 
Javascript :: login with facebook expo react native 
Javascript :: mongodb where field is not equal 
Javascript :: shell 
Javascript :: find key in nested json object 
Javascript :: regex for international phone number 
Javascript :: closures 
Javascript :: object loop 
Javascript :: js include another 
Javascript :: axios put api in componentDidMount React 
Javascript :: scroll top javascript 
Javascript :: promise js 
Javascript :: Working of JavaScript Arrays 
Javascript :: javascript Recursionexample 
Javascript :: javascript constructor 
Javascript :: uselayouteffect 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =