react_modal_library

0.8.2 • Public • Published

React Modal Library

A simple modal component for React application.

NPM publication

You can see npm publication here

Installation

You can install react_modal_library with npm command : npm install react_modal_library or with yarn command : yarn add react_modal_library

Use react_modal_library

  1. Import Modal component to your file : import { Modal } from 'react_modal_library'

  2. Insert Modal component at rendering (example) :

import { Modal } from 'react_modal_library';

const Form = () => {

  const [ isOpen, setIsOpen ] = useState(false);
  const openModal = () => setIsOpen(true);
  const closeModal = () => setIsOpen(false);
  
  const handleSubmit = (e) => {
    e.preventDefault();
    openModal();
   };

  return (
    <div className='Form'>
      <form method='post'>
        <div>
          <label htmlFor='firstName'>First Name</label>
          <input aria-required="true" type='text' id='firstName' name='firstName' onChange={(e) => setFirstname(e.target.value)} required value={firstname} />
        </div>
      </form>
      <button type='submit' id='saveButton' onClick={(e) => handleSubmit(e)}>Save</button>
      {isOpen && <Modal text='Employee created' close={closeModal} />}
    </div>
  );
}

export default Form;
  1. Pass props text and close to Modal component.

Props expected

  • text contains text to display in Modal component
  • close contains function that returns false

Demo

image

Readme

Keywords

Package Sidebar

Install

npm i react_modal_library

Weekly Downloads

1

Version

0.8.2

License

none

Unpacked Size

9.12 kB

Total Files

7

Last publish

Collaborators

  • desbasmarion