@tamagui/toast 1.7.10 → 1.8.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/dist/cjs/Toast.js +95 -543
- package/dist/cjs/Toast.js.map +3 -3
- package/dist/cjs/ToastAnnounce.js +93 -0
- package/dist/cjs/ToastAnnounce.js.map +7 -0
- package/dist/cjs/ToastImpl.js +354 -0
- package/dist/cjs/ToastImpl.js.map +7 -0
- package/dist/cjs/ToastProvider.js +109 -0
- package/dist/cjs/ToastProvider.js.map +7 -0
- package/dist/cjs/ToastViewport.js +307 -0
- package/dist/cjs/ToastViewport.js.map +7 -0
- package/dist/cjs/constants.js +29 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/createNativeToast.js +49 -0
- package/dist/cjs/createNativeToast.js.map +7 -0
- package/dist/cjs/createNativeToast.native.js +37 -0
- package/dist/cjs/createNativeToast.native.js.map +7 -0
- package/dist/cjs/createToast.js +88 -0
- package/dist/cjs/createToast.js.map +7 -0
- package/dist/cjs/types.js +17 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/esm/Toast.js +101 -531
- package/dist/esm/Toast.js.map +3 -3
- package/dist/esm/Toast.mjs +101 -531
- package/dist/esm/Toast.mjs.map +3 -3
- package/dist/esm/ToastAnnounce.js +64 -0
- package/dist/esm/ToastAnnounce.js.map +7 -0
- package/dist/esm/ToastAnnounce.mjs +64 -0
- package/dist/esm/ToastAnnounce.mjs.map +7 -0
- package/dist/esm/ToastImpl.js +330 -0
- package/dist/esm/ToastImpl.js.map +7 -0
- package/dist/esm/ToastImpl.mjs +330 -0
- package/dist/esm/ToastImpl.mjs.map +7 -0
- package/dist/esm/ToastProvider.js +70 -0
- package/dist/esm/ToastProvider.js.map +7 -0
- package/dist/esm/ToastProvider.mjs +70 -0
- package/dist/esm/ToastProvider.mjs.map +7 -0
- package/dist/esm/ToastViewport.js +274 -0
- package/dist/esm/ToastViewport.js.map +7 -0
- package/dist/esm/ToastViewport.mjs +274 -0
- package/dist/esm/ToastViewport.mjs.map +7 -0
- package/dist/esm/constants.js +5 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/constants.mjs +5 -0
- package/dist/esm/constants.mjs.map +7 -0
- package/dist/esm/createNativeToast.js +25 -0
- package/dist/esm/createNativeToast.js.map +7 -0
- package/dist/esm/createNativeToast.mjs +25 -0
- package/dist/esm/createNativeToast.mjs.map +7 -0
- package/dist/esm/createNativeToast.native.js +13 -0
- package/dist/esm/createNativeToast.native.js.map +7 -0
- package/dist/esm/createNativeToast.native.mjs +13 -0
- package/dist/esm/createNativeToast.native.mjs.map +7 -0
- package/dist/esm/createToast.js +54 -0
- package/dist/esm/createToast.js.map +7 -0
- package/dist/esm/createToast.mjs +54 -0
- package/dist/esm/createToast.mjs.map +7 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/types.mjs +1 -0
- package/dist/esm/types.mjs.map +7 -0
- package/dist/jsx/Toast.js +97 -509
- package/dist/jsx/Toast.js.map +3 -3
- package/dist/jsx/Toast.mjs +97 -509
- package/dist/jsx/Toast.mjs.map +3 -3
- package/dist/jsx/ToastAnnounce.js +60 -0
- package/dist/jsx/ToastAnnounce.js.map +7 -0
- package/dist/jsx/ToastAnnounce.mjs +60 -0
- package/dist/jsx/ToastAnnounce.mjs.map +7 -0
- package/dist/jsx/ToastImpl.js +309 -0
- package/dist/jsx/ToastImpl.js.map +7 -0
- package/dist/jsx/ToastImpl.mjs +309 -0
- package/dist/jsx/ToastImpl.mjs.map +7 -0
- package/dist/jsx/ToastProvider.js +65 -0
- package/dist/jsx/ToastProvider.js.map +7 -0
- package/dist/jsx/ToastProvider.mjs +65 -0
- package/dist/jsx/ToastProvider.mjs.map +7 -0
- package/dist/jsx/ToastViewport.js +254 -0
- package/dist/jsx/ToastViewport.js.map +7 -0
- package/dist/jsx/ToastViewport.mjs +254 -0
- package/dist/jsx/ToastViewport.mjs.map +7 -0
- package/dist/jsx/constants.js +5 -0
- package/dist/jsx/constants.js.map +7 -0
- package/dist/jsx/constants.mjs +5 -0
- package/dist/jsx/constants.mjs.map +7 -0
- package/dist/jsx/createNativeToast.js +25 -0
- package/dist/jsx/createNativeToast.js.map +7 -0
- package/dist/jsx/createNativeToast.mjs +25 -0
- package/dist/jsx/createNativeToast.mjs.map +7 -0
- package/dist/jsx/createNativeToast.native.js +13 -0
- package/dist/jsx/createNativeToast.native.js.map +7 -0
- package/dist/jsx/createNativeToast.native.mjs +13 -0
- package/dist/jsx/createNativeToast.native.mjs.map +7 -0
- package/dist/jsx/createToast.js +49 -0
- package/dist/jsx/createToast.js.map +7 -0
- package/dist/jsx/createToast.mjs +49 -0
- package/dist/jsx/createToast.mjs.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/dist/jsx/types.mjs +1 -0
- package/dist/jsx/types.mjs.map +7 -0
- package/package.json +14 -13
- package/src/Toast.tsx +139 -908
- package/src/ToastAnnounce.tsx +97 -0
- package/src/ToastImpl.tsx +439 -0
- package/src/ToastProvider.tsx +134 -0
- package/src/ToastViewport.tsx +354 -0
- package/src/constants.ts +1 -0
- package/src/createNativeToast.native.tsx +16 -0
- package/src/createNativeToast.tsx +25 -0
- package/src/createToast.tsx +93 -0
- package/src/types.ts +21 -0
- package/types/Toast.d.ts +429 -106
- package/types/Toast.d.ts.map +1 -1
- package/types/ToastAnnounce.d.ts +35 -0
- package/types/ToastAnnounce.d.ts.map +1 -0
- package/types/ToastImpl.d.ts +267 -0
- package/types/ToastImpl.d.ts.map +1 -0
- package/types/ToastProvider.d.ts +80 -0
- package/types/ToastProvider.d.ts.map +1 -0
- package/types/ToastViewport.d.ts +115 -0
- package/types/ToastViewport.d.ts.map +1 -0
- package/types/constants.d.ts +2 -0
- package/types/constants.d.ts.map +1 -0
- package/types/createNativeToast.d.ts +3 -0
- package/types/createNativeToast.d.ts.map +1 -0
- package/types/createNativeToast.native.d.ts +3 -0
- package/types/createNativeToast.native.d.ts.map +1 -0
- package/types/createToast.d.ts +42 -0
- package/types/createToast.d.ts.map +1 -0
- package/types/types.d.ts +17 -0
- package/types/types.d.ts.map +1 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const createNativeToast = (title, { message }) => {
|
|
2
|
+
if (!("Notification" in window)) {
|
|
3
|
+
throw Error("This browser does not support desktop notification");
|
|
4
|
+
}
|
|
5
|
+
if (Notification.permission === "denied")
|
|
6
|
+
return {};
|
|
7
|
+
const showNotification = () => {
|
|
8
|
+
new Notification(title, {
|
|
9
|
+
body: message
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
if (Notification.permission === "granted") {
|
|
13
|
+
showNotification();
|
|
14
|
+
} else {
|
|
15
|
+
Notification.requestPermission().then((permission) => {
|
|
16
|
+
if (permission === "granted") {
|
|
17
|
+
showNotification();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
createNativeToast
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=createNativeToast.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createNativeToast.tsx"],
|
|
4
|
+
"sourcesContent": ["import { CreateNativeToastsOptionsFn } from './types'\n\nexport const createNativeToast: CreateNativeToastsOptionsFn = (title, { message }) => {\n if (!('Notification' in window)) {\n throw Error('This browser does not support desktop notification')\n }\n\n if (Notification.permission === 'denied') return {}\n\n const showNotification = () => {\n new Notification(title, {\n body: message,\n })\n }\n\n if (Notification.permission === 'granted') {\n showNotification()\n } else {\n Notification.requestPermission().then((permission) => {\n if (permission === 'granted') {\n showNotification()\n }\n })\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAiD,CAAC,OAAO,EAAE,QAAQ,MAAM;AACpF,MAAI,EAAE,kBAAkB,SAAS;AAC/B,UAAM,MAAM,oDAAoD;AAAA,EAClE;AAEA,MAAI,aAAa,eAAe;AAAU,WAAO,CAAC;AAElD,QAAM,mBAAmB,MAAM;AAC7B,QAAI,aAAa,OAAO;AAAA,MACtB,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AAEA,MAAI,aAAa,eAAe,WAAW;AACzC,qBAAiB;AAAA,EACnB,OAAO;AACL,iBAAa,kBAAkB,EAAE,KAAK,CAAC,eAAe;AACpD,UAAI,eAAe,WAAW;AAC5B,yBAAiB;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const createNativeToast = (title, { message }) => {
|
|
2
|
+
if (!("Notification" in window)) {
|
|
3
|
+
throw Error("This browser does not support desktop notification");
|
|
4
|
+
}
|
|
5
|
+
if (Notification.permission === "denied")
|
|
6
|
+
return {};
|
|
7
|
+
const showNotification = () => {
|
|
8
|
+
new Notification(title, {
|
|
9
|
+
body: message
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
if (Notification.permission === "granted") {
|
|
13
|
+
showNotification();
|
|
14
|
+
} else {
|
|
15
|
+
Notification.requestPermission().then((permission) => {
|
|
16
|
+
if (permission === "granted") {
|
|
17
|
+
showNotification();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
createNativeToast
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=createNativeToast.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createNativeToast.tsx"],
|
|
4
|
+
"sourcesContent": ["import { CreateNativeToastsOptionsFn } from './types'\n\nexport const createNativeToast: CreateNativeToastsOptionsFn = (title, { message }) => {\n if (!('Notification' in window)) {\n throw Error('This browser does not support desktop notification')\n }\n\n if (Notification.permission === 'denied') return {}\n\n const showNotification = () => {\n new Notification(title, {\n body: message,\n })\n }\n\n if (Notification.permission === 'granted') {\n showNotification()\n } else {\n Notification.requestPermission().then((permission) => {\n if (permission === 'granted') {\n showNotification()\n }\n })\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAiD,CAAC,OAAO,EAAE,QAAQ,MAAM;AACpF,MAAI,EAAE,kBAAkB,SAAS;AAC/B,UAAM,MAAM,oDAAoD;AAAA,EAClE;AAEA,MAAI,aAAa,eAAe;AAAU,WAAO,CAAC;AAElD,QAAM,mBAAmB,MAAM;AAC7B,QAAI,aAAa,OAAO;AAAA,MACtB,MAAM;AAAA,IACR,CAAC;AAAA,EACH;AAEA,MAAI,aAAa,eAAe,WAAW;AACzC,qBAAiB;AAAA,EACnB,OAAO;AACL,iBAAa,kBAAkB,EAAE,KAAK,CAAC,eAAe;AACpD,UAAI,eAAe,WAAW;AAC5B,yBAAiB;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const createNativeToast = (title, { message, duration, preset = "done" }) => {
|
|
2
|
+
const Burnt = require("burnt");
|
|
3
|
+
Burnt.toast({
|
|
4
|
+
title,
|
|
5
|
+
message: message ?? "",
|
|
6
|
+
preset,
|
|
7
|
+
duration
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
createNativeToast
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=createNativeToast.native.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createNativeToast.native.tsx"],
|
|
4
|
+
"sourcesContent": ["import { CreateNativeToastsOptions, CreateNativeToastsOptionsFn } from './types'\n\nexport const createNativeToast: CreateNativeToastsOptionsFn = (\n title,\n { message, duration, preset = 'done' }: CreateNativeToastsOptions\n) => {\n // import inline to allow lazy usage of native dependecy:\n const Burnt = require('burnt')\n\n Burnt.toast({\n title,\n message: message ?? '',\n preset,\n duration,\n })\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAiD,CAC5D,OACA,EAAE,SAAS,UAAU,SAAS,OAAO,MAClC;AAEH,QAAM,QAAQ,QAAQ,OAAO;AAE7B,QAAM,MAAM;AAAA,IACV;AAAA,IACA,SAAS,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const createNativeToast = (title, { message, duration, preset = "done" }) => {
|
|
2
|
+
const Burnt = require("burnt");
|
|
3
|
+
Burnt.toast({
|
|
4
|
+
title,
|
|
5
|
+
message: message ?? "",
|
|
6
|
+
preset,
|
|
7
|
+
duration
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
createNativeToast
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=createNativeToast.native.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createNativeToast.native.tsx"],
|
|
4
|
+
"sourcesContent": ["import { CreateNativeToastsOptions, CreateNativeToastsOptionsFn } from './types'\n\nexport const createNativeToast: CreateNativeToastsOptionsFn = (\n title,\n { message, duration, preset = 'done' }: CreateNativeToastsOptions\n) => {\n // import inline to allow lazy usage of native dependecy:\n const Burnt = require('burnt')\n\n Burnt.toast({\n title,\n message: message ?? '',\n preset,\n duration,\n })\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,oBAAiD,CAC5D,OACA,EAAE,SAAS,UAAU,SAAS,OAAO,MAClC;AAEH,QAAM,QAAQ,QAAQ,OAAO;AAE7B,QAAM,MAAM;AAAA,IACV;AAAA,IACA,SAAS,WAAW;AAAA,IACpB;AAAA,IACA;AAAA,EACF,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isWeb } from "@tamagui/core";
|
|
3
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
4
|
+
import React, { useRef } from "react";
|
|
5
|
+
import { createNativeToast } from "./createNativeToast";
|
|
6
|
+
const [createImperativeToastContext, createImperativeToastScope] = createContextScope("ImperativeToast");
|
|
7
|
+
const [ImperativeToastProvider, useToastProviderContext] = createImperativeToastContext("ImperativeToastProvider");
|
|
8
|
+
const createToast = (options = {}) => {
|
|
9
|
+
return {
|
|
10
|
+
ImperativeToastProvider: ({
|
|
11
|
+
__scopeToast,
|
|
12
|
+
children
|
|
13
|
+
}) => {
|
|
14
|
+
const counterRef = useRef(0);
|
|
15
|
+
const [toast, setToast] = React.useState(null);
|
|
16
|
+
const addToast = React.useCallback(
|
|
17
|
+
(title, options2) => {
|
|
18
|
+
counterRef.current++;
|
|
19
|
+
setToast({ title, id: counterRef.current.toString(), ...options2 });
|
|
20
|
+
},
|
|
21
|
+
[setToast]
|
|
22
|
+
);
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
ImperativeToastProvider,
|
|
25
|
+
{
|
|
26
|
+
scope: __scopeToast,
|
|
27
|
+
addToast,
|
|
28
|
+
currentToast: toast,
|
|
29
|
+
children
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
},
|
|
33
|
+
useToast: () => {
|
|
34
|
+
const context = useToastProviderContext("useToast", void 0);
|
|
35
|
+
return {
|
|
36
|
+
/**
|
|
37
|
+
* The toast to get and show if not using native
|
|
38
|
+
*/
|
|
39
|
+
currentToast: context.currentToast,
|
|
40
|
+
show(title, showOptions) {
|
|
41
|
+
const native = (showOptions == null ? void 0 : showOptions.native) || options.native;
|
|
42
|
+
if (native === true || Array.isArray(options.native) && (isWeb && options.native.includes("web") || !isWeb && options.native.includes("mobile"))) {
|
|
43
|
+
return createNativeToast(title, showOptions ?? {});
|
|
44
|
+
}
|
|
45
|
+
context.addToast(title, showOptions ?? {});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
createToast
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=createToast.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createToast.tsx"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport React, { useRef } from 'react'\n\nimport { createNativeToast } from './createNativeToast'\nimport { CreateNativeToastsOptions, CreateNativeToastsOptionsFn } from './types'\n\ntype NativeValue = boolean | 'web' | 'mobile'\ninterface CreateToastOptions {\n /**\n * Will show a native toast if is true or is set to the current platform. On iOS, it wraps `SPIndicator` and `SPAlert`. On Android, it wraps `ToastAndroid`. On web, it wraps Notification API. Mobile's native features are handled by `burnt`.\n */\n native?: NativeValue\n}\ninterface ToastOptions extends CreateNativeToastsOptions {\n /**\n * Used when need custom data\n */\n additionalInfo?: Record<string, any>\n /**\n * Overrides the native option on `createToast()`\n */\n native?: NativeValue\n}\ntype ScopedProps<P> = P & { __scopeToast?: Scope }\n\ntype ToastData = { title: string; id: string } & CreateNativeToastsOptions\n\ninterface ImperativeToastContextValue {\n currentToast: ToastData | null\n addToast: CreateNativeToastsOptionsFn\n}\n\nconst [createImperativeToastContext, createImperativeToastScope] =\n createContextScope('ImperativeToast')\n\nconst [ImperativeToastProvider, useToastProviderContext] =\n createImperativeToastContext<ImperativeToastContextValue>('ImperativeToastProvider')\n\nconst createToast = (options = {} as CreateToastOptions) => {\n return {\n ImperativeToastProvider: ({\n __scopeToast,\n children,\n }: ScopedProps<{ children: React.ReactNode }>) => {\n const counterRef = useRef(0)\n const [toast, setToast] =\n React.useState<ImperativeToastContextValue['currentToast']>(null)\n const addToast = React.useCallback<CreateNativeToastsOptionsFn>(\n (title, options) => {\n counterRef.current++\n setToast({ title, id: counterRef.current.toString(), ...options })\n },\n [setToast]\n )\n\n return (\n <ImperativeToastProvider\n scope={__scopeToast}\n addToast={addToast}\n currentToast={toast}\n >\n {children}\n </ImperativeToastProvider>\n )\n },\n useToast: () => {\n const context = useToastProviderContext('useToast', undefined)\n\n return {\n /**\n * The toast to get and show if not using native\n */\n currentToast: context.currentToast,\n show(title: string, showOptions?: ToastOptions) {\n const native = showOptions?.native || options.native\n if (\n native === true ||\n (Array.isArray(options.native) &&\n ((isWeb && options.native.includes('web')) ||\n (!isWeb && options.native.includes('mobile'))))\n ) {\n return createNativeToast(title, showOptions ?? {})\n }\n context.addToast(title, showOptions ?? {})\n },\n }\n },\n }\n}\n\nexport { createToast }\nexport type { CreateToastOptions }\n"],
|
|
5
|
+
"mappings": "AAyDQ;AAzDR,SAAS,aAAa;AACtB,SAAgB,0BAA0B;AAC1C,OAAO,SAAS,cAAc;AAE9B,SAAS,yBAAyB;AA6BlC,MAAM,CAAC,8BAA8B,0BAA0B,IAC7D,mBAAmB,iBAAiB;AAEtC,MAAM,CAAC,yBAAyB,uBAAuB,IACrD,6BAA0D,yBAAyB;AAErF,MAAM,cAAc,CAAC,UAAU,CAAC,MAA4B;AAC1D,SAAO;AAAA,IACL,yBAAyB,CAAC;AAAA,MACxB;AAAA,MACA;AAAA,IACF,MAAkD;AAChD,YAAM,aAAa,OAAO,CAAC;AAC3B,YAAM,CAAC,OAAO,QAAQ,IACpB,MAAM,SAAsD,IAAI;AAClE,YAAM,WAAW,MAAM;AAAA,QACrB,CAAC,OAAOA,aAAY;AAClB,qBAAW;AACX,mBAAS,EAAE,OAAO,IAAI,WAAW,QAAQ,SAAS,GAAG,GAAGA,SAAQ,CAAC;AAAA,QACnE;AAAA,QACA,CAAC,QAAQ;AAAA,MACX;AAEA,aACE;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,UACP;AAAA,UACA,cAAc;AAAA,UAEb;AAAA;AAAA,MACH;AAAA,IAEJ;AAAA,IACA,UAAU,MAAM;AACd,YAAM,UAAU,wBAAwB,YAAY,MAAS;AAE7D,aAAO;AAAA;AAAA;AAAA;AAAA,QAIL,cAAc,QAAQ;AAAA,QACtB,KAAK,OAAe,aAA4B;AAC9C,gBAAM,UAAS,2CAAa,WAAU,QAAQ;AAC9C,cACE,WAAW,QACV,MAAM,QAAQ,QAAQ,MAAM,MACzB,SAAS,QAAQ,OAAO,SAAS,KAAK,KACrC,CAAC,SAAS,QAAQ,OAAO,SAAS,QAAQ,IAC/C;AACA,mBAAO,kBAAkB,OAAO,eAAe,CAAC,CAAC;AAAA,UACnD;AACA,kBAAQ,SAAS,OAAO,eAAe,CAAC,CAAC;AAAA,QAC3C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["options"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isWeb } from "@tamagui/core";
|
|
3
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
4
|
+
import React, { useRef } from "react";
|
|
5
|
+
import { createNativeToast } from "./createNativeToast";
|
|
6
|
+
const [createImperativeToastContext, createImperativeToastScope] = createContextScope("ImperativeToast");
|
|
7
|
+
const [ImperativeToastProvider, useToastProviderContext] = createImperativeToastContext("ImperativeToastProvider");
|
|
8
|
+
const createToast = (options = {}) => {
|
|
9
|
+
return {
|
|
10
|
+
ImperativeToastProvider: ({
|
|
11
|
+
__scopeToast,
|
|
12
|
+
children
|
|
13
|
+
}) => {
|
|
14
|
+
const counterRef = useRef(0);
|
|
15
|
+
const [toast, setToast] = React.useState(null);
|
|
16
|
+
const addToast = React.useCallback(
|
|
17
|
+
(title, options2) => {
|
|
18
|
+
counterRef.current++;
|
|
19
|
+
setToast({ title, id: counterRef.current.toString(), ...options2 });
|
|
20
|
+
},
|
|
21
|
+
[setToast]
|
|
22
|
+
);
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
ImperativeToastProvider,
|
|
25
|
+
{
|
|
26
|
+
scope: __scopeToast,
|
|
27
|
+
addToast,
|
|
28
|
+
currentToast: toast,
|
|
29
|
+
children
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
},
|
|
33
|
+
useToast: () => {
|
|
34
|
+
const context = useToastProviderContext("useToast", void 0);
|
|
35
|
+
return {
|
|
36
|
+
/**
|
|
37
|
+
* The toast to get and show if not using native
|
|
38
|
+
*/
|
|
39
|
+
currentToast: context.currentToast,
|
|
40
|
+
show(title, showOptions) {
|
|
41
|
+
const native = (showOptions == null ? void 0 : showOptions.native) || options.native;
|
|
42
|
+
if (native === true || Array.isArray(options.native) && (isWeb && options.native.includes("web") || !isWeb && options.native.includes("mobile"))) {
|
|
43
|
+
return createNativeToast(title, showOptions ?? {});
|
|
44
|
+
}
|
|
45
|
+
context.addToast(title, showOptions ?? {});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
createToast
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=createToast.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createToast.tsx"],
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport React, { useRef } from 'react'\n\nimport { createNativeToast } from './createNativeToast'\nimport { CreateNativeToastsOptions, CreateNativeToastsOptionsFn } from './types'\n\ntype NativeValue = boolean | 'web' | 'mobile'\ninterface CreateToastOptions {\n /**\n * Will show a native toast if is true or is set to the current platform. On iOS, it wraps `SPIndicator` and `SPAlert`. On Android, it wraps `ToastAndroid`. On web, it wraps Notification API. Mobile's native features are handled by `burnt`.\n */\n native?: NativeValue\n}\ninterface ToastOptions extends CreateNativeToastsOptions {\n /**\n * Used when need custom data\n */\n additionalInfo?: Record<string, any>\n /**\n * Overrides the native option on `createToast()`\n */\n native?: NativeValue\n}\ntype ScopedProps<P> = P & { __scopeToast?: Scope }\n\ntype ToastData = { title: string; id: string } & CreateNativeToastsOptions\n\ninterface ImperativeToastContextValue {\n currentToast: ToastData | null\n addToast: CreateNativeToastsOptionsFn\n}\n\nconst [createImperativeToastContext, createImperativeToastScope] =\n createContextScope('ImperativeToast')\n\nconst [ImperativeToastProvider, useToastProviderContext] =\n createImperativeToastContext<ImperativeToastContextValue>('ImperativeToastProvider')\n\nconst createToast = (options = {} as CreateToastOptions) => {\n return {\n ImperativeToastProvider: ({\n __scopeToast,\n children,\n }: ScopedProps<{ children: React.ReactNode }>) => {\n const counterRef = useRef(0)\n const [toast, setToast] =\n React.useState<ImperativeToastContextValue['currentToast']>(null)\n const addToast = React.useCallback<CreateNativeToastsOptionsFn>(\n (title, options) => {\n counterRef.current++\n setToast({ title, id: counterRef.current.toString(), ...options })\n },\n [setToast]\n )\n\n return (\n <ImperativeToastProvider\n scope={__scopeToast}\n addToast={addToast}\n currentToast={toast}\n >\n {children}\n </ImperativeToastProvider>\n )\n },\n useToast: () => {\n const context = useToastProviderContext('useToast', undefined)\n\n return {\n /**\n * The toast to get and show if not using native\n */\n currentToast: context.currentToast,\n show(title: string, showOptions?: ToastOptions) {\n const native = showOptions?.native || options.native\n if (\n native === true ||\n (Array.isArray(options.native) &&\n ((isWeb && options.native.includes('web')) ||\n (!isWeb && options.native.includes('mobile'))))\n ) {\n return createNativeToast(title, showOptions ?? {})\n }\n context.addToast(title, showOptions ?? {})\n },\n }\n },\n }\n}\n\nexport { createToast }\nexport type { CreateToastOptions }\n"],
|
|
5
|
+
"mappings": "AAyDQ;AAzDR,SAAS,aAAa;AACtB,SAAgB,0BAA0B;AAC1C,OAAO,SAAS,cAAc;AAE9B,SAAS,yBAAyB;AA6BlC,MAAM,CAAC,8BAA8B,0BAA0B,IAC7D,mBAAmB,iBAAiB;AAEtC,MAAM,CAAC,yBAAyB,uBAAuB,IACrD,6BAA0D,yBAAyB;AAErF,MAAM,cAAc,CAAC,UAAU,CAAC,MAA4B;AAC1D,SAAO;AAAA,IACL,yBAAyB,CAAC;AAAA,MACxB;AAAA,MACA;AAAA,IACF,MAAkD;AAChD,YAAM,aAAa,OAAO,CAAC;AAC3B,YAAM,CAAC,OAAO,QAAQ,IACpB,MAAM,SAAsD,IAAI;AAClE,YAAM,WAAW,MAAM;AAAA,QACrB,CAAC,OAAOA,aAAY;AAClB,qBAAW;AACX,mBAAS,EAAE,OAAO,IAAI,WAAW,QAAQ,SAAS,GAAG,GAAGA,SAAQ,CAAC;AAAA,QACnE;AAAA,QACA,CAAC,QAAQ;AAAA,MACX;AAEA,aACE;AAAA,QAAC;AAAA;AAAA,UACC,OAAO;AAAA,UACP;AAAA,UACA,cAAc;AAAA,UAEb;AAAA;AAAA,MACH;AAAA,IAEJ;AAAA,IACA,UAAU,MAAM;AACd,YAAM,UAAU,wBAAwB,YAAY,MAAS;AAE7D,aAAO;AAAA;AAAA;AAAA;AAAA,QAIL,cAAc,QAAQ;AAAA,QACtB,KAAK,OAAe,aAA4B;AAC9C,gBAAM,UAAS,2CAAa,WAAU,QAAQ;AAC9C,cACE,WAAW,QACV,MAAM,QAAQ,QAAQ,MAAM,MACzB,SAAS,QAAQ,OAAO,SAAS,KAAK,KACrC,CAAC,SAAS,QAAQ,OAAO,SAAS,QAAQ,IAC/C;AACA,mBAAO,kBAAkB,OAAO,eAAe,CAAC,CAAC;AAAA,UACnD;AACA,kBAAQ,SAAS,OAAO,eAAe,CAAC,CAAC;AAAA,QAC3C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["options"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|