Skip to content

An opinionated toast component for React.

Allow passing a promise without wrapper

skoshx6cfd70c0ec16
diff --git a/package.json b/package.json
index 3b8d2fd..0fa1bbd 100644
--- a/package.json
+++ b/package.json
@@ -26,6 +26,7 @@
"@playwright/test": "^1.30.0",
"@types/node": "^18.11.13",
"@types/react": "^18.0.26",
+ "postcss": "^8.4.21",
"react": "^18.2.0",
"tsup": "^6.4.0",
"turbo": "1.6",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0a9fe26..dae5ba1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -7,6 +7,7 @@ importers:
'@playwright/test': ^1.30.0
'@types/node': ^18.11.13
'@types/react': ^18.0.26
+ postcss: ^8.4.21
react: ^18.2.0
tsup: ^6.4.0
turbo: '1.6'
@@ -15,8 +16,9 @@ importers:
'@playwright/test': 1.30.0
'@types/node': 18.11.18
'@types/react': 18.0.26
+ postcss: 8.4.21
react: 18.2.0
+ tsup: 6.5.0_k22f457wtryv7dv7ltdlwpdpdm
turbo: 1.6.3
typescript: 4.9.4
@@ -1559,7 +1561,6 @@ packages:
resolution: {integrity: sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==}
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
- dev: false
/next-mdx-remote/4.3.0_biqbaboplfbrettd7655fr4n2y:
resolution: {integrity: sha512-fbxkY03pM2Wx5bDNTVKpYD5Hx3QVZGH+6xDtVIxlxXz4HTifP1yI2DrkDvxXbTz0SYGIbluRMIW81IOOa8pigA==}
@@ -1690,7 +1691,6 @@ packages:
/picocolors/1.0.0:
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
- dev: false
/picomatch/2.3.1:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
@@ -1708,7 +1708,7 @@ packages:
hasBin: true
dev: true
- /postcss-load-config/3.1.4:
+ /postcss-load-config/[email protected]:
resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==}
engines: {node: '>= 10'}
peerDependencies:
@@ -1721,6 +1721,7 @@ packages:
optional: true
dependencies:
lilconfig: 2.0.6
+ postcss: 8.4.21
yaml: 1.10.2
dev: true
@@ -1733,6 +1734,15 @@ packages:
source-map-js: 1.0.2
dev: false
+ /postcss/8.4.21:
+ resolution: {integrity: sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==}
+ engines: {node: ^10 || ^12 || >=14}
+ dependencies:
+ nanoid: 3.3.4
+ picocolors: 1.0.0
+ source-map-js: 1.0.2
+ dev: true
+
/prism-react-renderer/[email protected]:
resolution: {integrity: sha512-IJ+MSwBWKG+SM3b2SUfdrhC+gu01QkV2KmRQgREThBfSQRoufqRfxfHUxpG1WcaFjP+kojcFyO9Qqtpgt3qLCg==}
peerDependencies:
@@ -1877,7 +1887,6 @@ packages:
/source-map-js/1.0.2:
resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
engines: {node: '>=0.10.0'}
- dev: false
/source-map/0.7.4:
resolution: {integrity: sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==}
@@ -1994,7 +2003,7 @@ packages:
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
dev: false
+ /tsup/6.5.0_k22f457wtryv7dv7ltdlwpdpdm:
resolution: {integrity: sha512-36u82r7rYqRHFkD15R20Cd4ercPkbYmuvRkz3Q1LCm5BsiFNUgpo36zbjVhCOgvjyxNBWNKHsaD5Rl8SykfzNA==}
engines: {node: '>=14'}
hasBin: true
@@ -2018,7 +2027,8 @@ packages:
execa: 5.1.1
globby: 11.1.0
joycon: 3.1.1
- postcss-load-config: 3.1.4
+ postcss: 8.4.21
+ postcss-load-config: [email protected]
resolve-from: 5.0.0
rollup: 3.10.0
source-map: 0.8.0-beta.0
diff --git a/postcss.config.cjs b/postcss.config.cjs
new file mode 100644
index 0000000..4a9505f
--- /dev/null
+++ b/postcss.config.cjs
@@ -0,0 +1,3 @@
+module.exports = {
+ plugins: [require('autoprefixer')()],
+}
diff --git a/src/index.tsx b/src/index.tsx
index 6c7722e..6b9d92b 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -118,14 +118,22 @@ const Toast = (props: ToastProps) => {
React.useEffect(() => {
if (toast.promise) {
setPromiseStatus('loading');
- toast
- .promise()
- .then(() => {
- setPromiseStatus('success');
- })
- .catch(() => {
- setPromiseStatus('error');
- });
+ if (toast.promise instanceof Promise) {
+ toast.promise.then(() => {
+ setPromiseStatus('success');
+ }).catch(() => {
+ setPromiseStatus('error');
+ })
+ } else if (typeof toast.promise === "function") {
+ toast
+ .promise()
+ .then(() => {
+ setPromiseStatus('success');
+ })
+ .catch(() => {
+ setPromiseStatus('error');
+ });
+ }
}
}, [toast]);
diff --git a/src/types.ts b/src/types.ts
index 16003c3..029737e 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -8,7 +8,7 @@ export type PromiseData = {
error: string | React.ReactNode;
};
-export type PromiseT = () => Promise<any>;
+export type PromiseT = Promise<any> | (() => Promise<any>);
export interface ToastT {
id: number;
diff --git a/website/postcss.config.cjs b/website/postcss.config.cjs
new file mode 100644
index 0000000..3080304
--- /dev/null
+++ b/website/postcss.config.cjs
@@ -0,0 +1,5 @@
+module.exports = {
+ plugins: {
+ autoprefixer: {}
+ }
+};