1.0.2 • Published 1 year ago

@antoinea95/modal-component-hrnet v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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:

PropTypeDescriptionRequiredDefault Value
childrenReact.nodeThe content of your modal, it can be anything you wantYes-
onClose() => voidCallback function to be called when the modal is closed.Yes-
isShowbooleanBoolean indicating whether the modal is open or closed.Yes-
setIsShow() => voidCallback function to change isShow valueYes-
timeOutnumberNumber in miliseconds to close Modal automaticallyNo-
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.0

1 year ago