@tamagui/toast 1.14.0 → 1.14.2
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 +185 -1
- package/dist/cjs/Toast.js.map +2 -2
- package/dist/cjs/ToastAnnounce.js +92 -1
- package/dist/cjs/ToastAnnounce.js.map +2 -2
- package/dist/cjs/ToastImperative.js +110 -1
- package/dist/cjs/ToastImperative.js.map +2 -2
- package/dist/cjs/ToastImpl.js +352 -1
- package/dist/cjs/ToastImpl.js.map +2 -2
- package/dist/cjs/ToastProvider.js +119 -1
- package/dist/cjs/ToastProvider.js.map +2 -2
- package/dist/cjs/ToastViewport.js +312 -1
- package/dist/cjs/ToastViewport.js.map +2 -2
- package/dist/cjs/constants.js +28 -1
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/createNativeToast.js +69 -1
- package/dist/cjs/createNativeToast.js.map +2 -2
- package/dist/cjs/createNativeToast.native.js +43 -1
- package/dist/cjs/createNativeToast.native.js.map +2 -2
- package/dist/cjs/index.js +18 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +16 -1
- package/dist/cjs/types.js.map +2 -2
- package/dist/esm/Toast.js +163 -1
- package/dist/esm/Toast.js.map +2 -2
- package/dist/esm/Toast.mjs +163 -1
- package/dist/esm/Toast.mjs.map +2 -2
- package/dist/esm/ToastAnnounce.js +63 -1
- package/dist/esm/ToastAnnounce.js.map +2 -2
- package/dist/esm/ToastAnnounce.mjs +63 -1
- package/dist/esm/ToastAnnounce.mjs.map +2 -2
- package/dist/esm/ToastImperative.js +73 -1
- package/dist/esm/ToastImperative.js.map +2 -2
- package/dist/esm/ToastImperative.mjs +73 -1
- package/dist/esm/ToastImperative.mjs.map +2 -2
- package/dist/esm/ToastImpl.js +328 -1
- package/dist/esm/ToastImpl.js.map +2 -2
- package/dist/esm/ToastImpl.mjs +328 -1
- package/dist/esm/ToastImpl.mjs.map +2 -2
- package/dist/esm/ToastProvider.js +80 -1
- package/dist/esm/ToastProvider.js.map +2 -2
- package/dist/esm/ToastProvider.mjs +80 -1
- package/dist/esm/ToastProvider.mjs.map +2 -2
- package/dist/esm/ToastViewport.js +279 -1
- package/dist/esm/ToastViewport.js.map +2 -2
- package/dist/esm/ToastViewport.mjs +279 -1
- package/dist/esm/ToastViewport.mjs.map +2 -2
- package/dist/esm/constants.js +4 -1
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/constants.mjs +4 -1
- package/dist/esm/constants.mjs.map +2 -2
- package/dist/esm/createNativeToast.js +44 -1
- package/dist/esm/createNativeToast.js.map +2 -2
- package/dist/esm/createNativeToast.mjs +44 -1
- package/dist/esm/createNativeToast.mjs.map +2 -2
- package/dist/esm/createNativeToast.native.js +18 -1
- package/dist/esm/createNativeToast.native.js.map +2 -2
- package/dist/esm/createNativeToast.native.mjs +18 -1
- package/dist/esm/createNativeToast.native.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/jsx/Toast.js +156 -1
- package/dist/jsx/Toast.js.map +2 -2
- package/dist/jsx/Toast.mjs +156 -1
- package/dist/jsx/Toast.mjs.map +2 -2
- package/dist/jsx/ToastAnnounce.js +59 -1
- package/dist/jsx/ToastAnnounce.js.map +2 -2
- package/dist/jsx/ToastAnnounce.mjs +59 -1
- package/dist/jsx/ToastAnnounce.mjs.map +2 -2
- package/dist/jsx/ToastImperative.js +72 -1
- package/dist/jsx/ToastImperative.js.map +2 -2
- package/dist/jsx/ToastImperative.mjs +72 -1
- package/dist/jsx/ToastImperative.mjs.map +2 -2
- package/dist/jsx/ToastImpl.js +307 -1
- package/dist/jsx/ToastImpl.js.map +2 -2
- package/dist/jsx/ToastImpl.mjs +307 -1
- package/dist/jsx/ToastImpl.mjs.map +2 -2
- package/dist/jsx/ToastProvider.js +75 -1
- package/dist/jsx/ToastProvider.js.map +2 -2
- package/dist/jsx/ToastProvider.mjs +75 -1
- package/dist/jsx/ToastProvider.mjs.map +2 -2
- package/dist/jsx/ToastViewport.js +259 -1
- package/dist/jsx/ToastViewport.js.map +2 -2
- package/dist/jsx/ToastViewport.mjs +259 -1
- package/dist/jsx/ToastViewport.mjs.map +2 -2
- package/dist/jsx/constants.js +4 -1
- package/dist/jsx/constants.js.map +2 -2
- package/dist/jsx/constants.mjs +4 -1
- package/dist/jsx/constants.mjs.map +2 -2
- package/dist/jsx/createNativeToast.js +44 -1
- package/dist/jsx/createNativeToast.js.map +2 -2
- package/dist/jsx/createNativeToast.mjs +44 -1
- package/dist/jsx/createNativeToast.mjs.map +2 -2
- package/dist/jsx/createNativeToast.native.js +18 -1
- package/dist/jsx/createNativeToast.native.js.map +2 -2
- package/dist/jsx/createNativeToast.native.mjs +18 -1
- package/dist/jsx/createNativeToast.native.mjs.map +2 -2
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './Toast.js'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,uBAAd;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
2
17
|
//# sourceMappingURL=types.js.map
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types.ts"],
|
|
4
4
|
"sourcesContent": ["// from `burnt`\ntype BurntLayout = {\n iconSize?: {\n width: number\n height: number\n }\n}\n\n// from `burnt`\nexport type BurntToastOptions = {\n title: string\n message?: string\n /**\n * Defaults to `done`.\n */\n preset?: 'done' | 'error' | 'none'\n /**\n * Duration in seconds.\n */\n duration?: number\n haptic?: 'success' | 'warning' | 'error' | 'none'\n /**\n * Defaults to `true`.\n */\n shouldDismissByDrag?: boolean\n /**\n * Change the presentation side.\n * @platform ios\n */\n from?: 'top' | 'bottom'\n layout?: BurntLayout\n}\n\nexport interface CreateNativeToastOptions {\n /**\n * Body of the toast\n */\n message?: BurntToastOptions['message']\n /**\n * Duration of toast in ms\n *\n * @example 1000\n */\n duration?: BurntToastOptions['duration']\n /**\n * Options for the burnt package if you're using native toasts on mobile\n */\n burntOptions?: Omit<BurntToastOptions, 'title' | 'message' | 'duration'>\n /**\n * Options for the notification API if you're using native toasts on web\n */\n notificationOptions?: NotificationOptions\n}\n\nexport interface NativeToastRef {\n /**\n * Used to close web notifications\n */\n close: () => void\n}\n\nexport type CreateNativeToastsFn = (\n title: string,\n options: CreateNativeToastOptions\n) =>\n | {\n nativeToastRef?: NativeToastRef\n }\n | boolean\n\nexport type HideNativeToastsFn = (ref?: NativeToastRef) => void\n\nexport type ToastNativePlatform = 'web' | 'mobile' | 'android' | 'ios'\nexport type ToastNativeValue = boolean | ToastNativePlatform | ToastNativePlatform[]\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/esm/Toast.js
CHANGED
|
@@ -1,2 +1,164 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
composeEventHandlers,
|
|
4
|
+
styled,
|
|
5
|
+
themeable,
|
|
6
|
+
useEvent,
|
|
7
|
+
useId,
|
|
8
|
+
withStaticProperties
|
|
9
|
+
} from "@tamagui/core";
|
|
10
|
+
import { ThemeableStack } from "@tamagui/stacks";
|
|
11
|
+
import { SizableText } from "@tamagui/text";
|
|
12
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { TOAST_NAME } from "./constants";
|
|
15
|
+
import { ToastAnnounceExclude } from "./ToastAnnounce";
|
|
16
|
+
import {
|
|
17
|
+
useToast,
|
|
18
|
+
useToastController,
|
|
19
|
+
useToastState
|
|
20
|
+
} from "./ToastImperative.js";
|
|
21
|
+
import {
|
|
22
|
+
ToastImpl,
|
|
23
|
+
ToastImplFrame,
|
|
24
|
+
useToastInteractiveContext
|
|
25
|
+
} from "./ToastImpl";
|
|
26
|
+
import {
|
|
27
|
+
ToastProvider,
|
|
28
|
+
createToastScope
|
|
29
|
+
} from "./ToastProvider";
|
|
30
|
+
import { ToastViewport } from "./ToastViewport";
|
|
31
|
+
const TITLE_NAME = "ToastTitle";
|
|
32
|
+
const ToastTitleFrame = styled(SizableText, {
|
|
33
|
+
name: TITLE_NAME,
|
|
34
|
+
variants: {
|
|
35
|
+
unstyled: {
|
|
36
|
+
false: {
|
|
37
|
+
color: "$color",
|
|
38
|
+
size: "$4"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
defaultVariants: {
|
|
43
|
+
unstyled: false
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const ToastTitle = React.forwardRef(
|
|
47
|
+
(props, forwardedRef) => {
|
|
48
|
+
const { __scopeToast, ...titleProps } = props;
|
|
49
|
+
return /* @__PURE__ */ jsx(ToastTitleFrame, { ...titleProps, ref: forwardedRef });
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
ToastTitle.displayName = TITLE_NAME;
|
|
53
|
+
const DESCRIPTION_NAME = "ToastDescription";
|
|
54
|
+
const ToastDescriptionFrame = styled(SizableText, {
|
|
55
|
+
name: DESCRIPTION_NAME,
|
|
56
|
+
variants: {
|
|
57
|
+
unstyled: {
|
|
58
|
+
false: {
|
|
59
|
+
color: "$color11",
|
|
60
|
+
size: "$1"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
defaultVariants: {
|
|
65
|
+
unstyled: false
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const ToastDescription = React.forwardRef(
|
|
69
|
+
(props, forwardedRef) => {
|
|
70
|
+
const { __scopeToast, ...descriptionProps } = props;
|
|
71
|
+
return /* @__PURE__ */ jsx(ToastDescriptionFrame, { ...descriptionProps, ref: forwardedRef });
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
ToastDescription.displayName = DESCRIPTION_NAME;
|
|
75
|
+
const ACTION_NAME = "ToastAction";
|
|
76
|
+
const ToastAction = React.forwardRef(
|
|
77
|
+
(props, forwardedRef) => {
|
|
78
|
+
const { altText, ...actionProps } = props;
|
|
79
|
+
if (!altText)
|
|
80
|
+
return null;
|
|
81
|
+
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { altText, asChild: true, children: /* @__PURE__ */ jsx(ToastClose, { ...actionProps, ref: forwardedRef }) });
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
ToastAction.propTypes = {
|
|
85
|
+
altText(props) {
|
|
86
|
+
if (!props.altText) {
|
|
87
|
+
return new Error(`Missing prop \`altText\` expected on \`${ACTION_NAME}\``);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
ToastAction.displayName = ACTION_NAME;
|
|
93
|
+
const CLOSE_NAME = "ToastClose";
|
|
94
|
+
const ToastCloseFrame = styled(ThemeableStack, {
|
|
95
|
+
name: CLOSE_NAME,
|
|
96
|
+
tag: "button"
|
|
97
|
+
});
|
|
98
|
+
const ToastClose = React.forwardRef(
|
|
99
|
+
(props, forwardedRef) => {
|
|
100
|
+
const { __scopeToast, ...closeProps } = props;
|
|
101
|
+
const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast);
|
|
102
|
+
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
103
|
+
ToastCloseFrame,
|
|
104
|
+
{
|
|
105
|
+
accessibilityLabel: "Dialog Close",
|
|
106
|
+
...closeProps,
|
|
107
|
+
ref: forwardedRef,
|
|
108
|
+
onPress: composeEventHandlers(props.onPress, interactiveContext.onClose)
|
|
109
|
+
}
|
|
110
|
+
) });
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
ToastClose.displayName = CLOSE_NAME;
|
|
114
|
+
const ToastComponent = React.forwardRef(
|
|
115
|
+
ToastImplFrame.extractable((props, forwardedRef) => {
|
|
116
|
+
const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props;
|
|
117
|
+
const [open, setOpen] = useControllableState({
|
|
118
|
+
prop: openProp,
|
|
119
|
+
defaultProp: defaultOpen ?? true,
|
|
120
|
+
onChange: onOpenChange
|
|
121
|
+
});
|
|
122
|
+
const id = useId();
|
|
123
|
+
const onPause = useEvent(props.onPause);
|
|
124
|
+
const onResume = useEvent(props.onResume);
|
|
125
|
+
const shouldShow = forceMount || open;
|
|
126
|
+
if (!shouldShow)
|
|
127
|
+
return null;
|
|
128
|
+
return /* @__PURE__ */ jsx(
|
|
129
|
+
ToastImpl,
|
|
130
|
+
{
|
|
131
|
+
id,
|
|
132
|
+
open,
|
|
133
|
+
...toastProps,
|
|
134
|
+
ref: forwardedRef,
|
|
135
|
+
onClose: () => setOpen(false),
|
|
136
|
+
onPause,
|
|
137
|
+
onResume,
|
|
138
|
+
onSwipeEnd: composeEventHandlers(props.onSwipeEnd, (event) => {
|
|
139
|
+
setOpen(false);
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
ToastComponent.displayName = TOAST_NAME;
|
|
146
|
+
const Toast = withStaticProperties(
|
|
147
|
+
themeable(ToastComponent, ToastImplFrame.staticConfig),
|
|
148
|
+
{
|
|
149
|
+
Title: ToastTitle,
|
|
150
|
+
Description: ToastDescription,
|
|
151
|
+
Action: ToastAction,
|
|
152
|
+
Close: ToastClose
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
export {
|
|
156
|
+
Toast,
|
|
157
|
+
ToastProvider,
|
|
158
|
+
ToastViewport,
|
|
159
|
+
createToastScope,
|
|
160
|
+
useToast,
|
|
161
|
+
useToastController,
|
|
162
|
+
useToastState
|
|
163
|
+
};
|
|
2
164
|
//# sourceMappingURL=Toast.js.map
|
package/dist/esm/Toast.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Toast.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\n useId,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText } from '@tamagui/text'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounceExclude } from './ToastAnnounce'\nimport {\n ToastNativePlatform,\n ToastNativeValue,\n useToast,\n useToastController,\n useToastState,\n} from './ToastImperative.js'\nimport {\n ToastImpl,\n ToastImplFrame,\n ToastProps,\n useToastInteractiveContext,\n} from './ToastImpl'\nimport {\n ScopedProps,\n ToastProvider,\n ToastProviderProps,\n createToastScope,\n} from './ToastProvider'\nimport { ToastViewport, ToastViewportProps } from './ToastViewport'\n\n/* -------------------------------------------------------------------------------------------------\n * ToastTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'ToastTitle'\n\nconst ToastTitleFrame = styled(SizableText, {\n name: TITLE_NAME,\n variants: {\n unstyled: {\n false: {\n color: '$color',\n size: '$4',\n },\n },\n },\n defaultVariants: {\n unstyled: false,\n },\n})\n\ntype PrimitiveDivProps = GetProps<typeof ToastTitleFrame>\ntype ToastTitleProps = PrimitiveDivProps & {}\n\nconst ToastTitle = React.forwardRef<TamaguiElement, ToastTitleProps>(\n (props: ScopedProps<ToastTitleProps>, forwardedRef) => {\n const { __scopeToast, ...titleProps } = props\n return <ToastTitleFrame {...titleProps} ref={forwardedRef} />\n }\n)\n\nToastTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'ToastDescription'\n\nconst ToastDescriptionFrame = styled(SizableText, {\n name: DESCRIPTION_NAME,\n\n variants: {\n unstyled: {\n false: {\n color: '$color11',\n size: '$1',\n },\n },\n },\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\ntype ToastDescriptionFrameProps = GetProps<typeof ToastDescriptionFrame>\ntype ToastDescriptionProps = ToastDescriptionFrameProps & {}\n\nconst ToastDescription = React.forwardRef<TamaguiElement, ToastDescriptionProps>(\n (props: ScopedProps<ToastDescriptionProps>, forwardedRef) => {\n const { __scopeToast, ...descriptionProps } = props\n return <ToastDescriptionFrame {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nToastDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'ToastAction'\n\ntype ToastActionProps = ToastCloseProps & {\n /**\n * A short description for an alternate way to carry out the action. For screen reader users\n * who will not be able to navigate to the button easily/quickly.\n * @example <ToastAction altText=\"Goto account settings to updgrade\">Upgrade</ToastAction>\n * @example <ToastAction altText=\"Undo (Alt+U)\">Undo</ToastAction>\n */\n altText: string\n}\n\nconst ToastAction = React.forwardRef<TamaguiElement, ToastActionProps>(\n (props: ScopedProps<ToastActionProps>, forwardedRef) => {\n const { altText, ...actionProps } = props\n if (!altText) return null\n return (\n <ToastAnnounceExclude altText={altText} asChild>\n <ToastClose {...actionProps} ref={forwardedRef} />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastAction.propTypes = {\n altText(props) {\n if (!props.altText) {\n return new Error(`Missing prop \\`altText\\` expected on \\`${ACTION_NAME}\\``)\n }\n return null\n },\n}\n\nToastAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'ToastClose'\n\nconst ToastCloseFrame = styled(ThemeableStack, {\n name: CLOSE_NAME,\n tag: 'button',\n})\ntype ToastCloseFrameProps = GetProps<typeof ToastCloseFrame>\ntype ToastCloseProps = ToastCloseFrameProps & {}\n\nconst ToastClose = React.forwardRef<TamaguiElement, ToastCloseProps>(\n (props: ScopedProps<ToastCloseProps>, forwardedRef) => {\n const { __scopeToast, ...closeProps } = props\n const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast)\n\n return (\n <ToastAnnounceExclude asChild>\n <ToastCloseFrame\n accessibilityLabel=\"Dialog Close\"\n {...closeProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, interactiveContext.onClose)}\n />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastClose.displayName = CLOSE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Toast\n * -----------------------------------------------------------------------------------------------*/\n\nconst ToastComponent = React.forwardRef<TamaguiElement, ToastProps>(\n ToastImplFrame.extractable((props: ScopedProps<ToastProps>, forwardedRef) => {\n const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? true,\n onChange: onOpenChange,\n })\n\n const id = useId()\n const onPause = useEvent(props.onPause)\n const onResume = useEvent(props.onResume)\n const shouldShow = forceMount || open\n\n if (!shouldShow) return null\n\n return (\n <ToastImpl\n id={id}\n open={open}\n {...toastProps}\n ref={forwardedRef}\n onClose={() => setOpen(false)}\n onPause={onPause}\n onResume={onResume}\n onSwipeEnd={composeEventHandlers(props.onSwipeEnd, (event) => {\n setOpen(false)\n })}\n />\n )\n })\n)\n\nToastComponent.displayName = TOAST_NAME\n\nconst Toast = withStaticProperties(\n themeable(ToastComponent, ToastImplFrame.staticConfig),\n {\n Title: ToastTitle,\n Description: ToastDescription,\n Action: ToastAction,\n Close: ToastClose,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\nexport {\n Toast,\n ToastProvider,\n ToastViewport,\n //\n createToastScope,\n // imperative\n useToast,\n useToastController,\n useToastState,\n}\nexport type {\n ToastActionProps,\n ToastCloseProps,\n ToastDescriptionProps,\n ToastProps,\n ToastProviderProps,\n ToastTitleProps,\n ToastViewportProps,\n // imperative\n ToastNativeValue,\n ToastNativePlatform,\n}\n"],
|
|
5
|
-
"mappings": "AAiEW,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAiEW;AAjEX;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,YAAY,WAAW;AAEvB,SAAS,kBAAkB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K;AAAA,QACL,SAAS,MAAM,QAAQ,KAAK;AAAA,QAC5B;AAAA,QACA;AAAA,QACA,YAAY,qBAAqB,MAAM,YAAY,CAAC,UAAU;AAC5D,kBAAQ,KAAK;AAAA,QACf,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ,CAAC;AACH;AAEA,eAAe,cAAc;AAE7B,MAAM,QAAQ;AAAA,EACZ,UAAU,gBAAgB,eAAe,YAAY;AAAA,EACrD;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/esm/Toast.mjs
CHANGED
|
@@ -1,2 +1,164 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
composeEventHandlers,
|
|
4
|
+
styled,
|
|
5
|
+
themeable,
|
|
6
|
+
useEvent,
|
|
7
|
+
useId,
|
|
8
|
+
withStaticProperties
|
|
9
|
+
} from "@tamagui/core";
|
|
10
|
+
import { ThemeableStack } from "@tamagui/stacks";
|
|
11
|
+
import { SizableText } from "@tamagui/text";
|
|
12
|
+
import { useControllableState } from "@tamagui/use-controllable-state";
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { TOAST_NAME } from "./constants";
|
|
15
|
+
import { ToastAnnounceExclude } from "./ToastAnnounce";
|
|
16
|
+
import {
|
|
17
|
+
useToast,
|
|
18
|
+
useToastController,
|
|
19
|
+
useToastState
|
|
20
|
+
} from "./ToastImperative.js";
|
|
21
|
+
import {
|
|
22
|
+
ToastImpl,
|
|
23
|
+
ToastImplFrame,
|
|
24
|
+
useToastInteractiveContext
|
|
25
|
+
} from "./ToastImpl";
|
|
26
|
+
import {
|
|
27
|
+
ToastProvider,
|
|
28
|
+
createToastScope
|
|
29
|
+
} from "./ToastProvider";
|
|
30
|
+
import { ToastViewport } from "./ToastViewport";
|
|
31
|
+
const TITLE_NAME = "ToastTitle";
|
|
32
|
+
const ToastTitleFrame = styled(SizableText, {
|
|
33
|
+
name: TITLE_NAME,
|
|
34
|
+
variants: {
|
|
35
|
+
unstyled: {
|
|
36
|
+
false: {
|
|
37
|
+
color: "$color",
|
|
38
|
+
size: "$4"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
defaultVariants: {
|
|
43
|
+
unstyled: false
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const ToastTitle = React.forwardRef(
|
|
47
|
+
(props, forwardedRef) => {
|
|
48
|
+
const { __scopeToast, ...titleProps } = props;
|
|
49
|
+
return /* @__PURE__ */ jsx(ToastTitleFrame, { ...titleProps, ref: forwardedRef });
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
ToastTitle.displayName = TITLE_NAME;
|
|
53
|
+
const DESCRIPTION_NAME = "ToastDescription";
|
|
54
|
+
const ToastDescriptionFrame = styled(SizableText, {
|
|
55
|
+
name: DESCRIPTION_NAME,
|
|
56
|
+
variants: {
|
|
57
|
+
unstyled: {
|
|
58
|
+
false: {
|
|
59
|
+
color: "$color11",
|
|
60
|
+
size: "$1"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
defaultVariants: {
|
|
65
|
+
unstyled: false
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const ToastDescription = React.forwardRef(
|
|
69
|
+
(props, forwardedRef) => {
|
|
70
|
+
const { __scopeToast, ...descriptionProps } = props;
|
|
71
|
+
return /* @__PURE__ */ jsx(ToastDescriptionFrame, { ...descriptionProps, ref: forwardedRef });
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
ToastDescription.displayName = DESCRIPTION_NAME;
|
|
75
|
+
const ACTION_NAME = "ToastAction";
|
|
76
|
+
const ToastAction = React.forwardRef(
|
|
77
|
+
(props, forwardedRef) => {
|
|
78
|
+
const { altText, ...actionProps } = props;
|
|
79
|
+
if (!altText)
|
|
80
|
+
return null;
|
|
81
|
+
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { altText, asChild: true, children: /* @__PURE__ */ jsx(ToastClose, { ...actionProps, ref: forwardedRef }) });
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
ToastAction.propTypes = {
|
|
85
|
+
altText(props) {
|
|
86
|
+
if (!props.altText) {
|
|
87
|
+
return new Error(`Missing prop \`altText\` expected on \`${ACTION_NAME}\``);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
ToastAction.displayName = ACTION_NAME;
|
|
93
|
+
const CLOSE_NAME = "ToastClose";
|
|
94
|
+
const ToastCloseFrame = styled(ThemeableStack, {
|
|
95
|
+
name: CLOSE_NAME,
|
|
96
|
+
tag: "button"
|
|
97
|
+
});
|
|
98
|
+
const ToastClose = React.forwardRef(
|
|
99
|
+
(props, forwardedRef) => {
|
|
100
|
+
const { __scopeToast, ...closeProps } = props;
|
|
101
|
+
const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast);
|
|
102
|
+
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
103
|
+
ToastCloseFrame,
|
|
104
|
+
{
|
|
105
|
+
accessibilityLabel: "Dialog Close",
|
|
106
|
+
...closeProps,
|
|
107
|
+
ref: forwardedRef,
|
|
108
|
+
onPress: composeEventHandlers(props.onPress, interactiveContext.onClose)
|
|
109
|
+
}
|
|
110
|
+
) });
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
ToastClose.displayName = CLOSE_NAME;
|
|
114
|
+
const ToastComponent = React.forwardRef(
|
|
115
|
+
ToastImplFrame.extractable((props, forwardedRef) => {
|
|
116
|
+
const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props;
|
|
117
|
+
const [open, setOpen] = useControllableState({
|
|
118
|
+
prop: openProp,
|
|
119
|
+
defaultProp: defaultOpen ?? true,
|
|
120
|
+
onChange: onOpenChange
|
|
121
|
+
});
|
|
122
|
+
const id = useId();
|
|
123
|
+
const onPause = useEvent(props.onPause);
|
|
124
|
+
const onResume = useEvent(props.onResume);
|
|
125
|
+
const shouldShow = forceMount || open;
|
|
126
|
+
if (!shouldShow)
|
|
127
|
+
return null;
|
|
128
|
+
return /* @__PURE__ */ jsx(
|
|
129
|
+
ToastImpl,
|
|
130
|
+
{
|
|
131
|
+
id,
|
|
132
|
+
open,
|
|
133
|
+
...toastProps,
|
|
134
|
+
ref: forwardedRef,
|
|
135
|
+
onClose: () => setOpen(false),
|
|
136
|
+
onPause,
|
|
137
|
+
onResume,
|
|
138
|
+
onSwipeEnd: composeEventHandlers(props.onSwipeEnd, (event) => {
|
|
139
|
+
setOpen(false);
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
ToastComponent.displayName = TOAST_NAME;
|
|
146
|
+
const Toast = withStaticProperties(
|
|
147
|
+
themeable(ToastComponent, ToastImplFrame.staticConfig),
|
|
148
|
+
{
|
|
149
|
+
Title: ToastTitle,
|
|
150
|
+
Description: ToastDescription,
|
|
151
|
+
Action: ToastAction,
|
|
152
|
+
Close: ToastClose
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
export {
|
|
156
|
+
Toast,
|
|
157
|
+
ToastProvider,
|
|
158
|
+
ToastViewport,
|
|
159
|
+
createToastScope,
|
|
160
|
+
useToast,
|
|
161
|
+
useToastController,
|
|
162
|
+
useToastState
|
|
163
|
+
};
|
|
2
164
|
//# sourceMappingURL=Toast.mjs.map
|
package/dist/esm/Toast.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Toast.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\n useId,\n withStaticProperties,\n} from '@tamagui/core'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport { SizableText } from '@tamagui/text'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport * as React from 'react'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounceExclude } from './ToastAnnounce'\nimport {\n ToastNativePlatform,\n ToastNativeValue,\n useToast,\n useToastController,\n useToastState,\n} from './ToastImperative.js'\nimport {\n ToastImpl,\n ToastImplFrame,\n ToastProps,\n useToastInteractiveContext,\n} from './ToastImpl'\nimport {\n ScopedProps,\n ToastProvider,\n ToastProviderProps,\n createToastScope,\n} from './ToastProvider'\nimport { ToastViewport, ToastViewportProps } from './ToastViewport'\n\n/* -------------------------------------------------------------------------------------------------\n * ToastTitle\n * -----------------------------------------------------------------------------------------------*/\n\nconst TITLE_NAME = 'ToastTitle'\n\nconst ToastTitleFrame = styled(SizableText, {\n name: TITLE_NAME,\n variants: {\n unstyled: {\n false: {\n color: '$color',\n size: '$4',\n },\n },\n },\n defaultVariants: {\n unstyled: false,\n },\n})\n\ntype PrimitiveDivProps = GetProps<typeof ToastTitleFrame>\ntype ToastTitleProps = PrimitiveDivProps & {}\n\nconst ToastTitle = React.forwardRef<TamaguiElement, ToastTitleProps>(\n (props: ScopedProps<ToastTitleProps>, forwardedRef) => {\n const { __scopeToast, ...titleProps } = props\n return <ToastTitleFrame {...titleProps} ref={forwardedRef} />\n }\n)\n\nToastTitle.displayName = TITLE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastDescription\n * -----------------------------------------------------------------------------------------------*/\n\nconst DESCRIPTION_NAME = 'ToastDescription'\n\nconst ToastDescriptionFrame = styled(SizableText, {\n name: DESCRIPTION_NAME,\n\n variants: {\n unstyled: {\n false: {\n color: '$color11',\n size: '$1',\n },\n },\n },\n\n defaultVariants: {\n unstyled: false,\n },\n})\n\ntype ToastDescriptionFrameProps = GetProps<typeof ToastDescriptionFrame>\ntype ToastDescriptionProps = ToastDescriptionFrameProps & {}\n\nconst ToastDescription = React.forwardRef<TamaguiElement, ToastDescriptionProps>(\n (props: ScopedProps<ToastDescriptionProps>, forwardedRef) => {\n const { __scopeToast, ...descriptionProps } = props\n return <ToastDescriptionFrame {...descriptionProps} ref={forwardedRef} />\n }\n)\n\nToastDescription.displayName = DESCRIPTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastAction\n * -----------------------------------------------------------------------------------------------*/\n\nconst ACTION_NAME = 'ToastAction'\n\ntype ToastActionProps = ToastCloseProps & {\n /**\n * A short description for an alternate way to carry out the action. For screen reader users\n * who will not be able to navigate to the button easily/quickly.\n * @example <ToastAction altText=\"Goto account settings to updgrade\">Upgrade</ToastAction>\n * @example <ToastAction altText=\"Undo (Alt+U)\">Undo</ToastAction>\n */\n altText: string\n}\n\nconst ToastAction = React.forwardRef<TamaguiElement, ToastActionProps>(\n (props: ScopedProps<ToastActionProps>, forwardedRef) => {\n const { altText, ...actionProps } = props\n if (!altText) return null\n return (\n <ToastAnnounceExclude altText={altText} asChild>\n <ToastClose {...actionProps} ref={forwardedRef} />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastAction.propTypes = {\n altText(props) {\n if (!props.altText) {\n return new Error(`Missing prop \\`altText\\` expected on \\`${ACTION_NAME}\\``)\n }\n return null\n },\n}\n\nToastAction.displayName = ACTION_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * ToastClose\n * -----------------------------------------------------------------------------------------------*/\n\nconst CLOSE_NAME = 'ToastClose'\n\nconst ToastCloseFrame = styled(ThemeableStack, {\n name: CLOSE_NAME,\n tag: 'button',\n})\ntype ToastCloseFrameProps = GetProps<typeof ToastCloseFrame>\ntype ToastCloseProps = ToastCloseFrameProps & {}\n\nconst ToastClose = React.forwardRef<TamaguiElement, ToastCloseProps>(\n (props: ScopedProps<ToastCloseProps>, forwardedRef) => {\n const { __scopeToast, ...closeProps } = props\n const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast)\n\n return (\n <ToastAnnounceExclude asChild>\n <ToastCloseFrame\n accessibilityLabel=\"Dialog Close\"\n {...closeProps}\n ref={forwardedRef}\n onPress={composeEventHandlers(props.onPress as any, interactiveContext.onClose)}\n />\n </ToastAnnounceExclude>\n )\n }\n)\n\nToastClose.displayName = CLOSE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Toast\n * -----------------------------------------------------------------------------------------------*/\n\nconst ToastComponent = React.forwardRef<TamaguiElement, ToastProps>(\n ToastImplFrame.extractable((props: ScopedProps<ToastProps>, forwardedRef) => {\n const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props\n const [open, setOpen] = useControllableState({\n prop: openProp,\n defaultProp: defaultOpen ?? true,\n onChange: onOpenChange,\n })\n\n const id = useId()\n const onPause = useEvent(props.onPause)\n const onResume = useEvent(props.onResume)\n const shouldShow = forceMount || open\n\n if (!shouldShow) return null\n\n return (\n <ToastImpl\n id={id}\n open={open}\n {...toastProps}\n ref={forwardedRef}\n onClose={() => setOpen(false)}\n onPause={onPause}\n onResume={onResume}\n onSwipeEnd={composeEventHandlers(props.onSwipeEnd, (event) => {\n setOpen(false)\n })}\n />\n )\n })\n)\n\nToastComponent.displayName = TOAST_NAME\n\nconst Toast = withStaticProperties(\n themeable(ToastComponent, ToastImplFrame.staticConfig),\n {\n Title: ToastTitle,\n Description: ToastDescription,\n Action: ToastAction,\n Close: ToastClose,\n }\n)\n\n/* ---------------------------------------------------------------------------------------------- */\n\nexport {\n Toast,\n ToastProvider,\n ToastViewport,\n //\n createToastScope,\n // imperative\n useToast,\n useToastController,\n useToastState,\n}\nexport type {\n ToastActionProps,\n ToastCloseProps,\n ToastDescriptionProps,\n ToastProps,\n ToastProviderProps,\n ToastTitleProps,\n ToastViewportProps,\n // imperative\n ToastNativeValue,\n ToastNativePlatform,\n}\n"],
|
|
5
|
-
"mappings": "AAiEW,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAiEW;AAjEX;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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Ac;AAEjC,QAAI,CAAC;AAAY,aAAO;AAExB,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACC,GAAG;AAAA,QACJ,KAAK;AAAA,QACL,SAAS,MAAM,QAAQ,KAAK;AAAA,QAC5B;AAAA,QACA;AAAA,QACA,YAAY,qBAAqB,MAAM,YAAY,CAAC,UAAU;AAC5D,kBAAQ,KAAK;AAAA,QACf,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ,CAAC;AACH;AAEA,eAAe,cAAc;AAE7B,MAAM,QAAQ;AAAA,EACZ,UAAU,gBAAgB,eAAe,YAAY;AAAA,EACrD;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,64 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Stack,
|
|
4
|
+
Text,
|
|
5
|
+
styled,
|
|
6
|
+
useEvent,
|
|
7
|
+
useIsomorphicLayoutEffect
|
|
8
|
+
} from "@tamagui/core";
|
|
9
|
+
import { Portal } from "@tamagui/portal";
|
|
10
|
+
import { VisuallyHidden } from "@tamagui/visually-hidden";
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
import { useToastProviderContext } from "./ToastProvider";
|
|
13
|
+
import { TOAST_NAME } from "./constants";
|
|
14
|
+
const ToastAnnounceExcludeFrame = styled(Stack, {
|
|
15
|
+
name: "ToastAnnounceExclude"
|
|
16
|
+
});
|
|
17
|
+
const ToastAnnounceExclude = React.forwardRef(
|
|
18
|
+
(props, forwardedRef) => {
|
|
19
|
+
const { __scopeToast, altText, ...announceExcludeProps } = props;
|
|
20
|
+
return /* @__PURE__ */ jsx(
|
|
21
|
+
ToastAnnounceExcludeFrame,
|
|
22
|
+
{
|
|
23
|
+
"data-toast-announce-exclude": "",
|
|
24
|
+
"data-toast-announce-alt": altText || void 0,
|
|
25
|
+
...announceExcludeProps,
|
|
26
|
+
ref: forwardedRef
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
const ToastAnnounce = (props) => {
|
|
32
|
+
const { __scopeToast, children, ...announceProps } = props;
|
|
33
|
+
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
|
|
34
|
+
const [renderAnnounceText, setRenderAnnounceText] = React.useState(false);
|
|
35
|
+
const [isAnnounced, setIsAnnounced] = React.useState(false);
|
|
36
|
+
useNextFrame(() => setRenderAnnounceText(true));
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
const timer = setTimeout(() => setIsAnnounced(true), 1e3);
|
|
39
|
+
return () => clearTimeout(timer);
|
|
40
|
+
}, []);
|
|
41
|
+
return isAnnounced ? null : /* @__PURE__ */ jsx(Portal, { asChild: true, children: /* @__PURE__ */ jsx(VisuallyHidden, { ...announceProps, children: renderAnnounceText && /* @__PURE__ */ jsxs(Text, { children: [
|
|
42
|
+
context.label,
|
|
43
|
+
" ",
|
|
44
|
+
children
|
|
45
|
+
] }) }) });
|
|
46
|
+
};
|
|
47
|
+
function useNextFrame(callback = () => {
|
|
48
|
+
}) {
|
|
49
|
+
const fn = useEvent(callback);
|
|
50
|
+
useIsomorphicLayoutEffect(() => {
|
|
51
|
+
let raf1 = 0;
|
|
52
|
+
let raf2 = 0;
|
|
53
|
+
raf1 = requestAnimationFrame(() => raf2 = requestAnimationFrame(fn));
|
|
54
|
+
return () => {
|
|
55
|
+
cancelAnimationFrame(raf1);
|
|
56
|
+
cancelAnimationFrame(raf2);
|
|
57
|
+
};
|
|
58
|
+
}, [fn]);
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
ToastAnnounce,
|
|
62
|
+
ToastAnnounceExclude
|
|
63
|
+
};
|
|
2
64
|
//# sourceMappingURL=ToastAnnounce.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ToastAnnounce.tsx"],
|
|
4
4
|
"sourcesContent": ["import {\n GetProps,\n Stack,\n TamaguiElement,\n Text,\n styled,\n useEvent,\n useIsomorphicLayoutEffect,\n} from '@tamagui/core'\nimport { Portal } from '@tamagui/portal'\nimport { VisuallyHidden } from '@tamagui/visually-hidden'\nimport * as React from 'react'\n\nimport { ScopedProps, useToastProviderContext } from './ToastProvider'\nimport { TOAST_NAME } from './constants'\n\nconst ToastAnnounceExcludeFrame = styled(Stack, {\n name: 'ToastAnnounceExclude',\n})\ntype ToastAnnounceExcludeFrameProps = GetProps<typeof ToastAnnounceExcludeFrame>\ntype ToastAnnounceExcludeProps = ToastAnnounceExcludeFrameProps & {\n altText?: string\n}\n\nconst ToastAnnounceExclude = React.forwardRef<TamaguiElement, ToastAnnounceExcludeProps>(\n (props: ScopedProps<ToastAnnounceExcludeProps>, forwardedRef) => {\n const { __scopeToast, altText, ...announceExcludeProps } = props\n\n return (\n <ToastAnnounceExcludeFrame\n data-toast-announce-exclude=\"\"\n data-toast-announce-alt={altText || undefined}\n {...announceExcludeProps}\n ref={forwardedRef}\n />\n )\n }\n)\n\n/* -----------------------------------------------------------------------------------------------*/\n\ninterface ToastAnnounceProps\n extends Omit<GetProps<typeof VisuallyHidden>, 'children'>,\n ScopedProps<{ children: string[] }> {}\n\nconst ToastAnnounce: React.FC<ToastAnnounceProps> = (\n props: ScopedProps<ToastAnnounceProps>\n) => {\n const { __scopeToast, children, ...announceProps } = props\n const context = useToastProviderContext(TOAST_NAME, __scopeToast)\n const [renderAnnounceText, setRenderAnnounceText] = React.useState(false)\n const [isAnnounced, setIsAnnounced] = React.useState(false)\n\n // render text content in the next frame to ensure toast is announced in NVDA\n useNextFrame(() => setRenderAnnounceText(true))\n\n // cleanup after announcing\n React.useEffect(() => {\n const timer = setTimeout(() => setIsAnnounced(true), 1000)\n return () => clearTimeout(timer)\n }, [])\n\n return isAnnounced ? null : (\n <Portal asChild>\n <VisuallyHidden {...announceProps}>\n {renderAnnounceText && (\n <Text>\n {context.label} {children}\n </Text>\n )}\n </VisuallyHidden>\n </Portal>\n )\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction useNextFrame(callback = () => {}) {\n const fn = useEvent(callback)\n useIsomorphicLayoutEffect(() => {\n let raf1 = 0\n let raf2 = 0\n raf1 = requestAnimationFrame(() => (raf2 = requestAnimationFrame(fn)))\n return () => {\n cancelAnimationFrame(raf1)\n cancelAnimationFrame(raf2)\n }\n }, [fn])\n}\n\n\nexport {\n ToastAnnounce,\n ToastAnnounceProps,\n ToastAnnounceExclude,\n ToastAnnounceExcludeProps,\n}\n"],
|
|
5
|
-
"mappings": "AA6BM,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AA6BM,cAqCI,YArCJ;AA7BN;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAC/B,YAAY,WAAW;AAEvB,SAAsB,+BAA+B;AACrD,SAAS,kBAAkB;AAE3B,MAAM,4BAA4B,OAAO,OAAO;AAAA,EAC9C,MAAM;AACR,CAAC;AAMD,MAAM,uBAAuB,MAAM;AAAA,EACjC,CAAC,OAA+C,iBAAiB;AAC/D,UAAM,EAAE,cAAc,SAAS,GAAG,qBAAqB,IAAI;AAE3D,WACE;AAAA,MAAC;AAAA;AAAA,QACC,+BAA4B;AAAA,QAC5B,2BAAyB,WAAW;AAAA,QACnC,GAAG;AAAA,QACJ,KAAK;AAAA;AAAA,IACP;AAAA,EAEJ;AACF;AAQA,MAAM,gBAA8C,CAClD,UACG;AACH,QAAM,EAAE,cAAc,UAAU,GAAG,cAAc,IAAI;AACrD,QAAM,UAAU,wBAAwB,YAAY,YAAY;AAChE,QAAM,CAAC,oBAAoB,qBAAqB,IAAI,MAAM,SAAS,KAAK;AACxE,QAAM,CAAC,aAAa,cAAc,IAAI,MAAM,SAAS,KAAK;AAG1D,eAAa,MAAM,sBAAsB,IAAI,CAAC;AAG9C,QAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,WAAW,MAAM,eAAe,IAAI,GAAG,GAAI;AACzD,WAAO,MAAM,aAAa,KAAK;AAAA,EACjC,GAAG,CAAC,CAAC;AAEL,SAAO,cAAc,OACnB,oBAAC,UAAO,SAAO,MACb,8BAAC,kBAAgB,GAAG,eACjB,gCACC,qBAAC,QACE;AAAA,YAAQ;AAAA,IAAM;AAAA,IAAE;AAAA,KACnB,GAEJ,GACF;AAEJ;AAIA,SAAS,aAAa,WAAW,MAAM;AAAC,GAAG;AACzC,QAAM,KAAK,SAAS,QAAQ;AAC5B,4BAA0B,MAAM;AAC9B,QAAI,OAAO;AACX,QAAI,OAAO;AACX,WAAO,sBAAsB,MAAO,OAAO,sBAAsB,EAAE,CAAE;AACrE,WAAO,MAAM;AACX,2BAAqB,IAAI;AACzB,2BAAqB,IAAI;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,EAAE,CAAC;AACT;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,64 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
Stack,
|
|
4
|
+
Text,
|
|
5
|
+
styled,
|
|
6
|
+
useEvent,
|
|
7
|
+
useIsomorphicLayoutEffect
|
|
8
|
+
} from "@tamagui/core";
|
|
9
|
+
import { Portal } from "@tamagui/portal";
|
|
10
|
+
import { VisuallyHidden } from "@tamagui/visually-hidden";
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
import { useToastProviderContext } from "./ToastProvider";
|
|
13
|
+
import { TOAST_NAME } from "./constants";
|
|
14
|
+
const ToastAnnounceExcludeFrame = styled(Stack, {
|
|
15
|
+
name: "ToastAnnounceExclude"
|
|
16
|
+
});
|
|
17
|
+
const ToastAnnounceExclude = React.forwardRef(
|
|
18
|
+
(props, forwardedRef) => {
|
|
19
|
+
const { __scopeToast, altText, ...announceExcludeProps } = props;
|
|
20
|
+
return /* @__PURE__ */ jsx(
|
|
21
|
+
ToastAnnounceExcludeFrame,
|
|
22
|
+
{
|
|
23
|
+
"data-toast-announce-exclude": "",
|
|
24
|
+
"data-toast-announce-alt": altText || void 0,
|
|
25
|
+
...announceExcludeProps,
|
|
26
|
+
ref: forwardedRef
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
const ToastAnnounce = (props) => {
|
|
32
|
+
const { __scopeToast, children, ...announceProps } = props;
|
|
33
|
+
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
|
|
34
|
+
const [renderAnnounceText, setRenderAnnounceText] = React.useState(false);
|
|
35
|
+
const [isAnnounced, setIsAnnounced] = React.useState(false);
|
|
36
|
+
useNextFrame(() => setRenderAnnounceText(true));
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
const timer = setTimeout(() => setIsAnnounced(true), 1e3);
|
|
39
|
+
return () => clearTimeout(timer);
|
|
40
|
+
}, []);
|
|
41
|
+
return isAnnounced ? null : /* @__PURE__ */ jsx(Portal, { asChild: true, children: /* @__PURE__ */ jsx(VisuallyHidden, { ...announceProps, children: renderAnnounceText && /* @__PURE__ */ jsxs(Text, { children: [
|
|
42
|
+
context.label,
|
|
43
|
+
" ",
|
|
44
|
+
children
|
|
45
|
+
] }) }) });
|
|
46
|
+
};
|
|
47
|
+
function useNextFrame(callback = () => {
|
|
48
|
+
}) {
|
|
49
|
+
const fn = useEvent(callback);
|
|
50
|
+
useIsomorphicLayoutEffect(() => {
|
|
51
|
+
let raf1 = 0;
|
|
52
|
+
let raf2 = 0;
|
|
53
|
+
raf1 = requestAnimationFrame(() => raf2 = requestAnimationFrame(fn));
|
|
54
|
+
return () => {
|
|
55
|
+
cancelAnimationFrame(raf1);
|
|
56
|
+
cancelAnimationFrame(raf2);
|
|
57
|
+
};
|
|
58
|
+
}, [fn]);
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
ToastAnnounce,
|
|
62
|
+
ToastAnnounceExclude
|
|
63
|
+
};
|
|
2
64
|
//# sourceMappingURL=ToastAnnounce.mjs.map
|