0.11.0 • Published 2 years ago

library-modal v0.11.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

library-modal

a modal component for React application

library-modal on NPM

You can see details of modal on NPM : here

Install library-modal

On your terminal : npm install library-modal

Use library-modal

  • You must import package : import { Modal } from 'library-modal'
  • How insert modal component at rendering (is an example) :
import { Modal } from 'library-modal'

const Form = () => {

  const [firstname, setFirstname] = useState("")
  const [show, setShow] = useState(false)
  const [created, setCreated] = useState(false)

  const submitCreateEmployee = (e) => {
    if (!firstname) {
      setCreated(false)
      setShow(true)
    } else {
      setCreated(true)
      setShow(true)
    }
  };
  
  const hide = () => {
    setShow(false)
  };
  
  return (
    <div className='Form'>
      <form action="" className='formulaire' name='form'>
        <label htmlFor="firstName">First Name</label>
        <input onChange={(e) => setFirstname(e.target.value)} type="text" id="firstName" required />
      </form>
      <button onClick={submitCreateEmployee} className='button-save'>Save</button>
      {show && !created && <Modal contentModal="You must complete all the fields!" hide={hide} />}
      {show && created && <Modal contentModal="Employee Created!" hide={hide} />}
    </div>
  )
};

export default Form;

You have to pass props contentModal and hide to component

Props

  • contentModal : text to display on modal
  • hide : function called onClick update setShow on false
0.10.0

2 years ago

0.11.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago