# react-page-exit-confirmation

> A confirmation modal that triggers when you route or exit the page.

Latest version **0.0.1** (published 2020-03-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-page-exit-confirmation
pnpm add react-page-exit-confirmation
yarn add react-page-exit-confirmation
bun add react-page-exit-confirmation
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2020-03-14 |
| First published | 2020-03-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 21.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Youngjae Han |
| Maintainers | youngjaehan |
| Keywords | react-page-exit, react-exit, react-page-exit-confirmation |

## Links

- npm: https://www.npmjs.com/package/react-page-exit-confirmation
- Repository: https://github.com/cicada1992/react-page-exit-confirmation
- Homepage: https://github.com/cicada1992/react-page-exit-confirmation#readme
- Issues: https://github.com/cicada1992/react-page-exit-confirmation/issues
- npm.io page: https://npm.io/package/react-page-exit-confirmation

## Dependencies (3)

- [react-modal](https://npm.io/package/react-modal.md) ^3.11.2
- [styled-components](https://npm.io/package/styled-components.md) ^4.2.0
- [autobind-decorator](https://npm.io/package/autobind-decorator.md) ^2.4.0

## Recent versions

- 0.0.1 (latest) — 2020-03-14

## README

# react-page-exit-confirmation
A confirmation modal that triggers when you route or exit the page.

## Getting Started
```
npm install react-page-exit-confirmation --save

import PageExitConfirmation from 'react-page-exit-confirmation';
```

## Peer Dependancies
- react
- react-dom
- react-router-dom

## Demo
https://cicada1992.github.io/react-page-exit-confirmation/

#### Used code in demo
```
const shouldConfirm = true;
const modalContent = (
  <>
    <div>You have unsaved changes that will be lost if you leave.</div>
    <div>Is it okay?</div>
  </>
)

<PageExitConfirmation
  shouldConfirm={shouldConfirm}
  history={history}
  modalHeader="Leave this page?"
  modalContent={modalContent}
  modalStyle={{
    background: "#fff",
    borderRadius: 0
  }}
  leaveButtonStyle={{ background: "#5d95ff", color: "#fff" }}
/>
```

## Props
| Property | Type | Required? | Description | Default Value 
|:---|:---|:---:|:---|:---|
| shouldConfirm | boolean | ✓ | Condition to show confirmation dialog
| history | Pick<RouteComponentProps, "history"> | ✓ | History object to route (react-router-dom)
| modalHeader | React.ReactNode |  | Modal header (text \| element) | Leave this page?
| modalContent | React.ReactNode |  | Modal content (text \| element) | You have unsaved changes that will be lost if you leave.
| modalStyle | React.CSSProperties |  | Custom modal style | Refer DEFAULT_MODAL_STYLE
| leaveButtonStyle | React.CSSProperties |  | Custom leave btn style | Refer DEAFULT_BUTTON_STYLE
| cancelButtonStyle | React.CSSProperties |  | Custom cancel btn style | Refer DEAFULT_BUTTON_STYLE
```
const DEFAULT_MODAL_STYLE = {
  top: "50%",
  left: "50%",
  right: "auto",
  bottom: "auto",
  width: 500,
  padding: "30px 20px",
  transform: "translate(-50%, -50%)",
  boxShadow: "0 4px 14px 0 rgba(0, 0, 0, 0.37)"
};

const DEAFULT_BUTTON_STYLE = {
  width: 90,
  height: 30
};
```

## Simple Example
```
<PageExitConfirmation
  shouldConfirm={shouldConfirm}
  history={history}
/>
```

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