# react-modal-button

> Modern Modal Usage

Latest version **2.0.6** (published 2018-04-21) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.6 |
| Published | 2018-04-21 |
| First published | 2018-04-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Rasmus Josefsson |
| Maintainers | _rjosefsson, rjosefsson |
| Keywords | react, modal, backdrop, button |

## Links

- npm: https://www.npmjs.com/package/react-modal-button
- Repository: https://github.com/rajjejosefsson/react-modal-button
- Homepage: https://github.com/rajjejosefsson/react-modal-button#readme
- Issues: https://github.com/rajjejosefsson/react-modal-button/issues
- npm.io page: https://npm.io/package/react-modal-button

## Dependencies (1)

- [create-react-library](https://npm.io/package/create-react-library.md) ^2.3.4

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.6 (latest) — 2018-04-21
- 2.0.5 — 2018-04-18
- 2.0.4 — 2018-04-16
- 2.0.3 — 2018-04-16
- 2.0.2 — 2018-04-16
- 2.0.1 — 2018-04-16
- 1.0.2 — 2018-04-15
- 1.0.1 — 2018-04-15
- 1.0.0 — 2018-04-15

## README

<h1 align="center">
  React Modal Button
</h1>

<p align="center">
  <img height="50px"      src="https://camo.githubusercontent.com/801e23cd20de6f0e8838be63c663b081022fa6b4/68747470733a2f2f656d6f6a6970656469612d75732e73332e616d617a6f6e6177732e636f6d2f7468756d62732f3234302f6170706c652f3132392f646f675f31663431352e706e67" />
</p>
<p align="center" style="font-size: 1.2rem;">Button that takes a modal as prop</p>

<p align="center">
  <img src="https://img.shields.io/badge/🦄-Just Works-cc00cc.svg"/> <img src="https://img.shields.io/badge/💎-Modern-44aadd.svg"/> <img src="https://img.shields.io/badge/🦋-Extremely Lightweight-7799cc.svg"/> <img src="https://img.shields.io/badge/🔥-Blazing%20Fast-red.svg"/>
</p>
<hr />

## Installation

`npm i --save react-modal-button`

## Example

[Demo here - Codesandbox.io](https://codesandbox.io/s/q86k5wxl09)

## Usage

```javascript
import React from 'react';
import { ModalButton } from 'react-modal-button';

const App = () => (
  <div>
    <h1>React Modal Button!</h1>

    <ModalButton
      modal={({ closeModal }) => (
        <div>
          <p>My Modal</p>
          <button onClick={closeModal}>Close</button>
        </div>
      )}
    >
      Button Text Here 🐕
    </ModalButton>
  </div>
);
```

## Props for content

| prop  | render prop |
| ----- | :---------: |
| modal | closeModal  |

## Props on Button

| props           | defualt |
| --------------- | :-----: |
| buttonStyle     |         |
| buttonClassName |         |

## Props for Modal

| props               | Default |
| ------------------- | :-----: |
| isBackdrop          |  false  |
| showCloseButton     |  true   |
| closeOnBackdrop     |  true   |
| closeOnEsc          |  true   |
| height              | '300px' |
| width               | '500px' |
| animation           | 'fade'  |
| animationDurationMS |   300   |
| className           |         |
| windowClassName     |         |
| windowStyles        |         |
| backdropClassName   |         |
| backdropStyles      |         |

## Custom Animation

`modal-[your-animation-prop]-on-[enter/leave]`

## Control the modal with state

```javascript
import { Modal } from 'react-modal-button';

class App extends Component {
  state = {
    isModalOpen: false,
  };

  openModal = () => {
    this.setState({ isModalOpen: true });
  };

  closeModal = () => {
    this.setState({ isModalOpen: false });
  };

  render() {
    return (
      <div>
        <button onClick={this.openModal}>Open Modal</button>

        <Modal isOpen={this.state.isModalOpen} onClose={this.closeModal}>
          <div>Content</div>
          <button onClick={this.closeModal}>Close Modal</button>
        </Modal>
      </div>
    );
  }
}
```

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