# react-clean-modal

Latest version **0.2.2** (published 2021-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-clean-modal
pnpm add react-clean-modal
yarn add react-clean-modal
bun add react-clean-modal
```

## 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.2.2 |
| Published | 2021-11-29 |
| First published | 2021-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 12 |
| Unpacked size | 64.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Audrey Diez |
| Maintainers | minawa.io |
| Keywords | react, react-component, overlay, modal, dialog, ui, react-portal, portal, aria-modal, accessible, front-end |

## Links

- npm: https://www.npmjs.com/package/react-clean-modal
- Repository: https://github.com/audreydiez/react-clean-modal
- Homepage: https://youthful-edison-51a3c3.netlify.app/
- Issues: https://github.com/audreydiez/react-clean-modal/issues
- npm.io page: https://npm.io/package/react-clean-modal

## Dependencies (12)

- [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) 4.0.3
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.16.3
- [jest-html-reporter](https://npm.io/package/jest-html-reporter.md) ^3.4.1
- [react-test-renderer](https://npm.io/package/react-test-renderer.md) ^17.0.2
- [@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
- [@testing-library/react-hooks](https://npm.io/package/@testing-library/react-hooks.md) ^7.0.2
- [@wojtekmaj/enzyme-adapter-react-17](https://npm.io/package/@wojtekmaj/enzyme-adapter-react-17.md) ^0.6.5

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads
- [react-native-modal-translucent-axton](https://npm.io/package/react-native-modal-translucent-axton.md) — 4 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2021-11-29
- 0.2.1 — 2021-11-29
- 0.2.0 — 2021-11-05
- 0.1.9 — 2021-11-04
- 0.1.8 — 2021-11-04
- 0.1.7 — 2021-11-03
- 0.1.6 — 2021-10-31
- 0.1.5 — 2021-10-31
- 0.1.4 — 2021-10-30
- 0.1.3 — 2021-10-27
- 0.1.2 — 2021-10-26

## README

<h1 align="center">
  <br>
  <a href="https://github.com/audreydiez/react-clean-modal/blob/main/src/assets/logo_modal.svg">
<img src="https://github.com/audreydiez/react-clean-modal/blob/main/src/assets/logo_modal.svg" alt="react-clean-modal" width="200">
</a>
  <br> 
  React-clean-modal
  <br>
</h1>

<h4 align="center">A minimal modal plugin for React and very easy to use.</h4>

<div align="center">  
  <a href="https://img.shields.io/npm/dt/react-clean-modal">
      <img src="https://img.shields.io/npm/dt/react-clean-modal">
  </a>
  <a href="https://img.shields.io/github/license/audreydiez/react-clean-modal">
    <img src="https://img.shields.io/github/license/audreydiez/react-clean-modal">
  </a>
<a href="https://img.shields.io/github/contributors/audreydiez/react-clean-modal">
    <img src="https://img.shields.io/github/contributors/audreydiez/react-clean-modal">
  </a>
</div>

<div align="center">
  <a href="https://img.shields.io/badge/statements-83.33%25-green.svg?style=flat">
      <img src="https://img.shields.io/badge/statements-83.33%25-green.svg?style=flat">
  </a>
  <a href="https://img.shields.io/badge/branches-76%25-yellow.svg?style=flat">
    <img src="https://img.shields.io/badge/branches-76%25-yellow.svg?style=flat">
  </a>
<a href="https://img.shields.io/badge/functions-83.33%25-green.svg?style=flat">
    <img src="https://img.shields.io/badge/functions-83.33%25-green.svg?style=flat">
  </a>
<a href="https://img.shields.io/badge/lines-83.33%25-green.svg?style=flat">
    <img src="https://img.shields.io/badge/lines-83.33%25-green.svg?style=flat">
  </a>
</div>

<p align="center">
<a href="#live-examples">Live examples</a> •
  <a href="#key-features">Key Features</a> •
  <a href="#how-to-use">How To Use</a> •
  <a href="#documentation">Documentation</a> •
  <a href="#credits">Credits</a> •
  <a href="#related">Contributing</a> •
  <a href="#license">License</a> •
  <a href="#contact">Contact</a>
</p>

## Live examples

You can see code examples [here](https://github.com/audreydiez/react-custom-modal/blob/main/src/App.js).
</br>
You can see live demo [here](https://youthful-edison-51a3c3.netlify.app/).

## Key Features

-   Modal Portal: insert your own content inside the modal
-   Custom buttons: Use array with your buttons (event handling available)
-   Custom footer: add a footer with your button and align them
-   Close: with icon on top, on overlay click or/and on mouse scroll
-   Animations: Overlay fade-in and modal show-up
-   Custom props: add aria-label, data-testid, and custom css classes

## How To Use

To use the modal plugin:

```bash
# in your project root terminal
$ npm i react-clean-modal
```

Contributing/Fork : you'll need [Git](https://git-scm.com) and [Node.js](https://nodejs.org/en/download/) (which comes with [npm](http://npmjs.com)) installed on your computer. From your command line:

```bash
# Install dependencies
$ npm install

# Run the app
$ npm run start
```

## Documentation

Import Modal component and the hook useModal.
Props isVisible and hide are required.

```jsx
import React from 'react'
import { Modal, useModal } from 'react-clean-modal'

function App() {
    const { isShowing: showModal, toggle: toggleModal } = useModal()
    return (
        <>
            <button type="button" className="btn" onClick={toggleModal}>
                Open me!
            </button>

            <Modal isVisible={showModal} hide={toggleModal}>
                // Your content
                <h1>Title</h1>
                <div>Content</div>
                <button type="button" className="btn-clean-modal" onClick={toggleModal}>
                    Close me!
                </button>
            </Modal>
        </>
    )
}
```

### Custom footer

You can pass an array with button (custom classes, content and event function) to display a modal footer.

```jsx
import React from 'react'
import { Modal, useModal } from 'react-clean-modal'

function App() {
    const { isShowing: showModal, toggle: toggleModal } = useModal()

    const customEvent = () => {
        alert('Ah')
    }
    const arrayOfBtn = [
        {
            text: 'Close modal',
            className: 'btn-clean-modal'
        },
        {
            text: 'Alert me!',
            className: 'btn-clean-modal',
            eventHandling: customEvent
        }
    ]
    return (
        <>
            <button type="button" className="btn" onClick={toggleModal}>
                Open me!
            </button>

            <ReactCleanModal
                isVisible={showModal}
                hide={toggleModal}
                customFooter={arrayOfBtn}
                customFooterAlign={'left'}>
                // Your content
                <h1>Title</h1>
                <div>Content</div>
            </ReactCleanModal>
        </>
    )
}
```

### Waiting with spinner

You can show a spinner when you waiting for async function. the modal toggle will hide spinner automatically. In your function, launch spinner, get data and launch modal.

```jsx
import React from 'react'
import { Modal, useModal } from 'react-clean-modal'

function App() {
    const {
        isShowing: showModal,
        toggle: toggleModal,
        isShowingSpinner: showSpinner,
        toggleSpinner: toggleSpinner
    } = useModal()

    const launchModalTimer = () => {
        toggleSpinner()

        setTimeout(() => {
            toggleClassicModal()
        }, 3000)
    }

    return (
        <>
            <button type="button" className="btn" onClick={launchModalTimer}>
                Open me!
            </button>

            <ReactCleanModal isVisible={showModal} hide={toggleModal} showSpinner={showSpinner}>
                // Your content
                <h1>Title</h1>
                <div>Content</div>
            </ReactCleanModal>
        </>
    )
}
```

### All props

| Prop                | Type         | Required?    | Default              | Description                                                                           |
| ------------------- | ------------ | ------------ | -------------------- | ------------------------------------------------------------------------------------- |
| isVisible           | boolean      | **required** | false                | Event handler for modal (custom hook).                                                |
| hide                | function     | **required** | Hook to toggle modal | Event handler for modal (custom hook).                                                |
| animations          | boolean      | _optional_   | false                | true: fade-in and show-up animation.                                                  |
| ariaLabelledBy      | string       | _optional_   | -                    | ariaLabelledBy={'aria-label'} set in the modal container, linked with your own title. |
| closeOnOverlayClick | boolean      | _optional_   | false                | true: Modal will close on overlay click.                                              |
| closeOnScroll       | boolean      | _optional_   | false                | true: Modal will close on mouse scroll.                                               |
| closeOnTop          | boolean      | _optional_   | false                | true: Icon on right top displayed for close modal.                                    |
| customClass         | string       | _optional_   | -                    | Add a custom class to all HTML class attributes for override styles.                  |
| customFooter        | Array.Object | _optional_   | -                    | Add your buttons with proper event to the modal footer.                               |
| customFooterAlign   | string       | _optional_   | 'center'             | Align your buttons array ('left', 'center','right').                                  |
| testId              | string       | _optional_   | -                    | Add data-testid attribute to the modal container for tests.                           |
| showSpinner         | boolean      | _optional_   | false                | Update modal display with custom hook. See example above.                             |

## Credits

This software uses the following open source packages:

-   [React](https://fr.reactjs.org/)
-   [Babel/core](https://babeljs.io/)
-   [SASS](https://sass-lang.com/)
-   [ESLint](https://eslint.org/)
-   [Prettier](https://prettier.io/)
-   [Testing-library](https://testing-library.com/)
-   [istanbul-badges-readme](https://www.npmjs.com/package/istanbul-reporter-shield-badge)
-   [jest-html-reporter](https://www.npmjs.com/package/jest-html-reporter)
-   [Enzyme](https://enzymejs.github.io/enzyme/)

## Contribute

### You want to contribute ?

You can read this: [CONTRIBUTING.md](https://github.com/Yagini/LionelCorre-P14-Modal-react-module/blob/main/CONTRIBUTING.md). Contributors wanted :)

### Contact

Audrey Diez - [@Linkedin](https://www.linkedin.com/in/audrey-diez-5862345b/) - audrey.diez@gmail.com

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