react-confirm 0.3.0-7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,29 +32,27 @@ react-confirm library offers several benefits:
32
32
 
33
33
  ### Create your dialog component and Apply `confirmable` HOC to your component.
34
34
 
35
- ```js
36
- import React from 'react';
37
- import PropTypes from 'prop-types';
38
- import { confirmable } from 'react-confirm';
39
- import Dialog from 'any-dialog-library'; // your choice.
35
+ ```ts
36
+ import * as React from 'react';
37
+
38
+ import Modal from 'react-bootstrap/Modal'
39
+ import Button from 'react-bootstrap/Button'
40
+
41
+ import { confirmable, ConfirmDialog } from 'react-confirm';
40
42
 
41
- const YourDialog = ({show, proceed, confirmation, options}) => (
43
+ export interface Props {
44
+ confirmation?: string;
45
+ };
46
+
47
+ const Confirmation: ConfirmDialog<Props, boolean> = ({show, proceed, confirmation}) => (
42
48
  <Dialog onHide={() => proceed(false)} show={show}>
43
49
  {confirmation}
44
50
  <button onClick={() => proceed(false)}>CANCEL</button>
45
51
  <button onClick={() => proceed(true)}>OK</button>
46
52
  </Dialog>
47
- )
48
-
49
- YourDialog.propTypes = {
50
- show: PropTypes.bool, // from confirmable. indicates if the dialog is shown or not.
51
- proceed: PropTypes.func, // from confirmable. call to close the dialog with promise resolved.
52
- confirmation: PropTypes.string, // arguments of your confirm function
53
- options: PropTypes.object // arguments of your confirm function
54
- }
53
+ );
55
54
 
56
- // confirmable HOC pass props `show`, `dismiss`, `cancel` and `proceed` to your component.
57
- export default confirmable(YourDialog);
55
+ export default confirmable(Confirmation);
58
56
  ```
59
57
 
60
58
  ### Create a function using `createConfirmation`
@@ -64,11 +62,6 @@ import YourDialog from './YourDialog';
64
62
 
65
63
  // create confirm function
66
64
  export const confirm = createConfirmation(YourDialog);
67
-
68
- // This is optional. But wrapping function makes it easy to use.
69
- export function confirmWrapper(confirmation, options = {}) {
70
- return confirm({ confirmation, options });
71
- }
72
65
  ```
73
66
 
74
67
  ### Call it!
@@ -87,14 +80,6 @@ const handleOnClick = async () => {
87
80
  }
88
81
  }
89
82
 
90
- const handleOnClick2 = async () => {
91
- if (await confirmWrapper('Are your sure?')) {
92
- console.log('yes');
93
- } else {
94
- console.log('no');
95
- }
96
- }
97
-
98
83
  ```
99
84
 
100
85
  You can check more complex example in [codesandbox](https://codesandbox.io/s/react-confirm-with-react-bootstrap-kjju1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-confirm",
3
- "version": "0.3.0-7",
3
+ "version": "0.3.0",
4
4
  "description": "Small library which makes your Dialog component callable",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  "author": "",
31
31
  "license": "MIT",
32
32
  "peerDependencies": {
33
- "react": "18.x",
34
- "react-dom": "18.x"
33
+ "react": ">=18.x",
34
+ "react-dom": ">=18.x"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@babel/cli": "^7.17.6",
@@ -44,8 +44,8 @@
44
44
  "babel-jest": "^29.5.0",
45
45
  "jest": "^29.5.0",
46
46
  "jest-environment-jsdom": "^29.5.0",
47
- "react": "^18.2.0",
48
- "react-dom": "^18.2.0",
47
+ "react": ">=18.2.0",
48
+ "react-dom": ">=18.2.0",
49
49
  "regenerator-runtime": "^0.13.11",
50
50
  "rimraf": "^3.0.2"
51
51
  },
@@ -9,9 +9,13 @@ type ConfirmableProps<P, R> = {
9
9
  type ConfirmableDialog<P, R> = React.ComponentType<ConfirmableProps<P, R>>;
10
10
 
11
11
  export type ConfirmDialogProps<P, R> = {
12
+ /** Dismiss dialog without resolving the promise. */
12
13
  dismiss: () => void;
14
+ /** Resolve the promise with the given value. */
13
15
  proceed: (value: R) => void;
16
+ /** Reject the promise with the given value. */
14
17
  cancel: (value?: any) => void;
18
+ /** Indicates if the dialog should be shown aka. someone is waiting for a promise. */
15
19
  show: boolean;
16
20
  } & P;
17
21