@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,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,49 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/core";
|
|
2
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
3
|
+
import React, { useRef } from "react";
|
|
4
|
+
import { createNativeToast } from "./createNativeToast";
|
|
5
|
+
const [createImperativeToastContext, createImperativeToastScope] = createContextScope("ImperativeToast");
|
|
6
|
+
const [ImperativeToastProvider, useToastProviderContext] = createImperativeToastContext("ImperativeToastProvider");
|
|
7
|
+
const createToast = (options = {}) => {
|
|
8
|
+
return {
|
|
9
|
+
ImperativeToastProvider: ({
|
|
10
|
+
__scopeToast,
|
|
11
|
+
children
|
|
12
|
+
}) => {
|
|
13
|
+
const counterRef = useRef(0);
|
|
14
|
+
const [toast, setToast] = React.useState(null);
|
|
15
|
+
const addToast = React.useCallback(
|
|
16
|
+
(title, options2) => {
|
|
17
|
+
counterRef.current++;
|
|
18
|
+
setToast({ title, id: counterRef.current.toString(), ...options2 });
|
|
19
|
+
},
|
|
20
|
+
[setToast]
|
|
21
|
+
);
|
|
22
|
+
return <ImperativeToastProvider
|
|
23
|
+
scope={__scopeToast}
|
|
24
|
+
addToast={addToast}
|
|
25
|
+
currentToast={toast}
|
|
26
|
+
>{children}</ImperativeToastProvider>;
|
|
27
|
+
},
|
|
28
|
+
useToast: () => {
|
|
29
|
+
const context = useToastProviderContext("useToast", void 0);
|
|
30
|
+
return {
|
|
31
|
+
/**
|
|
32
|
+
* The toast to get and show if not using native
|
|
33
|
+
*/
|
|
34
|
+
currentToast: context.currentToast,
|
|
35
|
+
show(title, showOptions) {
|
|
36
|
+
const native = showOptions?.native || options.native;
|
|
37
|
+
if (native === true || Array.isArray(options.native) && (isWeb && options.native.includes("web") || !isWeb && options.native.includes("mobile"))) {
|
|
38
|
+
return createNativeToast(title, showOptions ?? {});
|
|
39
|
+
}
|
|
40
|
+
context.addToast(title, showOptions ?? {});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
createToast
|
|
48
|
+
};
|
|
49
|
+
//# 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": "AAAA,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,CAAC;AAAA,QACC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,cAAc;AAAA,QAEb,SACH,EANC;AAAA,IAQL;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,SAAS,aAAa,UAAU,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,49 @@
|
|
|
1
|
+
import { isWeb } from "@tamagui/core";
|
|
2
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
3
|
+
import React, { useRef } from "react";
|
|
4
|
+
import { createNativeToast } from "./createNativeToast";
|
|
5
|
+
const [createImperativeToastContext, createImperativeToastScope] = createContextScope("ImperativeToast");
|
|
6
|
+
const [ImperativeToastProvider, useToastProviderContext] = createImperativeToastContext("ImperativeToastProvider");
|
|
7
|
+
const createToast = (options = {}) => {
|
|
8
|
+
return {
|
|
9
|
+
ImperativeToastProvider: ({
|
|
10
|
+
__scopeToast,
|
|
11
|
+
children
|
|
12
|
+
}) => {
|
|
13
|
+
const counterRef = useRef(0);
|
|
14
|
+
const [toast, setToast] = React.useState(null);
|
|
15
|
+
const addToast = React.useCallback(
|
|
16
|
+
(title, options2) => {
|
|
17
|
+
counterRef.current++;
|
|
18
|
+
setToast({ title, id: counterRef.current.toString(), ...options2 });
|
|
19
|
+
},
|
|
20
|
+
[setToast]
|
|
21
|
+
);
|
|
22
|
+
return <ImperativeToastProvider
|
|
23
|
+
scope={__scopeToast}
|
|
24
|
+
addToast={addToast}
|
|
25
|
+
currentToast={toast}
|
|
26
|
+
>{children}</ImperativeToastProvider>;
|
|
27
|
+
},
|
|
28
|
+
useToast: () => {
|
|
29
|
+
const context = useToastProviderContext("useToast", void 0);
|
|
30
|
+
return {
|
|
31
|
+
/**
|
|
32
|
+
* The toast to get and show if not using native
|
|
33
|
+
*/
|
|
34
|
+
currentToast: context.currentToast,
|
|
35
|
+
show(title, showOptions) {
|
|
36
|
+
const native = showOptions?.native || options.native;
|
|
37
|
+
if (native === true || Array.isArray(options.native) && (isWeb && options.native.includes("web") || !isWeb && options.native.includes("mobile"))) {
|
|
38
|
+
return createNativeToast(title, showOptions ?? {});
|
|
39
|
+
}
|
|
40
|
+
context.addToast(title, showOptions ?? {});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
createToast
|
|
48
|
+
};
|
|
49
|
+
//# 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": "AAAA,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,CAAC;AAAA,QACC,OAAO;AAAA,QACP,UAAU;AAAA,QACV,cAAc;AAAA,QAEb,SACH,EANC;AAAA,IAQL;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,SAAS,aAAa,UAAU,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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/toast",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -31,24 +31,25 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/animate-presence": "1.
|
|
35
|
-
"@tamagui/compose-refs": "1.
|
|
36
|
-
"@tamagui/core": "1.
|
|
37
|
-
"@tamagui/create-context": "1.
|
|
38
|
-
"@tamagui/dismissable": "1.
|
|
39
|
-
"@tamagui/polyfill-dev": "1.
|
|
40
|
-
"@tamagui/portal": "1.
|
|
41
|
-
"@tamagui/stacks": "1.
|
|
42
|
-
"@tamagui/text": "1.
|
|
43
|
-
"@tamagui/use-controllable-state": "1.
|
|
44
|
-
"@tamagui/visually-hidden": "1.
|
|
34
|
+
"@tamagui/animate-presence": "1.8.0",
|
|
35
|
+
"@tamagui/compose-refs": "1.8.0",
|
|
36
|
+
"@tamagui/core": "1.8.0",
|
|
37
|
+
"@tamagui/create-context": "1.8.0",
|
|
38
|
+
"@tamagui/dismissable": "1.8.0",
|
|
39
|
+
"@tamagui/polyfill-dev": "1.8.0",
|
|
40
|
+
"@tamagui/portal": "1.8.0",
|
|
41
|
+
"@tamagui/stacks": "1.8.0",
|
|
42
|
+
"@tamagui/text": "1.8.0",
|
|
43
|
+
"@tamagui/use-controllable-state": "1.8.0",
|
|
44
|
+
"@tamagui/visually-hidden": "1.8.0",
|
|
45
|
+
"burnt": "^0.10.0"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"react": "*",
|
|
48
49
|
"react-native": "*"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@tamagui/build": "1.
|
|
52
|
+
"@tamagui/build": "1.8.0",
|
|
52
53
|
"react": "^18.2.0",
|
|
53
54
|
"react-native": "^0.71.4"
|
|
54
55
|
},
|