Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/littlee/react-x-modal

manage all modals in one place
https://github.com/littlee/react-x-modal

Last synced: 5 days ago
JSON representation

manage all modals in one place

Awesome Lists containing this project

README

        

# React X Modal

manage all modals in one place

## motivation

the typical way to render modal in react

- import modal component
- declare modal in JSX
- introduce a new state to control the visibility of the modal

this would become tedious when trying to manage multiple modals
react-x-modal let you open & close modals with a single method call
and pass other props to modal all at once

```js
// open
modal.open('myModal', { a: 'b' });
// close
modal.close('myModal');
```

## Install

```bash
npm i -S react-x-modal
```

## Usage

modal.js

```js
import xModal from 'react-x-modal';

const CommonModalWrap = props => {
return (


{props.children}
X

);
};

const ModalA = props => {
return

this is modal a
;
};

const ModalBWrap = props => {
return

{props.children}
;
};

const ModalB = props => {
return (


this is modal b

{/* render props passed when open */}
{props.pass}
close modal b

);
};

const modal = xModal({
wrap: CommonModalWrap,
mapping: {
modalA: ModalA,
modalB: {
wrap: ModalBWrap,
component: ModalB
}
}
});

export default modal;
```

App.js

```js
import React from 'react';
import modal from './modal';

const App = props => {
return (


{
modal.open('modalA');
}}
>
open modal a

{
modal.open('modalB', {
any: 'props',
can: 'pass',
from: 'here'
});
}}
>
open modal b


);
};
```