@antoinea95/modal-component-hrnet

1.0.2 • Public • Published

Modal component HRnet

This is a modal component for React. Developped for a student project and used in P14-hrnet

Prerequisites

My Table of Content

Installation

You can install the modal-component-hrnet package using npm:

npm install @antoinea95/modal-component-hrnet

Usage

Import Modal in your React component:

import { Modal } from '@antoinea95/modal-component-hrnet';

Implement Modal in your React component:

function MyComponent() {
  const [isShow, setIsShow] = useState(false)

  return (
    <div>
        <button onClick={() => setIsShow(true)}>Open Modal</button>
        <Modal
          onClose={() => setIsShow(false)}
          isShow={isShow}
          setIsShow={setIsShow}
          timeOut={3000} //optionnal, if you want modal close automatically
        >
        <p> This is a Modal </p>
        </Modal>
      </div>
  )
}

You can also display Modal without an Opening button, this an exemple with a confirmed Form :

function MyComponent() {
  const [isShow, setIsShow] = useState(false)

  const handleSubmit = (e) => {
    e.preventDefault();
    setIsShow(true);
  }

  return (
    <>
    <form onSubmit={(e) =>{handleSubmit(e)}}>
        <label htmlFor="email">E-mail</label>
        <input type="email" name="email" id="email" />

        <label htmlFor="password">Password</label>
        <input type="password" name="password" id="password" />

        <button type="submit"> Se connecter </button>
    </form>
    <Modal
      onClose={() => setIsShow(false)}
      isShow={isShow}
      setIsShow={setIsShow}
      timeOut={3000} //optionnal, if you want modal close automatically
      >
        <p> User connected </p>
    </Modal>
  )
}

Props

The Modal component props you need:

Prop Type Description Required Default Value
children React.node The content of your modal, it can be anything you want Yes -
onClose () => void Callback function to be called when the modal is closed. Yes -
isShow boolean Boolean indicating whether the modal is open or closed. Yes -
setIsShow () => void Callback function to change isShow value Yes -
timeOut number Number in miliseconds to close Modal automatically No -

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.21latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.21
1.0.11
1.0.01
0.0.90
0.0.80
0.0.70
0.0.61
0.0.50
0.0.00

Package Sidebar

Install

npm i @antoinea95/modal-component-hrnet

Weekly Downloads

4

Version

1.0.2

License

MIT

Unpacked Size

702 kB

Total Files

3

Last publish

Collaborators

  • antoinea95