UNPKG

12.8 kBMarkdownView Raw
1# react-responsive-modal
2
3[![npm version](https://badge.fury.io/js/react-responsive-modal.svg)](https://badge.fury.io/js/react-responsive-modal)
4[![npm](https://img.shields.io/npm/dm/react-responsive-modal.svg)](https://www.npmjs.com/package/react-responsive-modal)
5[![Build Status](https://travis-ci.org/pradel/react-responsive-modal.svg?branch=master)](https://travis-ci.org/pradel/react-responsive-modal)
6[![codecov](https://codecov.io/gh/pradel/react-responsive-modal/branch/master/graph/badge.svg)](https://codecov.io/gh/pradel/react-responsive-modal)
7[![dependencies Status](https://david-dm.org/pradel/react-responsive-modal/status.svg)](https://david-dm.org/pradel/react-responsive-modal)
8
9A simple responsive react modal compatible with React 15, 16 and ready for React 17.
10
11- Centered modals.
12- Scrolling modals.
13- Multiple modals.
14- Easily customizable via props.
15
16## Demo
17
18You can find a demo [here](https://react-responsive-modal.leopradel.com/).
19
20## Examples
21
22https://react-responsive-modal.leopradel.com/#example
23
24## Installation
25
26With npm: `npm install react-responsive-modal --save`
27
28Or with yarn: `yarn add react-responsive-modal`
29
30## Usage
31
32[![Edit react-responsive-modal](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/9jxp669j2o)
33
34```javascript
35import React from 'react';
36import ReactDOM from 'react-dom';
37import Modal from 'react-responsive-modal';
38
39export default class App extends React.Component {
40 state = {
41 open: false,
42 };
43
44 onOpenModal = () => {
45 this.setState({ open: true });
46 };
47
48 onCloseModal = () => {
49 this.setState({ open: false });
50 };
51
52 render() {
53 const { open } = this.state;
54 return (
55 <div>
56 <button onClick={this.onOpenModal}>Open modal</button>
57 <Modal open={open} onClose={this.onCloseModal} center>
58 <h2>Simple centered modal</h2>
59 </Modal>
60 </div>
61 );
62 }
63}
64
65ReactDOM.render(<App />, document.getElementById('app'));
66```
67
68## Props
69
70<!-- --begin-insert-props-- -->
71
72### Modal
73
74| Name | Type | Default | Description |
75| ------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
76| closeOnEsc | `bool` | `true` | Is the modal closable when user press esc key. |
77| closeOnOverlayClick | `bool` | `true` | Is the modal closable when user click on overlay. |
78| onEntered | `func` | `null` | Callback fired when the Modal is open and the animation is finished. |
79| onExited | `func` | `null` | Callback fired when the Modal has exited and the animation is finished. |
80| **onClose\*** | `func` | | Callback fired when the Modal is requested to be closed by a click on the overlay or when user press esc key. |
81| onEscKeyDown | `func` | `null` | Callback fired when the escape key is pressed. |
82| onOverlayClick | `func` | `null` | Callback fired when the overlay is clicked. |
83| **open\*** | `bool` | | Control if the modal is open or not. |
84| classNames | `object` | | An object containing classNames to style the modal, can have properties 'overlay' (classname for overlay div), 'modal' (classname for modal content div), 'closeButton' (classname for the button that contain the close icon), 'closeIcon' (classname for close icon svg). You can customize the transition with 'transitionEnter', 'transitionEnterActive', 'transitionExit', 'transitionExitActive' |
85| styles | `object` | | An object containing the styles objects to style the modal, can have properties 'overlay', 'modal', 'closeButton', 'closeIcon'. |
86| children | `node` | `null` | The content of the modal. |
87| center | `bool` | `false` | Should the dialog be centered. |
88| showCloseIcon | `bool` | `true` | Show the close icon. |
89| closeIconSize | `number` | `28` | Close icon size. |
90| closeIconSvgPath | `node` | `<path d="M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z" />` | A valid svg path to show as icon. |
91| animationDuration | `number` | `500` | Animation duration in milliseconds. |
92| container | `object` | | You can specify a container prop which should be of type `Element`. The portal will be rendered inside that element. The default behavior will create a div node and render it at the at the end of document.body. |
93
94<!-- --end-insert-props-- -->
95
96## License
97
98MIT © [Léo Pradel](https://www.leopradel.com/)