# react-modal_module

> Modal component for react

Latest version **0.1.4** (published 2022-02-13) · 0 weekly downloads

## Install

```sh
npm install react-modal_module
pnpm add react-modal_module
yarn add react-modal_module
bun add react-modal_module
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2022-02-13 |
| First published | 2022-02-13 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 162.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | myriam-g |

## Links

- npm: https://www.npmjs.com/package/react-modal_module
- Repository: https://github.com/NymeriaLucky/MyriamG_P14_react-modal_module_21122021
- Homepage: https://github.com/NymeriaLucky/MyriamG_P14_react-modal_module_21122021#readme
- Issues: https://github.com/NymeriaLucky/MyriamG_P14_react-modal_module_21122021/issues
- npm.io page: https://npm.io/package/react-modal_module

## Dependencies (9)

- [react](https://npm.io/package/react.md) ^17.0.2
- [react-dom](https://npm.io/package/react-dom.md) ^17.0.2
- [web-vitals](https://npm.io/package/web-vitals.md) ^1.1.2
- [react-scripts](https://npm.io/package/react-scripts.md) ^5.0.0
- [styled-components](https://npm.io/package/styled-components.md) ^5.3.1
- [react-modal_module](https://npm.io/package/react-modal_module.md) ^0.1.3
- [@testing-library/react](https://npm.io/package/@testing-library/react.md) ^11.2.7
- [@testing-library/jest-dom](https://npm.io/package/@testing-library/jest-dom.md) ^5.14.1
- [@testing-library/user-event](https://npm.io/package/@testing-library/user-event.md) ^12.8.3

## Recent versions

- 0.1.4 (latest) — 2022-02-13
- 0.1.3 — 2022-02-13
- 0.1.2 — 2022-02-13
- 0.1.1 — 2022-02-13
- 0.1.0 — 2022-02-13

## README

# react-modal_module for React

react-modal_module is a complete modal for the react project for the web.

## Installation

```

    npm i react-modal_module

```

## Usage

Import Modal component and the hook useModal from "react-modal_module" where you want to use this.

```jsx
import React from "react";
import Modal, { useModal } from "react-modal_module";

function App() {
  const [showModal, setShowModal, showSpinner, setShowSpinner] = useModal();
  return (
    <Modal showModal={showModal} setShowModal={setShowModal}>
      <p>I am a modal</p>
    </Modal>
  );
}
```

![Default modal](./src/lib/assets/default-modal.png)

In your modal Modal component you can personalize your content to be able to do that we pass the content through a spread operator in the props and we use the props like a children

```jsx
function Modal({ ...props }) {
  return <div>{props.children}</div>;
}
```

```jsx
import React from "react";
import Modal, { useModal } from "react-modal_module";

function App() {
  const [showModal, setShowModal, showSpinner, setShowSpinner] = useModal();
  return (
    <Modal showModal={showModal} setShowModal={setShowModal}>
      <form className="form">
        <label htmlFor="username" />
        <input type="text" id="username" className="form__input" />
        <label htmlFor="lastName" />
        <input type="text" id="lastname" className="form__input" />
        <button type="submit" className="form__button">
          Submit
        </button>
      </form>
    </Modal>
  );
}
```

![Custom Modal contain](./src/lib/assets/modal-custom-contain.png)

Modal is basically responsive, scroll bar is appear if the text is very long

![modal responsive](./src/lib/assets/modal-responsive.png)

## Modal Css

Modal have a basic css page if you want to use

```jsx
import "react-modal_module/dist/components/Modal.css";
```

or if you want personalize it you can make your own css page

```jsx
import "react-modal_module/dist/components/Modal.css"
import "../example/custom.css
```

You can find all class using on the default css here

- [Modal.css](https://github.com/NymeriaLucky/MyriamG_P14_react-modal_module_21122021/blob/main/src/lib/components/Modal.css)

## Props

All of native react-modal_module props can be passed to the component.

### _`Defaults Props`_

showModal and setShowModal is using for make a modal appear

```jsx
function App() {
  const [showModal, setShowModal, showSpinner, setShowSpinner] = useModal();
  return (
    <div>
      <button onClick={setShowModal}>Open Modal</button>
      <Modal
        showModal={showModal}
        setShowModal={setShowModal}
        showSpinner={showSpinner}
        setShowSpinner={setShowSpinner}
      >
        <p>I am a modal</p>
      </Modal>
    </div>
}
```

showSpinner and SetShowSpinner is using for make a spinner appear when they have an async function

```jsx
function App() {
  const [showModal, setShowModal, showSpinner, setShowSpinner] = useModal();

  const waitFor = (ms) => new Promise((r) => setTimeout(r, ms));
  const handleClick = async (event) => {
    setShowSpinner();
    await waitFor(2000);
    setShowModal();
  };

  return (
    <div>
      <button onClick={handleClick}>Open Modal</button>
      <Modal
        showModal={showModal}
        setShowModal={setShowModal}
        showSpinner={showSpinner}
        setShowSpinner={setShowSpinner}
      >
        <p>I am a modal</p>
      </Modal>
    </div>
  );
}
```

## `Optionnal props`

### _`unLockClose?: boolean`_

If unLockClose is true you can't close the modal with click and escape button

```jsx
<Modal
  showModal={showModal}
  setShowModal={setShowModal}
  showSpinner={showSpinner}
  setShowSpinner={setShowSpinner}
  unLockClose={true}
>
  <p className="text__color">Content</p>
</Modal>
```

### _`showClose?: boolean`_

For hiding the close button.

```jsx
<Modal showModal={showModal} setShowModal={setShowModal} showClose={false}>
  <p className="text__color">Content</p>
</Modal>
```

![show close](./src/lib/assets/showclose.png)

### _`showFade?: Boolean`_

You can add a fade effect, the fade effect prevents visibility of the spinner

To customize your fade effect you must change the css content properties in your css custom file

```css
//default className

.modal__fade-in 
.modal__fade-out
@keyframes: fadeInOpacity
@keyframes: fadeOutOpacity
```
```jsx
<Modal showModal={showModal} setShowModal={setShowModal} showFade={true}>
  <p>Content</p>
</Modal>
```

### _`icon?: string`_

You can custom the close icon. </br>
By default the modal have four type of icon: "cross", "exclamation", "heart", "star".</br> 
But if you want your one you just have to change css property on your custom css file. </br> (default className: modal__close-btn)

```css
//default className

.modal__close-btn
```

```jsx
<Modal showModal={showModal} setShowModal={setShowModal} icon="cross">
  <p>Content</p>
</Modal>
```
![cross](./src/lib/assets/cross.png) ![exclamation](./src/lib/assets/exclamation.png)![cross](./src/lib/assets/heart.png) ![star](./src/lib/assets/star.png)

## _`default state of the props and default state in the hook useModal`_

```jsx
  icon = "cross"
  unLockClose = true,
  showClose = true,
  showFade = false,
  ...props
```

```jsx
const [isShowingModal, setIsShowingModal] = useState(false);
const [isShowingSpinner, setIsShowingSpinner] = useState(false);
```

## Contribute

### You want to contribute ?

Go there [CONTRIBUTING.md](https://github.com/NymeriaLucky/MyriamG_P14_react-modal_module_21122021/blob/main/CONTRIBUTING.md)

## License

MIT

---
_Source: https://npm.io/package/react-modal_module · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
