# portal-modal

> ## Install

Latest version **1.0.3** (published 2017-12-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install portal-modal
pnpm add portal-modal
yarn add portal-modal
bun add portal-modal
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2017-12-06 |
| First published | 2017-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Malexsan |
| Maintainers | malexsan1 |

## Links

- npm: https://www.npmjs.com/package/portal-modal
- npm.io page: https://npm.io/package/portal-modal

## Dependencies (8)

- [react](https://npm.io/package/react.md) ^16.2.0
- [babel-cli](https://npm.io/package/babel-cli.md) ^6.26.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.2.0
- [babel-core](https://npm.io/package/babel-core.md) ^6.26.0
- [react-redux](https://npm.io/package/react-redux.md) ^5.0.6
- [babel-preset-react](https://npm.io/package/babel-preset-react.md) ^6.24.1
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.24.1
- [babel-preset-stage-2](https://npm.io/package/babel-preset-stage-2.md) ^6.24.1

## Recent versions

- 1.0.3 (latest) — 2017-12-06
- 1.0.2 — 2017-12-06
- 1.0.1 — 2017-12-06
- 1.0.0 — 2017-12-06

## README

# Modal implementation using React Fiber's Portal

## Install

```
npm install --save portal-modal
```

## Usage

This package exports a reducer and a React higher order component.

---

```js
// inside main reducer
import { combineReducers } from 'redux'
import { modalReducer } from 'portal-modal'

export default combineReducers({
  modal: modalReducer
})
```

---

The portal HoC adds a `showModal` function to the wrapped component. This function can receive an object with props for the underlying modal component.

The `withModal` HoC receives an object as a second parameter in which we can specify what custom React component to be rendered as a modal. This component receives all the props passed through the `showModal` function.

```js
// inside the component where we want to use the modal
import React from 'react'
import { withModal } from 'portal-modal'

const ModalComponent = ({ hideModal, dismissable, onConfirm }) => {
  return (
    <div className="modal" onClick={dismissable ? hideModal : null}>
      This is our custom modal component.
      <div>
        <button onClick={onConfirm}>Yes</button>
        <button onClick={hideModal}>Hide modal</button>
      </div>
    </div>
  )
}

class ComponentWithModal extends React.Component {
  render() {
    const { showModal } = this.props
    return (
      <div>
        <button
          onClick={() =>
            showModal({
              onConfirm: () => alert('Confirm button was pressed!'),
              dismissable: true
            })
          }
        >
          Show modal
        </button>
      </div>
    )
  }
}

export default withModal(ComponentWithModal, {
  modalComponent: ModalComponent
})
```

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