@tamagui/toast 1.9.0 → 1.9.1

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.
Files changed (98) hide show
  1. package/dist/cjs/Toast.js +2 -4
  2. package/dist/cjs/Toast.js.map +2 -2
  3. package/dist/cjs/ToastImperative.js +119 -0
  4. package/dist/cjs/ToastImperative.js.map +7 -0
  5. package/dist/cjs/ToastImpl.js +0 -1
  6. package/dist/cjs/ToastImpl.js.map +2 -2
  7. package/dist/cjs/ToastViewport.js +2 -1
  8. package/dist/cjs/ToastViewport.js.map +2 -2
  9. package/dist/cjs/createNativeToast.js +30 -9
  10. package/dist/cjs/createNativeToast.js.map +2 -2
  11. package/dist/cjs/createNativeToast.native.js +13 -6
  12. package/dist/cjs/createNativeToast.native.js.map +2 -2
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/cjs/index.js.map +2 -2
  15. package/dist/cjs/types.js.map +1 -1
  16. package/dist/esm/Toast.js +2 -3
  17. package/dist/esm/Toast.js.map +2 -2
  18. package/dist/esm/Toast.mjs +2 -3
  19. package/dist/esm/Toast.mjs.map +2 -2
  20. package/dist/esm/ToastImperative.js +84 -0
  21. package/dist/esm/ToastImperative.js.map +7 -0
  22. package/dist/esm/ToastImperative.mjs +84 -0
  23. package/dist/esm/ToastImperative.mjs.map +7 -0
  24. package/dist/esm/ToastImpl.js +0 -1
  25. package/dist/esm/ToastImpl.js.map +2 -2
  26. package/dist/esm/ToastImpl.mjs +0 -1
  27. package/dist/esm/ToastImpl.mjs.map +2 -2
  28. package/dist/esm/ToastViewport.js +2 -1
  29. package/dist/esm/ToastViewport.js.map +2 -2
  30. package/dist/esm/ToastViewport.mjs +2 -1
  31. package/dist/esm/ToastViewport.mjs.map +2 -2
  32. package/dist/esm/createNativeToast.js +28 -8
  33. package/dist/esm/createNativeToast.js.map +2 -2
  34. package/dist/esm/createNativeToast.mjs +28 -8
  35. package/dist/esm/createNativeToast.mjs.map +2 -2
  36. package/dist/esm/createNativeToast.native.js +11 -5
  37. package/dist/esm/createNativeToast.native.js.map +2 -2
  38. package/dist/esm/createNativeToast.native.mjs +11 -5
  39. package/dist/esm/createNativeToast.native.mjs.map +2 -2
  40. package/dist/esm/index.js +1 -0
  41. package/dist/esm/index.js.map +2 -2
  42. package/dist/esm/index.mjs +1 -0
  43. package/dist/esm/index.mjs.map +2 -2
  44. package/dist/jsx/Toast.js +2 -3
  45. package/dist/jsx/Toast.js.map +2 -2
  46. package/dist/jsx/Toast.mjs +2 -3
  47. package/dist/jsx/Toast.mjs.map +2 -2
  48. package/dist/jsx/ToastImperative.js +79 -0
  49. package/dist/jsx/ToastImperative.js.map +7 -0
  50. package/dist/jsx/ToastImperative.mjs +79 -0
  51. package/dist/jsx/ToastImperative.mjs.map +7 -0
  52. package/dist/jsx/ToastImpl.js +0 -1
  53. package/dist/jsx/ToastImpl.js.map +2 -2
  54. package/dist/jsx/ToastImpl.mjs +0 -1
  55. package/dist/jsx/ToastImpl.mjs.map +2 -2
  56. package/dist/jsx/ToastViewport.js +2 -1
  57. package/dist/jsx/ToastViewport.js.map +2 -2
  58. package/dist/jsx/ToastViewport.mjs +2 -1
  59. package/dist/jsx/ToastViewport.mjs.map +2 -2
  60. package/dist/jsx/createNativeToast.js +28 -8
  61. package/dist/jsx/createNativeToast.js.map +2 -2
  62. package/dist/jsx/createNativeToast.mjs +28 -8
  63. package/dist/jsx/createNativeToast.mjs.map +2 -2
  64. package/dist/jsx/createNativeToast.native.js +11 -5
  65. package/dist/jsx/createNativeToast.native.js.map +2 -2
  66. package/dist/jsx/createNativeToast.native.mjs +11 -5
  67. package/dist/jsx/createNativeToast.native.mjs.map +2 -2
  68. package/dist/jsx/index.js +1 -0
  69. package/dist/jsx/index.js.map +2 -2
  70. package/dist/jsx/index.mjs +1 -0
  71. package/dist/jsx/index.mjs.map +2 -2
  72. package/package.json +13 -13
  73. package/src/Toast.tsx +3 -5
  74. package/src/ToastImperative.tsx +150 -0
  75. package/src/ToastImpl.tsx +13 -10
  76. package/src/ToastViewport.tsx +10 -2
  77. package/src/createNativeToast.native.tsx +18 -7
  78. package/src/createNativeToast.tsx +32 -8
  79. package/src/index.ts +1 -0
  80. package/src/types.ts +31 -9
  81. package/types/Toast.d.ts +1 -2
  82. package/types/Toast.d.ts.map +1 -1
  83. package/types/ToastImperative.d.ts +57 -0
  84. package/types/ToastImperative.d.ts.map +1 -0
  85. package/types/ToastImpl.d.ts +8 -0
  86. package/types/ToastImpl.d.ts.map +1 -1
  87. package/types/ToastViewport.d.ts +12 -0
  88. package/types/ToastViewport.d.ts.map +1 -1
  89. package/types/createNativeToast.d.ts +3 -2
  90. package/types/createNativeToast.d.ts.map +1 -1
  91. package/types/createNativeToast.native.d.ts +3 -2
  92. package/types/createNativeToast.native.d.ts.map +1 -1
  93. package/types/index.d.ts +1 -0
  94. package/types/index.d.ts.map +1 -1
  95. package/types/types.d.ts +24 -7
  96. package/types/types.d.ts.map +1 -1
  97. package/src/createToast.tsx +0 -93
  98. package/types/createToast.d.ts +0 -42
package/types/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './Toast';
2
+ export * from './ToastImperative';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA"}
package/types/types.d.ts CHANGED
@@ -1,17 +1,34 @@
1
- import { ToastOptions as BurntToastOptions } from 'burnt/build/types';
2
- export interface CreateNativeToastsOptions {
1
+ import { BaseToastOptions as BurntToastOptions } from 'burnt/build/types';
2
+ export interface CreateNativeToastOptions {
3
3
  /**
4
4
  * Body of the toast
5
5
  */
6
6
  message?: BurntToastOptions['message'];
7
7
  /**
8
- * Only supported on native iOS driver
8
+ * Duration of toast in ms
9
+ *
10
+ * @example 1000
9
11
  */
10
- preset?: BurntToastOptions['preset'];
12
+ duration?: BurntToastOptions['duration'];
11
13
  /**
12
- * Duration of toast
14
+ * Options for the burnt package if you're using native toasts on mobile
13
15
  */
14
- duration?: BurntToastOptions['duration'];
16
+ burntOptions?: Omit<BurntToastOptions, 'title' | 'message' | 'duration'>;
17
+ /**
18
+ * Options for the notification API if you're using native toasts on web
19
+ */
20
+ notificationOptions?: NotificationOptions;
21
+ }
22
+ export interface NativeToastRef {
23
+ /**
24
+ * Used to close web notifications
25
+ */
26
+ close: () => void;
15
27
  }
16
- export type CreateNativeToastsOptionsFn = (title: string, options: CreateNativeToastsOptions) => void;
28
+ export type CreateNativeToastsFn = (title: string, options: CreateNativeToastOptions) => {
29
+ nativeToastRef?: NativeToastRef;
30
+ } | boolean;
31
+ export type HideNativeToastsFn = (ref?: NativeToastRef) => void;
32
+ export type ToastNativePlatform = 'web' | 'mobile' | 'android' | 'ios';
33
+ export type ToastNativeValue = boolean | ToastNativePlatform | ToastNativePlatform[];
17
34
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAErE,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IACpC;;OAEG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAA;CACzC;AAED,MAAM,MAAM,2BAA2B,GAAG,CACxC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,yBAAyB,KAC/B,IAAI,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,IAAI,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAEzE,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;IACtC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAA;IACxC;;OAEG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC,CAAA;IACxE;;OAEG;IACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;CAC1C;AAED,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,wBAAwB,KAE/B;IACE,cAAc,CAAC,EAAE,cAAc,CAAA;CAChC,GACD,OAAO,CAAA;AAEX,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,CAAC,EAAE,cAAc,KAAK,IAAI,CAAA;AAE/D,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,CAAA;AACtE,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,mBAAmB,GAAG,mBAAmB,EAAE,CAAA"}
@@ -1,93 +0,0 @@
1
- import { isWeb } from '@tamagui/core'
2
- import { Scope, createContextScope } from '@tamagui/create-context'
3
- import React, { useRef } from 'react'
4
-
5
- import { createNativeToast } from './createNativeToast'
6
- import { CreateNativeToastsOptions, CreateNativeToastsOptionsFn } from './types'
7
-
8
- type NativeValue = boolean | 'web' | 'mobile'
9
- interface CreateToastOptions {
10
- /**
11
- * 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`.
12
- */
13
- native?: NativeValue
14
- }
15
- interface ToastOptions extends CreateNativeToastsOptions {
16
- /**
17
- * Used when need custom data
18
- */
19
- additionalInfo?: Record<string, any>
20
- /**
21
- * Overrides the native option on `createToast()`
22
- */
23
- native?: NativeValue
24
- }
25
- type ScopedProps<P> = P & { __scopeToast?: Scope }
26
-
27
- type ToastData = { title: string; id: string } & CreateNativeToastsOptions
28
-
29
- interface ImperativeToastContextValue {
30
- currentToast: ToastData | null
31
- addToast: CreateNativeToastsOptionsFn
32
- }
33
-
34
- const [createImperativeToastContext, createImperativeToastScope] =
35
- createContextScope('ImperativeToast')
36
-
37
- const [ImperativeToastProvider, useToastProviderContext] =
38
- createImperativeToastContext<ImperativeToastContextValue>('ImperativeToastProvider')
39
-
40
- const createToast = (options = {} as CreateToastOptions) => {
41
- return {
42
- ImperativeToastProvider: ({
43
- __scopeToast,
44
- children,
45
- }: ScopedProps<{ children: React.ReactNode }>) => {
46
- const counterRef = useRef(0)
47
- const [toast, setToast] =
48
- React.useState<ImperativeToastContextValue['currentToast']>(null)
49
- const addToast = React.useCallback<CreateNativeToastsOptionsFn>(
50
- (title, options) => {
51
- counterRef.current++
52
- setToast({ title, id: counterRef.current.toString(), ...options })
53
- },
54
- [setToast]
55
- )
56
-
57
- return (
58
- <ImperativeToastProvider
59
- scope={__scopeToast}
60
- addToast={addToast}
61
- currentToast={toast}
62
- >
63
- {children}
64
- </ImperativeToastProvider>
65
- )
66
- },
67
- useToast: () => {
68
- const context = useToastProviderContext('useToast', undefined)
69
-
70
- return {
71
- /**
72
- * The toast to get and show if not using native
73
- */
74
- currentToast: context.currentToast,
75
- show(title: string, showOptions?: ToastOptions) {
76
- const native = showOptions?.native || options.native
77
- if (
78
- native === true ||
79
- (Array.isArray(options.native) &&
80
- ((isWeb && options.native.includes('web')) ||
81
- (!isWeb && options.native.includes('mobile'))))
82
- ) {
83
- return createNativeToast(title, showOptions ?? {})
84
- }
85
- context.addToast(title, showOptions ?? {})
86
- },
87
- }
88
- },
89
- }
90
- }
91
-
92
- export { createToast }
93
- export type { CreateToastOptions }
@@ -1,42 +0,0 @@
1
- import { Scope } from '@tamagui/create-context';
2
- import React from 'react';
3
- import { CreateNativeToastsOptions } from './types';
4
- type NativeValue = boolean | 'web' | 'mobile';
5
- interface CreateToastOptions {
6
- /**
7
- * 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`.
8
- */
9
- native?: NativeValue;
10
- }
11
- interface ToastOptions extends CreateNativeToastsOptions {
12
- /**
13
- * Used when need custom data
14
- */
15
- additionalInfo?: Record<string, any>;
16
- /**
17
- * Overrides the native option on `createToast()`
18
- */
19
- native?: NativeValue;
20
- }
21
- type ScopedProps<P> = P & {
22
- __scopeToast?: Scope;
23
- };
24
- type ToastData = {
25
- title: string;
26
- id: string;
27
- } & CreateNativeToastsOptions;
28
- declare const createToast: (options?: CreateToastOptions) => {
29
- ImperativeToastProvider: ({ __scopeToast, children, }: ScopedProps<{
30
- children: React.ReactNode;
31
- }>) => JSX.Element;
32
- useToast: () => {
33
- /**
34
- * The toast to get and show if not using native
35
- */
36
- currentToast: ToastData | null;
37
- show(title: string, showOptions?: ToastOptions): void;
38
- };
39
- };
40
- export { createToast };
41
- export type { CreateToastOptions };
42
- //# sourceMappingURL=createToast.d.ts.map