# react-promise-confirmation-dialog

> Simple promise-based confirmation dialogs

Latest version **1.1.3** (published 2023-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-promise-confirmation-dialog
pnpm add react-promise-confirmation-dialog
yarn add react-promise-confirmation-dialog
bun add react-promise-confirmation-dialog
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2023-02-27 |
| First published | 2023-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 64.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gentrit Halili |
| Maintainers | gentrithalili |
| Keywords | react, typescript, confirmation, modal, promise, alert |

## Links

- npm: https://www.npmjs.com/package/react-promise-confirmation-dialog
- Repository: https://github.com/gentrithalili1/react-promise-confirmation-dialog
- npm.io page: https://npm.io/package/react-promise-confirmation-dialog

## 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

- 1.1.3 (latest) — 2023-02-27
- 1.1.2 — 2023-02-27
- 1.1.1 — 2023-02-24
- 1.1.0 — 2023-02-21
- 1.0.7 — 2023-02-21
- 1.0.6 — 2023-02-21
- 1.0.5 — 2023-02-21
- 1.0.4 — 2023-02-21
- 1.0.3 — 2023-02-21
- 1.0.2 — 2023-02-20
- 1.0.1 — 2023-02-20
- 1.0.0 — 2023-02-20

## README

<h3 align="center">Welcome to <code>react-promise-confirmation-dialog</code> 👋</h3>
<p>
  <a href="https://www.npmjs.com/package/react-promise-confirmation-dialog" target="_blank">
    <img alt="Version" src="https://img.shields.io/npm/v/react-promise-confirmation-dialog">
  </a>
  <a href="#" target="_blank">
    <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
  </a>
</p>

## Intro

React Promise Confirmation Dialog is a simple and easy-to-use package that allows you to create dynamic and customizable confirmation dialogs. You can easily handle user confirmation and rejection responses using promises.

This package is customizable, allowing you to easily tailor the look and feel of your dialogs to match the style of your application.

### ✨ [Live Demo](https://gentrithalili1.github.io/react-promise-confirmation-dialog/)
##

## Install

Install `react-promise-confirmation-dialog` via `yarn` or `npm`

```sh
yarn add react-promise-confirmation-dialog
```

```sh
npm i react-promise-confirmation-dialog
```

## Usage

```js
import { PromiseConfirmationContextProvider } from 'react-promise-confirmation-dialog'
```

```jsx
function Index() {
  return (
    <PromiseConfirmationContextProvider>
      <App />
    </PromiseConfirmationContextProvider>
  );
}
```

```jsx
function App() {
  const handleConfirmClick = async () => {
    try {
      await confirmation.confirm()
      // Your code after confirmation is resolved ...
    } catch (rejectReason) {
      // Your code after confirmation is declined ...
    }
  };
  
  return (
    <div>
      <button onClick={handleConfirmClick}>Confirm</button>
    </div>
  );
}
```


## Props and Configurations
You can provide default configuration to <code>PromiseConfirmationContextProvider</code>

```jsx
function Index() {
  return (
    <PromiseConfirmationContextProvider config={{
        portalElementId: '',
        text: '',
        confirmButtonLabel: '',
        cancelButtonLabel: ''
    }}>
      <App />
    </PromiseConfirmationContextProvider>
  );
}
```
| name              | type      | default       | description                                     |
|-------------------| --------- |---------------|-------------------------------------------------|
| `portalElementId` | `string`  | undefined     | Custom element to render the confirmation modal |
| `text`            | `string`  | Are you sure? | Modal title.                                    |
| `confirmButtonLabel` | `string` | `Confirm`     | Confirm button text                             |
| `cancelButtonLabel`| `string`  | Cancel        | Decline button text                             |  |

---

You can also provide custom params everytime you open a confirmation dialog 

```jsx
function App() {
    const handleConfirmClick = async () => {
        try {
            await confirmation.confirm({
                text: '',
                confirmButtonLabel: '',
                cancelButtonLabel: '',
                customData: '',
                customComponent: ''
            })
            // Your code after confirmation is resolved ...
        } catch (rejectReason) {
            // Your code after confirmation is declined ...
        }
    };

    return (
        <div>
            <button onClick={handleConfirmClick}>Confirm</button>
        </div>
    );
}
```

| name                 | type   | default     | description                            |
|----------------------|--------|-------------|----------------------------------------|
| `text`               | `string` | Are you sure? | Modal title                            |
| `confirmButtonLabel` | `string` | Confirm     | Confirm button text                    |
| `cancelButtonLabel`  | `string` | Cancel      | Decline button text                    |  |
| `customData`         | `any`  | undefined   | Custom data when using custom components |  |
| `customComponent`    | `(params: Omit<PromiseConfirmationData, 'customComponent'>) => ReactNode`    | undefined   | Custom component                       |  |

---

## Todos

- [ ] Default custom component support


## Author
- Github: [@gentrithalili1](https://github.com/gentrithalili1)

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