@tamagui/toast 1.15.4 → 1.15.6
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.map +1 -1
- package/dist/cjs/ToastImperative.js +1 -2
- package/dist/cjs/ToastImperative.js.map +2 -2
- package/dist/cjs/ToastImpl.js +8 -12
- package/dist/cjs/ToastImpl.js.map +2 -2
- package/dist/cjs/ToastProvider.js +9 -3
- package/dist/cjs/ToastProvider.js.map +2 -2
- package/dist/cjs/ToastViewport.js +44 -21
- package/dist/cjs/ToastViewport.js.map +2 -2
- package/dist/esm/Toast.js.map +1 -1
- package/dist/esm/Toast.mjs.map +1 -1
- package/dist/esm/ToastImperative.js +1 -2
- package/dist/esm/ToastImperative.js.map +2 -2
- package/dist/esm/ToastImperative.mjs +1 -2
- package/dist/esm/ToastImperative.mjs.map +2 -2
- package/dist/esm/ToastImpl.js +8 -12
- package/dist/esm/ToastImpl.js.map +2 -2
- package/dist/esm/ToastImpl.mjs +8 -12
- package/dist/esm/ToastImpl.mjs.map +2 -2
- package/dist/esm/ToastProvider.js +9 -3
- package/dist/esm/ToastProvider.js.map +2 -2
- package/dist/esm/ToastProvider.mjs +9 -3
- package/dist/esm/ToastProvider.mjs.map +2 -2
- package/dist/esm/ToastViewport.js +44 -21
- package/dist/esm/ToastViewport.js.map +2 -2
- package/dist/esm/ToastViewport.mjs +44 -21
- package/dist/esm/ToastViewport.mjs.map +2 -2
- package/dist/jsx/Toast.js.map +1 -1
- package/dist/jsx/Toast.mjs.map +1 -1
- package/dist/jsx/ToastImperative.js +1 -2
- package/dist/jsx/ToastImperative.js.map +2 -2
- package/dist/jsx/ToastImperative.mjs +1 -2
- package/dist/jsx/ToastImperative.mjs.map +2 -2
- package/dist/jsx/ToastImpl.js +8 -11
- package/dist/jsx/ToastImpl.js.map +2 -2
- package/dist/jsx/ToastImpl.mjs +8 -11
- package/dist/jsx/ToastImpl.mjs.map +2 -2
- package/dist/jsx/ToastProvider.js +9 -3
- package/dist/jsx/ToastProvider.js.map +2 -2
- package/dist/jsx/ToastProvider.mjs +9 -3
- package/dist/jsx/ToastProvider.mjs.map +2 -2
- package/dist/jsx/ToastViewport.js +44 -20
- package/dist/jsx/ToastViewport.js.map +2 -2
- package/dist/jsx/ToastViewport.mjs +44 -20
- package/dist/jsx/ToastViewport.mjs.map +2 -2
- package/package.json +13 -13
- package/src/Toast.tsx +2 -2
- package/src/ToastImperative.tsx +11 -3
- package/src/ToastImpl.tsx +21 -21
- package/src/ToastProvider.tsx +14 -5
- package/src/ToastViewport.tsx +51 -21
- package/types/Toast.d.ts +38 -66
- package/types/Toast.d.ts.map +1 -1
- package/types/ToastAnnounce.d.ts +1 -1
- package/types/ToastImperative.d.ts +10 -1
- package/types/ToastImperative.d.ts.map +1 -1
- package/types/ToastImpl.d.ts +13 -20
- package/types/ToastImpl.d.ts.map +1 -1
- package/types/ToastProvider.d.ts +2 -2
- package/types/ToastProvider.d.ts.map +1 -1
- package/types/ToastViewport.d.ts +18 -59
- package/types/ToastViewport.d.ts.map +1 -1
package/dist/esm/Toast.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Toast.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\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 = React.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"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\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 } as const,\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 } as const,\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 = React.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
5
|
"mappings": "AAgEW;AAhEX;AAAA,EAGE;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;AAC3B,SAAS,4BAA4B;AACrC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,qBAAyC;AAMlD,MAAM,aAAa;AAEnB,MAAM,kBAAkB,OAAO,aAAa;AAAA,EAC1C,MAAM;AAAA,EACN,UAAU;AAAA,IACR,UAA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;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Toast.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Toast.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\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 = React.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"],
|
|
4
|
+
"sourcesContent": ["import {\n GetProps,\n TamaguiElement,\n composeEventHandlers,\n styled,\n themeable,\n useEvent,\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 } as const,\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 } as const,\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 = React.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
5
|
"mappings": "AAgEW;AAhEX;AAAA,EAGE;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;AAC3B,SAAS,4BAA4B;AACrC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,qBAAyC;AAMlD,MAAM,aAAa;AAEnB,MAAM,kBAAkB,OAAO,aAAa;AAAA,EAC1C,MAAM;AAAA,EACN,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAKD,MAAM,aAAa,MAAM;AAAA,EACvB,CAAC,OAAqC,iBAAiB;AACrD,UAAM,EAAE,cAAc,GAAG,WAAW,IAAI;AACxC,WAAO,oBAAC,mBAAiB,GAAG,YAAY,KAAK,cAAc;AAAA,EAC7D;AACF;AAEA,WAAW,cAAc;AAMzB,MAAM,mBAAmB;AAEzB,MAAM,wBAAwB,OAAO,aAAa;AAAA,EAChD,MAAM;AAAA,EAEN,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAAA,EAEA,iBAAiB;AAAA,IAC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UAAU,aAAa,cAAc,GAAG,WAAW,IAAI;AACjF,UAAM,CAAC,MAAM,OAAO,IAAI,qBAAqB;AAAA,MAC3C,MAAM;AAAA,MACN,aAAa,eAAe;AAAA,MAC5B,UAAU;AAAA,IACZ,CAAC;AAED,UAAM,KAAK,MAAM,MAAM;AACvB,UAAM,UAAU,SAAS,MAAM,OAAO;AACtC,UAAM,WAAW,SAAS,MAAM,QAAQ;AACxC,UAAM,aAAa,cAAc;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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -42,6 +42,7 @@ const ToastImperativeProvider = ({
|
|
|
42
42
|
setToast({
|
|
43
43
|
title,
|
|
44
44
|
id: counterRef.current.toString(),
|
|
45
|
+
viewportName: (showOptions == null ? void 0 : showOptions.viewportName) ?? "default",
|
|
45
46
|
...showOptions,
|
|
46
47
|
isHandledNatively
|
|
47
48
|
});
|
|
@@ -61,8 +62,6 @@ const ToastImperativeProvider = ({
|
|
|
61
62
|
options
|
|
62
63
|
};
|
|
63
64
|
}, [show, hide, lastNativeToastRef, JSON.stringify(options || null)]);
|
|
64
|
-
const currentContextValue = useMemo(() => {
|
|
65
|
-
}, []);
|
|
66
65
|
return /* @__PURE__ */ jsx(ToastContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(ToastCurrentContext.Provider, { value: toast, children }) });
|
|
67
66
|
};
|
|
68
67
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ToastImperative.tsx"],
|
|
4
|
-
"sourcesContent": ["import { isWeb } from '@tamagui/core'\nimport React, { createContext, useContext, useMemo, useRef } from 'react'\nimport { Platform } from 'react-native'\n\nimport { createNativeToast } from './createNativeToast'\nimport {\n CreateNativeToastOptions,\n NativeToastRef,\n ToastNativePlatform,\n ToastNativeValue,\n} from './types'\n\ninterface ToastImperativeOptions extends Omit<CreateNativeToastOptions, 'message'> {\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?: ToastNativeValue\n}\ninterface ShowOptions extends CreateNativeToastOptions {\n /**\n * Used when need custom data\n */\n additionalInfo?: Record<string, any>\n /**\n * Overrides the native option on `ToastImperativeProvider`\n */\n native?: ToastNativeValue\n}\n\ntype ToastData = { title: string; id: string } &
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/core'\nimport React, { createContext, useContext, useMemo, useRef } from 'react'\nimport { Platform } from 'react-native'\n\nimport { createNativeToast } from './createNativeToast'\nimport {\n CreateNativeToastOptions,\n NativeToastRef,\n ToastNativePlatform,\n ToastNativeValue,\n} from './types'\n\ninterface ToastImperativeOptions extends Omit<CreateNativeToastOptions, 'message'> {\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?: ToastNativeValue\n}\ninterface ShowOptions extends CreateNativeToastOptions {\n /**\n * Used when need custom data\n * @deprecated Use `customData` instead\n */\n additionalInfo?: Record<string, any>\n /**\n * Used when need custom data\n */\n customData?: Record<string, any>\n /**\n * Overrides the native option on `ToastImperativeProvider`\n */\n native?: ToastNativeValue\n /**\n * Which viewport to send this toast to. This is only intended to be used with custom toasts and you should wire it up when creating the toast.\n */\n viewportName?: string | 'default'\n}\n\ntype ToastData = { title: string; id: string } & ShowOptions & {\n isHandledNatively: boolean\n }\n\ninterface ToastContextI {\n nativeToast: NativeToastRef | null\n\n /**\n * Call it to show a new toast. If you're using native toasts, you can pass native options using \\`burntOptions\\` or \\`notificationOptions\\` depending on the native platform (mobile/web).\n */\n show: (title: string, options?: ShowOptions) => boolean\n\n /**\n * Call it to hide the currently displayed toast.\n *\n * _NOTE_: does not work on Android native toasts\n *\n * _NOTE_: hides the last toast on web notification toasts\n */\n hide: () => void\n\n options?: ToastImperativeOptions\n}\n\nconst ToastContext = createContext<ToastContextI>({} as any)\nconst ToastCurrentContext = createContext<ToastData | null>(null)\n\nexport const useToastController = () => {\n return useContext(ToastContext)\n}\n\nexport const useToastState = () => {\n return useContext(ToastCurrentContext)\n}\n\n/** @deprecated use `useToastController` and `useToastState` instead to avoid performance pitfalls */\nexport const useToast = () => {\n return {\n ...useToastController(),\n currentToast: useToastState(),\n }\n}\n\ninterface ToastImperativeProviderProps {\n children: React.ReactNode\n /**\n * Used to provide defaults to imperative API. Options can be overwritten when calling `show()`.\n */\n options: ToastImperativeOptions\n}\n\nexport const ToastImperativeProvider = ({\n children,\n options,\n}: ToastImperativeProviderProps) => {\n const counterRef = useRef(0)\n\n const [toast, setToast] = React.useState<ToastData | null>(null)\n\n const [lastNativeToastRef, setLastNativeToastRef] =\n React.useState<ToastContextI['nativeToast']>(null)\n\n const show = React.useCallback<ToastContextI['show']>(\n (title, showOptions) => {\n const native = showOptions?.native ?? options.native\n const isWebNative = Array.isArray(native)\n ? native.includes('web')\n : native === 'web'\n const isMobileNative = Array.isArray(native)\n ? native.includes('mobile')\n : native === 'mobile'\n const isAndroidNative =\n isMobileNative ||\n (Array.isArray(native) ? native.includes('android') : native === 'android')\n const isIosNative =\n isMobileNative ||\n (Array.isArray(native) ? native.includes('ios') : native === 'ios')\n\n const isHandledNatively =\n native === true ||\n (isWeb && isWebNative) ||\n (!isWeb && isMobileNative) ||\n (Platform.OS === 'android' && isAndroidNative) ||\n (Platform.OS === 'ios' && isIosNative)\n\n if (isHandledNatively) {\n const nativeToastResult = createNativeToast(title, showOptions ?? {})\n if (typeof nativeToastResult === 'object' && nativeToastResult.nativeToastRef) {\n setLastNativeToastRef(nativeToastResult.nativeToastRef)\n }\n }\n counterRef.current++\n setToast({\n title,\n id: counterRef.current.toString(),\n viewportName: showOptions?.viewportName ?? 'default',\n ...showOptions,\n isHandledNatively,\n })\n return true\n },\n [setToast, options.native]\n )\n const hide = React.useCallback(() => {\n lastNativeToastRef?.close()\n setToast(null)\n }, [setToast, lastNativeToastRef])\n\n const contextValue = useMemo(() => {\n return {\n show,\n hide,\n nativeToast: lastNativeToastRef,\n options,\n }\n }, [show, hide, lastNativeToastRef, JSON.stringify(options || null)])\n\n return (\n <ToastContext.Provider value={contextValue}>\n <ToastCurrentContext.Provider value={toast}>\n {children}\n </ToastCurrentContext.Provider>\n </ToastContext.Provider>\n )\n}\n\nexport type { ToastImperativeProviderProps, ToastNativePlatform, ToastNativeValue }\n"],
|
|
5
|
+
"mappings": "AA6JM;AA7JN,SAAS,aAAa;AACtB,OAAO,SAAS,eAAe,YAAY,SAAS,cAAc;AAClE,SAAS,gBAAgB;AAEzB,SAAS,yBAAyB;AA0DlC,MAAM,eAAe,cAA6B,CAAC,CAAQ;AAC3D,MAAM,sBAAsB,cAAgC,IAAI;AAEzD,MAAM,qBAAqB,MAAM;AACtC,SAAO,WAAW,YAAY;AAChC;AAEO,MAAM,gBAAgB,MAAM;AACjC,SAAO,WAAW,mBAAmB;AACvC;AAGO,MAAM,WAAW,MAAM;AAC5B,SAAO;AAAA,IACL,GAAG,mBAAmB;AAAA,IACtB,cAAc,cAAc;AAAA,EAC9B;AACF;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AEjC,QAAM,eAAe,QAAQ,MAAM;AACjC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,oBAAoB,KAAK,UAAU,WAAW,IAAI,CAAC,CAAC;AAEpE,SACE,oBAAC,aAAa,UAAb,EAAsB,OAAO,cAC5B,8BAAC,oBAAoB,UAApB,EAA6B,OAAO,OAClC,UACH,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -42,6 +42,7 @@ const ToastImperativeProvider = ({
|
|
|
42
42
|
setToast({
|
|
43
43
|
title,
|
|
44
44
|
id: counterRef.current.toString(),
|
|
45
|
+
viewportName: (showOptions == null ? void 0 : showOptions.viewportName) ?? "default",
|
|
45
46
|
...showOptions,
|
|
46
47
|
isHandledNatively
|
|
47
48
|
});
|
|
@@ -61,8 +62,6 @@ const ToastImperativeProvider = ({
|
|
|
61
62
|
options
|
|
62
63
|
};
|
|
63
64
|
}, [show, hide, lastNativeToastRef, JSON.stringify(options || null)]);
|
|
64
|
-
const currentContextValue = useMemo(() => {
|
|
65
|
-
}, []);
|
|
66
65
|
return /* @__PURE__ */ jsx(ToastContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(ToastCurrentContext.Provider, { value: toast, children }) });
|
|
67
66
|
};
|
|
68
67
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ToastImperative.tsx"],
|
|
4
|
-
"sourcesContent": ["import { isWeb } from '@tamagui/core'\nimport React, { createContext, useContext, useMemo, useRef } from 'react'\nimport { Platform } from 'react-native'\n\nimport { createNativeToast } from './createNativeToast'\nimport {\n CreateNativeToastOptions,\n NativeToastRef,\n ToastNativePlatform,\n ToastNativeValue,\n} from './types'\n\ninterface ToastImperativeOptions extends Omit<CreateNativeToastOptions, 'message'> {\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?: ToastNativeValue\n}\ninterface ShowOptions extends CreateNativeToastOptions {\n /**\n * Used when need custom data\n */\n additionalInfo?: Record<string, any>\n /**\n * Overrides the native option on `ToastImperativeProvider`\n */\n native?: ToastNativeValue\n}\n\ntype ToastData = { title: string; id: string } &
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { isWeb } from '@tamagui/core'\nimport React, { createContext, useContext, useMemo, useRef } from 'react'\nimport { Platform } from 'react-native'\n\nimport { createNativeToast } from './createNativeToast'\nimport {\n CreateNativeToastOptions,\n NativeToastRef,\n ToastNativePlatform,\n ToastNativeValue,\n} from './types'\n\ninterface ToastImperativeOptions extends Omit<CreateNativeToastOptions, 'message'> {\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?: ToastNativeValue\n}\ninterface ShowOptions extends CreateNativeToastOptions {\n /**\n * Used when need custom data\n * @deprecated Use `customData` instead\n */\n additionalInfo?: Record<string, any>\n /**\n * Used when need custom data\n */\n customData?: Record<string, any>\n /**\n * Overrides the native option on `ToastImperativeProvider`\n */\n native?: ToastNativeValue\n /**\n * Which viewport to send this toast to. This is only intended to be used with custom toasts and you should wire it up when creating the toast.\n */\n viewportName?: string | 'default'\n}\n\ntype ToastData = { title: string; id: string } & ShowOptions & {\n isHandledNatively: boolean\n }\n\ninterface ToastContextI {\n nativeToast: NativeToastRef | null\n\n /**\n * Call it to show a new toast. If you're using native toasts, you can pass native options using \\`burntOptions\\` or \\`notificationOptions\\` depending on the native platform (mobile/web).\n */\n show: (title: string, options?: ShowOptions) => boolean\n\n /**\n * Call it to hide the currently displayed toast.\n *\n * _NOTE_: does not work on Android native toasts\n *\n * _NOTE_: hides the last toast on web notification toasts\n */\n hide: () => void\n\n options?: ToastImperativeOptions\n}\n\nconst ToastContext = createContext<ToastContextI>({} as any)\nconst ToastCurrentContext = createContext<ToastData | null>(null)\n\nexport const useToastController = () => {\n return useContext(ToastContext)\n}\n\nexport const useToastState = () => {\n return useContext(ToastCurrentContext)\n}\n\n/** @deprecated use `useToastController` and `useToastState` instead to avoid performance pitfalls */\nexport const useToast = () => {\n return {\n ...useToastController(),\n currentToast: useToastState(),\n }\n}\n\ninterface ToastImperativeProviderProps {\n children: React.ReactNode\n /**\n * Used to provide defaults to imperative API. Options can be overwritten when calling `show()`.\n */\n options: ToastImperativeOptions\n}\n\nexport const ToastImperativeProvider = ({\n children,\n options,\n}: ToastImperativeProviderProps) => {\n const counterRef = useRef(0)\n\n const [toast, setToast] = React.useState<ToastData | null>(null)\n\n const [lastNativeToastRef, setLastNativeToastRef] =\n React.useState<ToastContextI['nativeToast']>(null)\n\n const show = React.useCallback<ToastContextI['show']>(\n (title, showOptions) => {\n const native = showOptions?.native ?? options.native\n const isWebNative = Array.isArray(native)\n ? native.includes('web')\n : native === 'web'\n const isMobileNative = Array.isArray(native)\n ? native.includes('mobile')\n : native === 'mobile'\n const isAndroidNative =\n isMobileNative ||\n (Array.isArray(native) ? native.includes('android') : native === 'android')\n const isIosNative =\n isMobileNative ||\n (Array.isArray(native) ? native.includes('ios') : native === 'ios')\n\n const isHandledNatively =\n native === true ||\n (isWeb && isWebNative) ||\n (!isWeb && isMobileNative) ||\n (Platform.OS === 'android' && isAndroidNative) ||\n (Platform.OS === 'ios' && isIosNative)\n\n if (isHandledNatively) {\n const nativeToastResult = createNativeToast(title, showOptions ?? {})\n if (typeof nativeToastResult === 'object' && nativeToastResult.nativeToastRef) {\n setLastNativeToastRef(nativeToastResult.nativeToastRef)\n }\n }\n counterRef.current++\n setToast({\n title,\n id: counterRef.current.toString(),\n viewportName: showOptions?.viewportName ?? 'default',\n ...showOptions,\n isHandledNatively,\n })\n return true\n },\n [setToast, options.native]\n )\n const hide = React.useCallback(() => {\n lastNativeToastRef?.close()\n setToast(null)\n }, [setToast, lastNativeToastRef])\n\n const contextValue = useMemo(() => {\n return {\n show,\n hide,\n nativeToast: lastNativeToastRef,\n options,\n }\n }, [show, hide, lastNativeToastRef, JSON.stringify(options || null)])\n\n return (\n <ToastContext.Provider value={contextValue}>\n <ToastCurrentContext.Provider value={toast}>\n {children}\n </ToastCurrentContext.Provider>\n </ToastContext.Provider>\n )\n}\n\nexport type { ToastImperativeProviderProps, ToastNativePlatform, ToastNativeValue }\n"],
|
|
5
|
+
"mappings": "AA6JM;AA7JN,SAAS,aAAa;AACtB,OAAO,SAAS,eAAe,YAAY,SAAS,cAAc;AAClE,SAAS,gBAAgB;AAEzB,SAAS,yBAAyB;AA0DlC,MAAM,eAAe,cAA6B,CAAC,CAAQ;AAC3D,MAAM,sBAAsB,cAAgC,IAAI;AAEzD,MAAM,qBAAqB,MAAM;AACtC,SAAO,WAAW,YAAY;AAChC;AAEO,MAAM,gBAAgB,MAAM;AACjC,SAAO,WAAW,mBAAmB;AACvC;AAGO,MAAM,WAAW,MAAM;AAC5B,SAAO;AAAA,IACL,GAAG,mBAAmB;AAAA,IACtB,cAAc,cAAc;AAAA,EAC9B;AACF;AAUO,MAAM,0BAA0B,CAAC;AAAA,EACtC;AAAA,EACA;AACF,MAAoC;AAClC,QAAM,aAAa,OAAO,CAAC;AAE3B,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAA2B,IAAI;AAE/D,QAAM,CAAC,oBAAoB,qBAAqB,IAC9C,MAAM,SAAuC,IAAI;AAEnD,QAAM,OAAO,MAAM;AAAA,IACjB,CAAC,OAAO,gBAAgB;AACtB,YAAM,UAAS,2CAAa,WAAU,QAAQ;AAC9C,YAAM,cAAc,MAAM,QAAQ,MAAM,IACpC,OAAO,SAAS,KAAK,IACrB,WAAW;AACf,YAAM,iBAAiB,MAAM,QAAQ,MAAM,IACvC,OAAO,SAAS,QAAQ,IACxB,WAAW;AACf,YAAM,kBACJ,mBACC,MAAM,QAAQ,MAAM,IAAI,OAAO,SAAS,SAAS,IAAI,WAAW;AACnE,YAAM,cACJ,mBACC,MAAM,QAAQ,MAAM,IAAI,OAAO,SAAS,KAAK,IAAI,WAAW;AAE/D,YAAM,oBACJ,WAAW,QACV,SAAS,eACT,CAAC,SAAS,kBACV,SAAS,OAAO,aAAa,mBAC7B,SAAS,OAAO,SAAS;AAE5B,UAAI,mBAAmB;AACrB,cAAM,oBAAoB,kBAAkB,OAAO,eAAe,CAAC,CAAC;AACpE,YAAI,OAAO,sBAAsB,YAAY,kBAAkB,gBAAgB;AAC7E,gCAAsB,kBAAkB,cAAc;AAAA,QACxD;AAAA,MACF;AACA,iBAAW;AACX,eAAS;AAAA,QACP;AAAA,QACA,IAAI,WAAW,QAAQ,SAAS;AAAA,QAChC,eAAc,2CAAa,iBAAgB;AAAA,QAC3C,GAAG;AAAA,QACH;AAAA,MACF,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,UAAU,QAAQ,MAAM;AAAA,EAC3B;AACA,QAAM,OAAO,MAAM,YAAY,MAAM;AACnC,6DAAoB;AACpB,aAAS,IAAI;AAAA,EACf,GAAG,CAAC,UAAU,kBAAkB,CAAC;AAEjC,QAAM,eAAe,QAAQ,MAAM;AACjC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,oBAAoB,KAAK,UAAU,WAAW,IAAI,CAAC,CAAC;AAEpE,SACE,oBAAC,aAAa,UAAb,EAAsB,OAAO,cAC5B,8BAAC,oBAAoB,UAApB,EAA6B,OAAO,OAClC,UACH,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/ToastImpl.js
CHANGED
|
@@ -26,13 +26,10 @@ import { VIEWPORT_PAUSE, VIEWPORT_RESUME } from "./ToastViewport";
|
|
|
26
26
|
const ToastImplFrame = styled(ThemeableStack, {
|
|
27
27
|
name: "ToastImpl",
|
|
28
28
|
variants: {
|
|
29
|
-
backgrounded: {
|
|
30
|
-
true: {
|
|
31
|
-
backgroundColor: "$color6"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
29
|
unstyled: {
|
|
35
30
|
false: {
|
|
31
|
+
focusable: true,
|
|
32
|
+
backgroundColor: "$color6",
|
|
36
33
|
borderRadius: "$10",
|
|
37
34
|
paddingHorizontal: "$5",
|
|
38
35
|
paddingVertical: "$2",
|
|
@@ -42,7 +39,6 @@ const ToastImplFrame = styled(ThemeableStack, {
|
|
|
42
39
|
}
|
|
43
40
|
},
|
|
44
41
|
defaultVariants: {
|
|
45
|
-
backgrounded: true,
|
|
46
42
|
unstyled: false
|
|
47
43
|
}
|
|
48
44
|
});
|
|
@@ -68,7 +64,7 @@ const ToastImpl = React.forwardRef(
|
|
|
68
64
|
onSwipeMove,
|
|
69
65
|
onSwipeCancel,
|
|
70
66
|
onSwipeEnd,
|
|
71
|
-
viewportName,
|
|
67
|
+
viewportName = "default",
|
|
72
68
|
...toastProps
|
|
73
69
|
} = props;
|
|
74
70
|
const isPresent = useIsPresent();
|
|
@@ -80,15 +76,17 @@ const ToastImpl = React.forwardRef(
|
|
|
80
76
|
const closeTimerRemainingTimeRef = React.useRef(duration);
|
|
81
77
|
const closeTimerRef = React.useRef(0);
|
|
82
78
|
const { onToastAdd, onToastRemove } = context;
|
|
79
|
+
const viewport = React.useMemo(() => {
|
|
80
|
+
return context.viewports[viewportName];
|
|
81
|
+
}, [context.viewports, viewportName]);
|
|
83
82
|
const handleClose = useEvent(() => {
|
|
84
|
-
var _a;
|
|
85
83
|
if (!isPresent) {
|
|
86
84
|
return;
|
|
87
85
|
}
|
|
88
86
|
if (isWeb) {
|
|
89
87
|
const isFocusInToast = node == null ? void 0 : node.contains(document.activeElement);
|
|
90
88
|
if (isFocusInToast)
|
|
91
|
-
|
|
89
|
+
viewport == null ? void 0 : viewport.focus();
|
|
92
90
|
}
|
|
93
91
|
onClose();
|
|
94
92
|
});
|
|
@@ -115,7 +113,6 @@ const ToastImpl = React.forwardRef(
|
|
|
115
113
|
React.useEffect(() => {
|
|
116
114
|
if (!isWeb)
|
|
117
115
|
return;
|
|
118
|
-
const viewport = context.viewport;
|
|
119
116
|
if (viewport) {
|
|
120
117
|
viewport.addEventListener(VIEWPORT_PAUSE, handlePause);
|
|
121
118
|
viewport.addEventListener(VIEWPORT_RESUME, handleResume);
|
|
@@ -124,7 +121,7 @@ const ToastImpl = React.forwardRef(
|
|
|
124
121
|
viewport.removeEventListener(VIEWPORT_RESUME, handleResume);
|
|
125
122
|
};
|
|
126
123
|
}
|
|
127
|
-
}, [
|
|
124
|
+
}, [viewport, duration, onPause, onResume, startTimer]);
|
|
128
125
|
React.useEffect(() => {
|
|
129
126
|
if (open && !context.isClosePausedRef.current) {
|
|
130
127
|
startTimer(duration);
|
|
@@ -241,7 +238,6 @@ const ToastImpl = React.forwardRef(
|
|
|
241
238
|
role: "status",
|
|
242
239
|
"aria-live": "off",
|
|
243
240
|
"aria-atomic": true,
|
|
244
|
-
tabIndex: 0,
|
|
245
241
|
"data-state": open ? "open" : "closed",
|
|
246
242
|
"data-swipe-direction": context.swipeDirection,
|
|
247
243
|
pointerEvents: "auto",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ToastImpl.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useIsPresent } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n isWeb,\n styled,\n useAnimationDriver,\n useEvent,\n useThemeName,\n} from '@tamagui/core'\nimport { Dismissable, DismissableProps } from '@tamagui/dismissable'\nimport { PortalItem } from '@tamagui/portal'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { Animated, GestureResponderEvent, PanResponder } from 'react-native'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounce } from './ToastAnnounce'\nimport {\n Collection,\n ScopedProps,\n SwipeDirection,\n createToastContext,\n useToastProviderContext,\n} from './ToastProvider'\nimport { VIEWPORT_PAUSE, VIEWPORT_RESUME } from './ToastViewport'\n\nconst ToastImplFrame = styled(ThemeableStack, {\n name: 'ToastImpl',\n variants: {\n backgrounded: {\n true: {\n backgroundColor: '$color6',\n },\n },\n unstyled: {\n false: {\n borderRadius: '$10',\n paddingHorizontal: '$5',\n paddingVertical: '$2',\n marginHorizontal: 'auto',\n marginVertical: '$1',\n },\n },\n },\n defaultVariants: {\n backgrounded: true,\n unstyled: false,\n },\n})\ninterface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n */\n open?: boolean\n /**\n * The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.\n */\n defaultOpen?: boolean\n /**\n * Event handler called when the open state of the dialog changes.\n */\n onOpenChange?(open: boolean): void\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\ntype SwipeEvent = GestureResponderEvent\n\nconst [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(\n TOAST_NAME,\n {\n onClose() {},\n }\n)\n\ntype ToastImplPrivateProps = { open: boolean; onClose(): void }\ntype ToastImplFrameProps = GetProps<typeof ToastImplFrame>\ntype ToastImplProps = ToastImplPrivateProps &\n ToastImplFrameProps & {\n /**\n * Control the sensitivity of the toast for accessibility purposes.\n * For toasts that are the result of a user action, choose foreground. Toasts generated from background tasks should use background.\n */\n type?: 'foreground' | 'background'\n /**\n * Time in milliseconds that toast should remain visible for. Overrides value given to `ToastProvider`.\n */\n duration?: number\n /**\n * Event handler called when the escape key is down. It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: DismissableProps['onEscapeKeyDown']\n /**\n * Event handler called when the dismiss timer is paused.\n * On web, this occurs when the pointer is moved over the viewport, the viewport is focused or when the window is blurred.\n * On mobile, this occurs when the toast is touched.\n */\n onPause?(): void\n /**\n * Event handler called when the dismiss timer is resumed.\n * On web, this occurs when the pointer is moved away from the viewport, the viewport is blurred or when the window is focused.\n * On mobile, this occurs when the toast is released.\n */\n onResume?(): void\n /**\n * Event handler called when starting a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeStart?(event: SwipeEvent): void\n /**\n * Event handler called during a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeMove?(event: SwipeEvent): void\n /**\n * Event handler called at the cancellation of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeCancel?(event: SwipeEvent): void\n /**\n * Event handler called at the end of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeEnd?(event: SwipeEvent): void\n /**\n * The viewport's name to send the toast to. Used when using multiple viewports and want to forward toasts to different ones.\n *\n * @default \"default\"\n */\n viewportName?: string\n /**\n * \n */\n id?: string\n }\n\nconst ToastImpl = React.forwardRef<TamaguiElement, ToastImplProps>(\n (props: ScopedProps<ToastImplProps>, forwardedRef) => {\n const {\n __scopeToast,\n type = 'foreground',\n duration: durationProp,\n open,\n onClose,\n onEscapeKeyDown,\n onPause,\n onResume,\n onSwipeStart,\n onSwipeMove,\n onSwipeCancel,\n onSwipeEnd,\n viewportName,\n ...toastProps\n } = props\n const isPresent = useIsPresent()\n const context = useToastProviderContext(TOAST_NAME, __scopeToast)\n const [node, setNode] = React.useState<TamaguiElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node))\n const duration = durationProp || context.duration\n const closeTimerStartTimeRef = React.useRef(0)\n const closeTimerRemainingTimeRef = React.useRef(duration)\n const closeTimerRef = React.useRef(0)\n const { onToastAdd, onToastRemove } = context\n const handleClose = useEvent(() => {\n if (!isPresent) {\n // already removed from the react tree\n return\n }\n // focus viewport if focus is within toast to read the remaining toast\n // count to SR users and ensure focus isn't lost\n if (isWeb) {\n const isFocusInToast = (node as HTMLDivElement)?.contains(document.activeElement)\n if (isFocusInToast) context.viewport?.focus()\n }\n onClose()\n })\n\n const startTimer = React.useCallback(\n (duration: number) => {\n if (!duration || duration === Infinity) return\n clearTimeout(closeTimerRef.current)\n closeTimerStartTimeRef.current = new Date().getTime()\n closeTimerRef.current = setTimeout(handleClose, duration) as unknown as number\n },\n [handleClose]\n )\n const handleResume = React.useCallback(() => {\n startTimer(closeTimerRemainingTimeRef.current)\n onResume?.()\n }, [onResume, startTimer])\n const handlePause = React.useCallback(() => {\n const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current\n closeTimerRemainingTimeRef.current =\n closeTimerRemainingTimeRef.current - elapsedTime\n window.clearTimeout(closeTimerRef.current)\n onPause?.()\n }, [onPause])\n\n React.useEffect(() => {\n if (!isWeb) return\n const viewport = context.viewport as HTMLElement\n if (viewport) {\n viewport.addEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.addEventListener(VIEWPORT_RESUME, handleResume)\n return () => {\n viewport.removeEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.removeEventListener(VIEWPORT_RESUME, handleResume)\n }\n }\n }, [context.viewport, duration, onPause, onResume, startTimer])\n\n // start timer when toast opens or duration changes.\n // we include `open` in deps because closed !== unmounted when animating\n // so it could reopen before being completely unmounted\n React.useEffect(() => {\n if (open && !context.isClosePausedRef.current) {\n startTimer(duration)\n }\n }, [open, duration, context.isClosePausedRef, startTimer])\n\n React.useEffect(() => {\n onToastAdd()\n return () => onToastRemove()\n }, [onToastAdd, onToastRemove])\n\n const announceTextContent = React.useMemo(() => {\n if (!isWeb) return null\n return node ? getAnnounceTextContent(node as HTMLDivElement) : null\n }, [node])\n\n const isHorizontalSwipe = ['left', 'right', 'horizontal'].includes(\n context.swipeDirection\n )\n\n const driver = useAnimationDriver()\n if (!driver) {\n throw new Error('Must set animations in tamagui.config.ts')\n }\n\n const { useAnimatedNumber, useAnimatedNumberStyle } = driver\n\n const animatedNumber = useAnimatedNumber(0)\n\n // temp until reanimated useAnimatedNumber fix\n const AnimatedView = (driver['NumberView'] ?? driver.View) as typeof Animated.View\n\n const animatedStyles = useAnimatedNumberStyle(animatedNumber, (val) => {\n return {\n transform: [isHorizontalSwipe ? { translateX: val } : { translateY: val }],\n }\n })\n\n const panResponder = React.useMemo(() => {\n return PanResponder.create({\n onMoveShouldSetPanResponder: (e) => {\n onSwipeStart?.(e)\n return true\n },\n onPanResponderGrant: (e) => {\n if (!isWeb) {\n handlePause?.()\n }\n },\n onPanResponderMove: (e, { dy, dx }) => {\n let y = 0\n let x = 0\n if (context.swipeDirection === 'horizontal') x = dx\n else if (context.swipeDirection === 'left') x = Math.min(0, dx)\n else if (context.swipeDirection === 'right') x = Math.max(0, dx)\n else if (context.swipeDirection === 'vertical') y = dy\n else if (context.swipeDirection === 'up') y = Math.min(0, dy)\n else if (context.swipeDirection === 'down') y = Math.max(0, dy)\n\n onSwipeMove?.(e)\n\n const delta = { x, y }\n animatedNumber.setValue(isHorizontalSwipe ? x : y, { type: 'direct' })\n if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {\n onSwipeEnd?.(e)\n }\n },\n onPanResponderEnd: (e, { dx, dy }) => {\n if (\n !isDeltaInDirection(\n { x: dx, y: dy },\n context.swipeDirection,\n context.swipeThreshold\n )\n ) {\n if (!isWeb) {\n handleResume?.()\n }\n onSwipeCancel?.(e)\n animatedNumber.setValue(0, { type: 'spring' })\n }\n },\n })\n }, [handlePause, handleResume])\n\n // need to get the theme name from context and apply it again since portals don't retain the theme\n const themeName = useThemeName()\n\n return (\n <>\n {announceTextContent && (\n <ToastAnnounce\n __scopeToast={__scopeToast}\n // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.\n role=\"status\"\n aria-live={type === 'foreground' ? 'assertive' : 'polite'}\n aria-atomic\n >\n {announceTextContent}\n </ToastAnnounce>\n )}\n\n <PortalItem hostName={viewportName ?? 'default'}>\n <ToastInteractiveProvider\n key={props.id}\n scope={__scopeToast}\n onClose={() => {\n handleClose()\n }}\n >\n <Dismissable\n // asChild\n onEscapeKeyDown={composeEventHandlers(onEscapeKeyDown, () => {\n if (!context.isFocusedToastEscapeKeyDownRef.current) {\n handleClose()\n }\n context.isFocusedToastEscapeKeyDownRef.current = false\n })}\n >\n <Theme forceClassName name={themeName}>\n <AnimatedView\n {...panResponder?.panHandlers}\n style={[{ margin: 'auto' }, animatedStyles]}\n >\n <Collection.ItemSlot scope={__scopeToast}>\n <ToastImplFrame\n // Ensure toasts are announced as status list or status when focused\n role=\"status\"\n aria-live=\"off\"\n aria-atomic\n tabIndex={0}\n data-state={open ? 'open' : 'closed'}\n data-swipe-direction={context.swipeDirection}\n pointerEvents=\"auto\"\n // touchAction=\"none\"\n userSelect=\"none\"\n {...toastProps}\n ref={composedRefs}\n {...(isWeb && {\n onKeyDown: composeEventHandlers(\n (props as any).onKeyDown,\n (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n onEscapeKeyDown?.(event)\n onEscapeKeyDown?.(event)\n if (!event.defaultPrevented) {\n context.isFocusedToastEscapeKeyDownRef.current = true\n handleClose()\n }\n }\n ),\n })}\n />\n </Collection.ItemSlot>\n </AnimatedView>\n </Theme>\n </Dismissable>\n </ToastInteractiveProvider>\n </PortalItem>\n </>\n )\n }\n)\n\nToastImpl.propTypes = {\n type(props) {\n if (props.type && !['foreground', 'background'].includes(props.type)) {\n const error = `Invalid prop \\`type\\` supplied to \\`${TOAST_NAME}\\`. Expected \\`foreground | background\\`.`\n return new Error(error)\n }\n return null\n },\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\nconst isDeltaInDirection = (\n delta: { x: number; y: number },\n direction: SwipeDirection,\n threshold = 0\n) => {\n const deltaX = Math.abs(delta.x)\n const deltaY = Math.abs(delta.y)\n const isDeltaX = deltaX > deltaY\n if (direction === 'left' || direction === 'right' || direction === 'horizontal') {\n return isDeltaX && deltaX > threshold\n } else {\n return !isDeltaX && deltaY > threshold\n }\n}\n\nfunction getAnnounceTextContent(container: HTMLElement) {\n if (!isWeb) return ''\n const textContent: string[] = []\n const childNodes = Array.from(container.childNodes)\n\n childNodes.forEach((node) => {\n if (node.nodeType === node.TEXT_NODE && node.textContent)\n textContent.push(node.textContent)\n if (isHTMLElement(node)) {\n const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none'\n const isExcluded = node.dataset.toastAnnounceExclude === ''\n\n if (!isHidden) {\n if (isExcluded) {\n const altText = node.dataset.toastAnnounceAlt\n if (altText) textContent.push(altText)\n } else {\n textContent.push(...getAnnounceTextContent(node))\n }\n }\n }\n })\n\n // We return a collection of text rather than a single concatenated string.\n // This allows SR VO to naturally pause break between nodes while announcing.\n return textContent\n}\n\nfunction isHTMLElement(node: any): node is HTMLElement {\n return node.nodeType === node.ELEMENT_NODE\n}\n\nexport { ToastImpl, ToastImplFrame, ToastImplProps, useToastInteractiveContext }\nexport type { ToastProps }\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useIsPresent } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n isWeb,\n styled,\n useAnimationDriver,\n useEvent,\n useThemeName,\n} from '@tamagui/core'\nimport { Dismissable, DismissableProps } from '@tamagui/dismissable'\nimport { PortalItem } from '@tamagui/portal'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { Animated, GestureResponderEvent, PanResponder } from 'react-native'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounce } from './ToastAnnounce'\nimport {\n Collection,\n ScopedProps,\n SwipeDirection,\n createToastContext,\n useToastProviderContext,\n} from './ToastProvider'\nimport { VIEWPORT_PAUSE, VIEWPORT_RESUME } from './ToastViewport'\n\nconst ToastImplFrame = styled(ThemeableStack, {\n name: 'ToastImpl',\n variants: {\n unstyled: {\n false: {\n focusable: true,\n backgroundColor: '$color6',\n borderRadius: '$10',\n paddingHorizontal: '$5',\n paddingVertical: '$2',\n marginHorizontal: 'auto',\n marginVertical: '$1',\n },\n },\n } as const,\n defaultVariants: {\n unstyled: false,\n },\n})\ninterface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n */\n open?: boolean\n /**\n * The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.\n */\n defaultOpen?: boolean\n /**\n * Event handler called when the open state of the dialog changes.\n */\n onOpenChange?(open: boolean): void\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\ntype SwipeEvent = GestureResponderEvent\n\nconst [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(\n TOAST_NAME,\n {\n onClose() {},\n }\n)\n\ntype ToastImplPrivateProps = { open: boolean; onClose(): void }\ntype ToastImplFrameProps = GetProps<typeof ToastImplFrame>\ntype ToastImplProps = ToastImplPrivateProps &\n ToastImplFrameProps & {\n /**\n * Control the sensitivity of the toast for accessibility purposes.\n * For toasts that are the result of a user action, choose foreground. Toasts generated from background tasks should use background.\n */\n type?: 'foreground' | 'background'\n /**\n * Time in milliseconds that toast should remain visible for. Overrides value given to `ToastProvider`.\n */\n duration?: number\n /**\n * Event handler called when the escape key is down. It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: DismissableProps['onEscapeKeyDown']\n /**\n * Event handler called when the dismiss timer is paused.\n * On web, this occurs when the pointer is moved over the viewport, the viewport is focused or when the window is blurred.\n * On mobile, this occurs when the toast is touched.\n */\n onPause?(): void\n /**\n * Event handler called when the dismiss timer is resumed.\n * On web, this occurs when the pointer is moved away from the viewport, the viewport is blurred or when the window is focused.\n * On mobile, this occurs when the toast is released.\n */\n onResume?(): void\n /**\n * Event handler called when starting a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeStart?(event: SwipeEvent): void\n /**\n * Event handler called during a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeMove?(event: SwipeEvent): void\n /**\n * Event handler called at the cancellation of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeCancel?(event: SwipeEvent): void\n /**\n * Event handler called at the end of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeEnd?(event: SwipeEvent): void\n /**\n * The viewport's name to send the toast to. Used when using multiple viewports and want to forward toasts to different ones.\n *\n * @default \"default\"\n */\n viewportName?: string\n /**\n *\n */\n id?: string\n }\n\nconst ToastImpl = React.forwardRef<TamaguiElement, ToastImplProps>(\n (props: ScopedProps<ToastImplProps>, forwardedRef) => {\n const {\n __scopeToast,\n type = 'foreground',\n duration: durationProp,\n open,\n onClose,\n onEscapeKeyDown,\n onPause,\n onResume,\n onSwipeStart,\n onSwipeMove,\n onSwipeCancel,\n onSwipeEnd,\n viewportName = 'default',\n ...toastProps\n } = props\n const isPresent = useIsPresent()\n const context = useToastProviderContext(TOAST_NAME, __scopeToast)\n const [node, setNode] = React.useState<TamaguiElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node))\n const duration = durationProp || context.duration\n const closeTimerStartTimeRef = React.useRef(0)\n const closeTimerRemainingTimeRef = React.useRef(duration)\n const closeTimerRef = React.useRef(0)\n const { onToastAdd, onToastRemove } = context\n\n const viewport = React.useMemo(() => {\n return context.viewports[viewportName] as HTMLElement | null | undefined\n }, [context.viewports, viewportName])\n\n const handleClose = useEvent(() => {\n if (!isPresent) {\n // already removed from the react tree\n return\n }\n // focus viewport if focus is within toast to read the remaining toast\n // count to SR users and ensure focus isn't lost\n if (isWeb) {\n const isFocusInToast = (node as HTMLDivElement)?.contains(document.activeElement)\n if (isFocusInToast) viewport?.focus()\n }\n onClose()\n })\n\n const startTimer = React.useCallback(\n (duration: number) => {\n if (!duration || duration === Infinity) return\n clearTimeout(closeTimerRef.current)\n closeTimerStartTimeRef.current = new Date().getTime()\n closeTimerRef.current = setTimeout(handleClose, duration) as unknown as number\n },\n [handleClose]\n )\n const handleResume = React.useCallback(() => {\n startTimer(closeTimerRemainingTimeRef.current)\n onResume?.()\n }, [onResume, startTimer])\n const handlePause = React.useCallback(() => {\n const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current\n closeTimerRemainingTimeRef.current =\n closeTimerRemainingTimeRef.current - elapsedTime\n window.clearTimeout(closeTimerRef.current)\n onPause?.()\n }, [onPause])\n\n React.useEffect(() => {\n if (!isWeb) return\n\n if (viewport) {\n viewport.addEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.addEventListener(VIEWPORT_RESUME, handleResume)\n return () => {\n viewport.removeEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.removeEventListener(VIEWPORT_RESUME, handleResume)\n }\n }\n }, [viewport, duration, onPause, onResume, startTimer])\n\n // start timer when toast opens or duration changes.\n // we include `open` in deps because closed !== unmounted when animating\n // so it could reopen before being completely unmounted\n React.useEffect(() => {\n if (open && !context.isClosePausedRef.current) {\n startTimer(duration)\n }\n }, [open, duration, context.isClosePausedRef, startTimer])\n\n React.useEffect(() => {\n onToastAdd()\n return () => onToastRemove()\n }, [onToastAdd, onToastRemove])\n\n const announceTextContent = React.useMemo(() => {\n if (!isWeb) return null\n return node ? getAnnounceTextContent(node as HTMLDivElement) : null\n }, [node])\n\n const isHorizontalSwipe = ['left', 'right', 'horizontal'].includes(\n context.swipeDirection\n )\n\n const driver = useAnimationDriver()\n if (!driver) {\n throw new Error('Must set animations in tamagui.config.ts')\n }\n\n const { useAnimatedNumber, useAnimatedNumberStyle } = driver\n\n const animatedNumber = useAnimatedNumber(0)\n\n // temp until reanimated useAnimatedNumber fix\n const AnimatedView = (driver['NumberView'] ?? driver.View) as typeof Animated.View\n\n const animatedStyles = useAnimatedNumberStyle(animatedNumber, (val) => {\n return {\n transform: [isHorizontalSwipe ? { translateX: val } : { translateY: val }],\n }\n })\n\n const panResponder = React.useMemo(() => {\n return PanResponder.create({\n onMoveShouldSetPanResponder: (e) => {\n onSwipeStart?.(e)\n return true\n },\n onPanResponderGrant: (e) => {\n if (!isWeb) {\n handlePause?.()\n }\n },\n onPanResponderMove: (e, { dy, dx }) => {\n let y = 0\n let x = 0\n if (context.swipeDirection === 'horizontal') x = dx\n else if (context.swipeDirection === 'left') x = Math.min(0, dx)\n else if (context.swipeDirection === 'right') x = Math.max(0, dx)\n else if (context.swipeDirection === 'vertical') y = dy\n else if (context.swipeDirection === 'up') y = Math.min(0, dy)\n else if (context.swipeDirection === 'down') y = Math.max(0, dy)\n\n onSwipeMove?.(e)\n\n const delta = { x, y }\n animatedNumber.setValue(isHorizontalSwipe ? x : y, { type: 'direct' })\n if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {\n onSwipeEnd?.(e)\n }\n },\n onPanResponderEnd: (e, { dx, dy }) => {\n if (\n !isDeltaInDirection(\n { x: dx, y: dy },\n context.swipeDirection,\n context.swipeThreshold\n )\n ) {\n if (!isWeb) {\n handleResume?.()\n }\n onSwipeCancel?.(e)\n animatedNumber.setValue(0, { type: 'spring' })\n }\n },\n })\n }, [handlePause, handleResume])\n\n // need to get the theme name from context and apply it again since portals don't retain the theme\n const themeName = useThemeName()\n\n return (\n <>\n {announceTextContent && (\n <ToastAnnounce\n __scopeToast={__scopeToast}\n // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.\n role=\"status\"\n aria-live={type === 'foreground' ? 'assertive' : 'polite'}\n aria-atomic\n >\n {announceTextContent}\n </ToastAnnounce>\n )}\n\n <PortalItem hostName={viewportName ?? 'default'}>\n <ToastInteractiveProvider\n key={props.id}\n scope={__scopeToast}\n onClose={() => {\n handleClose()\n }}\n >\n <Dismissable\n // asChild\n onEscapeKeyDown={composeEventHandlers(onEscapeKeyDown, () => {\n if (!context.isFocusedToastEscapeKeyDownRef.current) {\n handleClose()\n }\n context.isFocusedToastEscapeKeyDownRef.current = false\n })}\n >\n <Theme forceClassName name={themeName}>\n <AnimatedView\n {...panResponder?.panHandlers}\n style={[{ margin: 'auto' }, animatedStyles]}\n >\n <Collection.ItemSlot scope={__scopeToast}>\n <ToastImplFrame\n // Ensure toasts are announced as status list or status when focused\n role=\"status\"\n aria-live=\"off\"\n aria-atomic\n data-state={open ? 'open' : 'closed'}\n data-swipe-direction={context.swipeDirection}\n pointerEvents=\"auto\"\n // touchAction=\"none\"\n userSelect=\"none\"\n {...toastProps}\n ref={composedRefs}\n {...(isWeb && {\n onKeyDown: composeEventHandlers(\n (props as any).onKeyDown,\n (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n onEscapeKeyDown?.(event)\n onEscapeKeyDown?.(event)\n if (!event.defaultPrevented) {\n context.isFocusedToastEscapeKeyDownRef.current = true\n handleClose()\n }\n }\n ),\n })}\n />\n </Collection.ItemSlot>\n </AnimatedView>\n </Theme>\n </Dismissable>\n </ToastInteractiveProvider>\n </PortalItem>\n </>\n )\n }\n)\n\nToastImpl.propTypes = {\n type(props) {\n if (props.type && !['foreground', 'background'].includes(props.type)) {\n const error = `Invalid prop \\`type\\` supplied to \\`${TOAST_NAME}\\`. Expected \\`foreground | background\\`.`\n return new Error(error)\n }\n return null\n },\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\nconst isDeltaInDirection = (\n delta: { x: number; y: number },\n direction: SwipeDirection,\n threshold = 0\n) => {\n const deltaX = Math.abs(delta.x)\n const deltaY = Math.abs(delta.y)\n const isDeltaX = deltaX > deltaY\n if (direction === 'left' || direction === 'right' || direction === 'horizontal') {\n return isDeltaX && deltaX > threshold\n } else {\n return !isDeltaX && deltaY > threshold\n }\n}\n\nfunction getAnnounceTextContent(container: HTMLElement) {\n if (!isWeb) return ''\n const textContent: string[] = []\n const childNodes = Array.from(container.childNodes)\n\n childNodes.forEach((node) => {\n if (node.nodeType === node.TEXT_NODE && node.textContent)\n textContent.push(node.textContent)\n if (isHTMLElement(node)) {\n const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none'\n const isExcluded = node.dataset.toastAnnounceExclude === ''\n\n if (!isHidden) {\n if (isExcluded) {\n const altText = node.dataset.toastAnnounceAlt\n if (altText) textContent.push(altText)\n } else {\n textContent.push(...getAnnounceTextContent(node))\n }\n }\n }\n })\n\n // We return a collection of text rather than a single concatenated string.\n // This allows SR VO to naturally pause break between nodes while announcing.\n return textContent\n}\n\nfunction isHTMLElement(node: any): node is HTMLElement {\n return node.nodeType === node.ELEMENT_NODE\n}\n\nexport { ToastImpl, ToastImplFrame, ToastImplProps, useToastInteractiveContext }\nexport type { ToastProps }\n"],
|
|
5
|
+
"mappings": "AAmTM,mBAEI,KAFJ;AAnTN,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAqC;AAC9C,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,YAAY,WAAW;AACvB,SAA0C,oBAAoB;AAE9D,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB,uBAAuB;AAEhD,MAAM,iBAAiB,OAAO,gBAAgB;AAAA,EAC5C,MAAM;AAAA,EACN,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,WAAW;AAAA,QACX,iBAAiB;AAAA,QACjB,cAAc;AAAA,QACd,mBAAmB;AAAA,QACnB,iBAAiB;AAAA,QACjB,kBAAkB;AAAA,QAClB,gBAAgB;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,UAAU;AAAA,EACZ;AACF,CAAC;AAuBD,MAAM,CAAC,0BAA0B,0BAA0B,IAAI;AAAA,EAC7D;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IAAC;AAAA,EACb;AACF;AA2DA,MAAM,YAAY,MAAM;AAAA,EACtB,CAAC,OAAoC,iBAAiB;AACpD,UAAM;AAAA,MACJ;AAAA,MACA,OAAO;AAAA,MACP,UAAU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KAAK,GAAG,uBAAuB,IAAI,CAAC;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAID,SAAO;AACT;AAEA,SAAS,cAAc,MAAgC;AACrD,SAAO,KAAK,aAAa,KAAK;AAChC;",
|
|
6
6
|
"names": ["node", "duration"]
|
|
7
7
|
}
|
package/dist/esm/ToastImpl.mjs
CHANGED
|
@@ -26,13 +26,10 @@ import { VIEWPORT_PAUSE, VIEWPORT_RESUME } from "./ToastViewport";
|
|
|
26
26
|
const ToastImplFrame = styled(ThemeableStack, {
|
|
27
27
|
name: "ToastImpl",
|
|
28
28
|
variants: {
|
|
29
|
-
backgrounded: {
|
|
30
|
-
true: {
|
|
31
|
-
backgroundColor: "$color6"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
29
|
unstyled: {
|
|
35
30
|
false: {
|
|
31
|
+
focusable: true,
|
|
32
|
+
backgroundColor: "$color6",
|
|
36
33
|
borderRadius: "$10",
|
|
37
34
|
paddingHorizontal: "$5",
|
|
38
35
|
paddingVertical: "$2",
|
|
@@ -42,7 +39,6 @@ const ToastImplFrame = styled(ThemeableStack, {
|
|
|
42
39
|
}
|
|
43
40
|
},
|
|
44
41
|
defaultVariants: {
|
|
45
|
-
backgrounded: true,
|
|
46
42
|
unstyled: false
|
|
47
43
|
}
|
|
48
44
|
});
|
|
@@ -68,7 +64,7 @@ const ToastImpl = React.forwardRef(
|
|
|
68
64
|
onSwipeMove,
|
|
69
65
|
onSwipeCancel,
|
|
70
66
|
onSwipeEnd,
|
|
71
|
-
viewportName,
|
|
67
|
+
viewportName = "default",
|
|
72
68
|
...toastProps
|
|
73
69
|
} = props;
|
|
74
70
|
const isPresent = useIsPresent();
|
|
@@ -80,15 +76,17 @@ const ToastImpl = React.forwardRef(
|
|
|
80
76
|
const closeTimerRemainingTimeRef = React.useRef(duration);
|
|
81
77
|
const closeTimerRef = React.useRef(0);
|
|
82
78
|
const { onToastAdd, onToastRemove } = context;
|
|
79
|
+
const viewport = React.useMemo(() => {
|
|
80
|
+
return context.viewports[viewportName];
|
|
81
|
+
}, [context.viewports, viewportName]);
|
|
83
82
|
const handleClose = useEvent(() => {
|
|
84
|
-
var _a;
|
|
85
83
|
if (!isPresent) {
|
|
86
84
|
return;
|
|
87
85
|
}
|
|
88
86
|
if (isWeb) {
|
|
89
87
|
const isFocusInToast = node == null ? void 0 : node.contains(document.activeElement);
|
|
90
88
|
if (isFocusInToast)
|
|
91
|
-
|
|
89
|
+
viewport == null ? void 0 : viewport.focus();
|
|
92
90
|
}
|
|
93
91
|
onClose();
|
|
94
92
|
});
|
|
@@ -115,7 +113,6 @@ const ToastImpl = React.forwardRef(
|
|
|
115
113
|
React.useEffect(() => {
|
|
116
114
|
if (!isWeb)
|
|
117
115
|
return;
|
|
118
|
-
const viewport = context.viewport;
|
|
119
116
|
if (viewport) {
|
|
120
117
|
viewport.addEventListener(VIEWPORT_PAUSE, handlePause);
|
|
121
118
|
viewport.addEventListener(VIEWPORT_RESUME, handleResume);
|
|
@@ -124,7 +121,7 @@ const ToastImpl = React.forwardRef(
|
|
|
124
121
|
viewport.removeEventListener(VIEWPORT_RESUME, handleResume);
|
|
125
122
|
};
|
|
126
123
|
}
|
|
127
|
-
}, [
|
|
124
|
+
}, [viewport, duration, onPause, onResume, startTimer]);
|
|
128
125
|
React.useEffect(() => {
|
|
129
126
|
if (open && !context.isClosePausedRef.current) {
|
|
130
127
|
startTimer(duration);
|
|
@@ -241,7 +238,6 @@ const ToastImpl = React.forwardRef(
|
|
|
241
238
|
role: "status",
|
|
242
239
|
"aria-live": "off",
|
|
243
240
|
"aria-atomic": true,
|
|
244
|
-
tabIndex: 0,
|
|
245
241
|
"data-state": open ? "open" : "closed",
|
|
246
242
|
"data-swipe-direction": context.swipeDirection,
|
|
247
243
|
pointerEvents: "auto",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ToastImpl.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useIsPresent } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n isWeb,\n styled,\n useAnimationDriver,\n useEvent,\n useThemeName,\n} from '@tamagui/core'\nimport { Dismissable, DismissableProps } from '@tamagui/dismissable'\nimport { PortalItem } from '@tamagui/portal'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { Animated, GestureResponderEvent, PanResponder } from 'react-native'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounce } from './ToastAnnounce'\nimport {\n Collection,\n ScopedProps,\n SwipeDirection,\n createToastContext,\n useToastProviderContext,\n} from './ToastProvider'\nimport { VIEWPORT_PAUSE, VIEWPORT_RESUME } from './ToastViewport'\n\nconst ToastImplFrame = styled(ThemeableStack, {\n name: 'ToastImpl',\n variants: {\n backgrounded: {\n true: {\n backgroundColor: '$color6',\n },\n },\n unstyled: {\n false: {\n borderRadius: '$10',\n paddingHorizontal: '$5',\n paddingVertical: '$2',\n marginHorizontal: 'auto',\n marginVertical: '$1',\n },\n },\n },\n defaultVariants: {\n backgrounded: true,\n unstyled: false,\n },\n})\ninterface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n */\n open?: boolean\n /**\n * The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.\n */\n defaultOpen?: boolean\n /**\n * Event handler called when the open state of the dialog changes.\n */\n onOpenChange?(open: boolean): void\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\ntype SwipeEvent = GestureResponderEvent\n\nconst [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(\n TOAST_NAME,\n {\n onClose() {},\n }\n)\n\ntype ToastImplPrivateProps = { open: boolean; onClose(): void }\ntype ToastImplFrameProps = GetProps<typeof ToastImplFrame>\ntype ToastImplProps = ToastImplPrivateProps &\n ToastImplFrameProps & {\n /**\n * Control the sensitivity of the toast for accessibility purposes.\n * For toasts that are the result of a user action, choose foreground. Toasts generated from background tasks should use background.\n */\n type?: 'foreground' | 'background'\n /**\n * Time in milliseconds that toast should remain visible for. Overrides value given to `ToastProvider`.\n */\n duration?: number\n /**\n * Event handler called when the escape key is down. It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: DismissableProps['onEscapeKeyDown']\n /**\n * Event handler called when the dismiss timer is paused.\n * On web, this occurs when the pointer is moved over the viewport, the viewport is focused or when the window is blurred.\n * On mobile, this occurs when the toast is touched.\n */\n onPause?(): void\n /**\n * Event handler called when the dismiss timer is resumed.\n * On web, this occurs when the pointer is moved away from the viewport, the viewport is blurred or when the window is focused.\n * On mobile, this occurs when the toast is released.\n */\n onResume?(): void\n /**\n * Event handler called when starting a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeStart?(event: SwipeEvent): void\n /**\n * Event handler called during a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeMove?(event: SwipeEvent): void\n /**\n * Event handler called at the cancellation of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeCancel?(event: SwipeEvent): void\n /**\n * Event handler called at the end of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeEnd?(event: SwipeEvent): void\n /**\n * The viewport's name to send the toast to. Used when using multiple viewports and want to forward toasts to different ones.\n *\n * @default \"default\"\n */\n viewportName?: string\n /**\n * \n */\n id?: string\n }\n\nconst ToastImpl = React.forwardRef<TamaguiElement, ToastImplProps>(\n (props: ScopedProps<ToastImplProps>, forwardedRef) => {\n const {\n __scopeToast,\n type = 'foreground',\n duration: durationProp,\n open,\n onClose,\n onEscapeKeyDown,\n onPause,\n onResume,\n onSwipeStart,\n onSwipeMove,\n onSwipeCancel,\n onSwipeEnd,\n viewportName,\n ...toastProps\n } = props\n const isPresent = useIsPresent()\n const context = useToastProviderContext(TOAST_NAME, __scopeToast)\n const [node, setNode] = React.useState<TamaguiElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node))\n const duration = durationProp || context.duration\n const closeTimerStartTimeRef = React.useRef(0)\n const closeTimerRemainingTimeRef = React.useRef(duration)\n const closeTimerRef = React.useRef(0)\n const { onToastAdd, onToastRemove } = context\n const handleClose = useEvent(() => {\n if (!isPresent) {\n // already removed from the react tree\n return\n }\n // focus viewport if focus is within toast to read the remaining toast\n // count to SR users and ensure focus isn't lost\n if (isWeb) {\n const isFocusInToast = (node as HTMLDivElement)?.contains(document.activeElement)\n if (isFocusInToast) context.viewport?.focus()\n }\n onClose()\n })\n\n const startTimer = React.useCallback(\n (duration: number) => {\n if (!duration || duration === Infinity) return\n clearTimeout(closeTimerRef.current)\n closeTimerStartTimeRef.current = new Date().getTime()\n closeTimerRef.current = setTimeout(handleClose, duration) as unknown as number\n },\n [handleClose]\n )\n const handleResume = React.useCallback(() => {\n startTimer(closeTimerRemainingTimeRef.current)\n onResume?.()\n }, [onResume, startTimer])\n const handlePause = React.useCallback(() => {\n const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current\n closeTimerRemainingTimeRef.current =\n closeTimerRemainingTimeRef.current - elapsedTime\n window.clearTimeout(closeTimerRef.current)\n onPause?.()\n }, [onPause])\n\n React.useEffect(() => {\n if (!isWeb) return\n const viewport = context.viewport as HTMLElement\n if (viewport) {\n viewport.addEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.addEventListener(VIEWPORT_RESUME, handleResume)\n return () => {\n viewport.removeEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.removeEventListener(VIEWPORT_RESUME, handleResume)\n }\n }\n }, [context.viewport, duration, onPause, onResume, startTimer])\n\n // start timer when toast opens or duration changes.\n // we include `open` in deps because closed !== unmounted when animating\n // so it could reopen before being completely unmounted\n React.useEffect(() => {\n if (open && !context.isClosePausedRef.current) {\n startTimer(duration)\n }\n }, [open, duration, context.isClosePausedRef, startTimer])\n\n React.useEffect(() => {\n onToastAdd()\n return () => onToastRemove()\n }, [onToastAdd, onToastRemove])\n\n const announceTextContent = React.useMemo(() => {\n if (!isWeb) return null\n return node ? getAnnounceTextContent(node as HTMLDivElement) : null\n }, [node])\n\n const isHorizontalSwipe = ['left', 'right', 'horizontal'].includes(\n context.swipeDirection\n )\n\n const driver = useAnimationDriver()\n if (!driver) {\n throw new Error('Must set animations in tamagui.config.ts')\n }\n\n const { useAnimatedNumber, useAnimatedNumberStyle } = driver\n\n const animatedNumber = useAnimatedNumber(0)\n\n // temp until reanimated useAnimatedNumber fix\n const AnimatedView = (driver['NumberView'] ?? driver.View) as typeof Animated.View\n\n const animatedStyles = useAnimatedNumberStyle(animatedNumber, (val) => {\n return {\n transform: [isHorizontalSwipe ? { translateX: val } : { translateY: val }],\n }\n })\n\n const panResponder = React.useMemo(() => {\n return PanResponder.create({\n onMoveShouldSetPanResponder: (e) => {\n onSwipeStart?.(e)\n return true\n },\n onPanResponderGrant: (e) => {\n if (!isWeb) {\n handlePause?.()\n }\n },\n onPanResponderMove: (e, { dy, dx }) => {\n let y = 0\n let x = 0\n if (context.swipeDirection === 'horizontal') x = dx\n else if (context.swipeDirection === 'left') x = Math.min(0, dx)\n else if (context.swipeDirection === 'right') x = Math.max(0, dx)\n else if (context.swipeDirection === 'vertical') y = dy\n else if (context.swipeDirection === 'up') y = Math.min(0, dy)\n else if (context.swipeDirection === 'down') y = Math.max(0, dy)\n\n onSwipeMove?.(e)\n\n const delta = { x, y }\n animatedNumber.setValue(isHorizontalSwipe ? x : y, { type: 'direct' })\n if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {\n onSwipeEnd?.(e)\n }\n },\n onPanResponderEnd: (e, { dx, dy }) => {\n if (\n !isDeltaInDirection(\n { x: dx, y: dy },\n context.swipeDirection,\n context.swipeThreshold\n )\n ) {\n if (!isWeb) {\n handleResume?.()\n }\n onSwipeCancel?.(e)\n animatedNumber.setValue(0, { type: 'spring' })\n }\n },\n })\n }, [handlePause, handleResume])\n\n // need to get the theme name from context and apply it again since portals don't retain the theme\n const themeName = useThemeName()\n\n return (\n <>\n {announceTextContent && (\n <ToastAnnounce\n __scopeToast={__scopeToast}\n // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.\n role=\"status\"\n aria-live={type === 'foreground' ? 'assertive' : 'polite'}\n aria-atomic\n >\n {announceTextContent}\n </ToastAnnounce>\n )}\n\n <PortalItem hostName={viewportName ?? 'default'}>\n <ToastInteractiveProvider\n key={props.id}\n scope={__scopeToast}\n onClose={() => {\n handleClose()\n }}\n >\n <Dismissable\n // asChild\n onEscapeKeyDown={composeEventHandlers(onEscapeKeyDown, () => {\n if (!context.isFocusedToastEscapeKeyDownRef.current) {\n handleClose()\n }\n context.isFocusedToastEscapeKeyDownRef.current = false\n })}\n >\n <Theme forceClassName name={themeName}>\n <AnimatedView\n {...panResponder?.panHandlers}\n style={[{ margin: 'auto' }, animatedStyles]}\n >\n <Collection.ItemSlot scope={__scopeToast}>\n <ToastImplFrame\n // Ensure toasts are announced as status list or status when focused\n role=\"status\"\n aria-live=\"off\"\n aria-atomic\n tabIndex={0}\n data-state={open ? 'open' : 'closed'}\n data-swipe-direction={context.swipeDirection}\n pointerEvents=\"auto\"\n // touchAction=\"none\"\n userSelect=\"none\"\n {...toastProps}\n ref={composedRefs}\n {...(isWeb && {\n onKeyDown: composeEventHandlers(\n (props as any).onKeyDown,\n (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n onEscapeKeyDown?.(event)\n onEscapeKeyDown?.(event)\n if (!event.defaultPrevented) {\n context.isFocusedToastEscapeKeyDownRef.current = true\n handleClose()\n }\n }\n ),\n })}\n />\n </Collection.ItemSlot>\n </AnimatedView>\n </Theme>\n </Dismissable>\n </ToastInteractiveProvider>\n </PortalItem>\n </>\n )\n }\n)\n\nToastImpl.propTypes = {\n type(props) {\n if (props.type && !['foreground', 'background'].includes(props.type)) {\n const error = `Invalid prop \\`type\\` supplied to \\`${TOAST_NAME}\\`. Expected \\`foreground | background\\`.`\n return new Error(error)\n }\n return null\n },\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\nconst isDeltaInDirection = (\n delta: { x: number; y: number },\n direction: SwipeDirection,\n threshold = 0\n) => {\n const deltaX = Math.abs(delta.x)\n const deltaY = Math.abs(delta.y)\n const isDeltaX = deltaX > deltaY\n if (direction === 'left' || direction === 'right' || direction === 'horizontal') {\n return isDeltaX && deltaX > threshold\n } else {\n return !isDeltaX && deltaY > threshold\n }\n}\n\nfunction getAnnounceTextContent(container: HTMLElement) {\n if (!isWeb) return ''\n const textContent: string[] = []\n const childNodes = Array.from(container.childNodes)\n\n childNodes.forEach((node) => {\n if (node.nodeType === node.TEXT_NODE && node.textContent)\n textContent.push(node.textContent)\n if (isHTMLElement(node)) {\n const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none'\n const isExcluded = node.dataset.toastAnnounceExclude === ''\n\n if (!isHidden) {\n if (isExcluded) {\n const altText = node.dataset.toastAnnounceAlt\n if (altText) textContent.push(altText)\n } else {\n textContent.push(...getAnnounceTextContent(node))\n }\n }\n }\n })\n\n // We return a collection of text rather than a single concatenated string.\n // This allows SR VO to naturally pause break between nodes while announcing.\n return textContent\n}\n\nfunction isHTMLElement(node: any): node is HTMLElement {\n return node.nodeType === node.ELEMENT_NODE\n}\n\nexport { ToastImpl, ToastImplFrame, ToastImplProps, useToastInteractiveContext }\nexport type { ToastProps }\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useIsPresent } from '@tamagui/animate-presence'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport {\n GetProps,\n TamaguiElement,\n Theme,\n composeEventHandlers,\n isWeb,\n styled,\n useAnimationDriver,\n useEvent,\n useThemeName,\n} from '@tamagui/core'\nimport { Dismissable, DismissableProps } from '@tamagui/dismissable'\nimport { PortalItem } from '@tamagui/portal'\nimport { ThemeableStack } from '@tamagui/stacks'\nimport * as React from 'react'\nimport { Animated, GestureResponderEvent, PanResponder } from 'react-native'\n\nimport { TOAST_NAME } from './constants'\nimport { ToastAnnounce } from './ToastAnnounce'\nimport {\n Collection,\n ScopedProps,\n SwipeDirection,\n createToastContext,\n useToastProviderContext,\n} from './ToastProvider'\nimport { VIEWPORT_PAUSE, VIEWPORT_RESUME } from './ToastViewport'\n\nconst ToastImplFrame = styled(ThemeableStack, {\n name: 'ToastImpl',\n variants: {\n unstyled: {\n false: {\n focusable: true,\n backgroundColor: '$color6',\n borderRadius: '$10',\n paddingHorizontal: '$5',\n paddingVertical: '$2',\n marginHorizontal: 'auto',\n marginVertical: '$1',\n },\n },\n } as const,\n defaultVariants: {\n unstyled: false,\n },\n})\ninterface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {\n /**\n * The controlled open state of the dialog. Must be used in conjunction with `onOpenChange`.\n */\n open?: boolean\n /**\n * The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.\n */\n defaultOpen?: boolean\n /**\n * Event handler called when the open state of the dialog changes.\n */\n onOpenChange?(open: boolean): void\n /**\n * Used to force mounting when more control is needed. Useful when\n * controlling animation with React animation libraries.\n */\n forceMount?: true\n}\n\ntype SwipeEvent = GestureResponderEvent\n\nconst [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(\n TOAST_NAME,\n {\n onClose() {},\n }\n)\n\ntype ToastImplPrivateProps = { open: boolean; onClose(): void }\ntype ToastImplFrameProps = GetProps<typeof ToastImplFrame>\ntype ToastImplProps = ToastImplPrivateProps &\n ToastImplFrameProps & {\n /**\n * Control the sensitivity of the toast for accessibility purposes.\n * For toasts that are the result of a user action, choose foreground. Toasts generated from background tasks should use background.\n */\n type?: 'foreground' | 'background'\n /**\n * Time in milliseconds that toast should remain visible for. Overrides value given to `ToastProvider`.\n */\n duration?: number\n /**\n * Event handler called when the escape key is down. It can be prevented by calling `event.preventDefault`.\n */\n onEscapeKeyDown?: DismissableProps['onEscapeKeyDown']\n /**\n * Event handler called when the dismiss timer is paused.\n * On web, this occurs when the pointer is moved over the viewport, the viewport is focused or when the window is blurred.\n * On mobile, this occurs when the toast is touched.\n */\n onPause?(): void\n /**\n * Event handler called when the dismiss timer is resumed.\n * On web, this occurs when the pointer is moved away from the viewport, the viewport is blurred or when the window is focused.\n * On mobile, this occurs when the toast is released.\n */\n onResume?(): void\n /**\n * Event handler called when starting a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeStart?(event: SwipeEvent): void\n /**\n * Event handler called during a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeMove?(event: SwipeEvent): void\n /**\n * Event handler called at the cancellation of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeCancel?(event: SwipeEvent): void\n /**\n * Event handler called at the end of a swipe interaction. It can be prevented by calling `event.preventDefault`.\n */\n onSwipeEnd?(event: SwipeEvent): void\n /**\n * The viewport's name to send the toast to. Used when using multiple viewports and want to forward toasts to different ones.\n *\n * @default \"default\"\n */\n viewportName?: string\n /**\n *\n */\n id?: string\n }\n\nconst ToastImpl = React.forwardRef<TamaguiElement, ToastImplProps>(\n (props: ScopedProps<ToastImplProps>, forwardedRef) => {\n const {\n __scopeToast,\n type = 'foreground',\n duration: durationProp,\n open,\n onClose,\n onEscapeKeyDown,\n onPause,\n onResume,\n onSwipeStart,\n onSwipeMove,\n onSwipeCancel,\n onSwipeEnd,\n viewportName = 'default',\n ...toastProps\n } = props\n const isPresent = useIsPresent()\n const context = useToastProviderContext(TOAST_NAME, __scopeToast)\n const [node, setNode] = React.useState<TamaguiElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node))\n const duration = durationProp || context.duration\n const closeTimerStartTimeRef = React.useRef(0)\n const closeTimerRemainingTimeRef = React.useRef(duration)\n const closeTimerRef = React.useRef(0)\n const { onToastAdd, onToastRemove } = context\n\n const viewport = React.useMemo(() => {\n return context.viewports[viewportName] as HTMLElement | null | undefined\n }, [context.viewports, viewportName])\n\n const handleClose = useEvent(() => {\n if (!isPresent) {\n // already removed from the react tree\n return\n }\n // focus viewport if focus is within toast to read the remaining toast\n // count to SR users and ensure focus isn't lost\n if (isWeb) {\n const isFocusInToast = (node as HTMLDivElement)?.contains(document.activeElement)\n if (isFocusInToast) viewport?.focus()\n }\n onClose()\n })\n\n const startTimer = React.useCallback(\n (duration: number) => {\n if (!duration || duration === Infinity) return\n clearTimeout(closeTimerRef.current)\n closeTimerStartTimeRef.current = new Date().getTime()\n closeTimerRef.current = setTimeout(handleClose, duration) as unknown as number\n },\n [handleClose]\n )\n const handleResume = React.useCallback(() => {\n startTimer(closeTimerRemainingTimeRef.current)\n onResume?.()\n }, [onResume, startTimer])\n const handlePause = React.useCallback(() => {\n const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current\n closeTimerRemainingTimeRef.current =\n closeTimerRemainingTimeRef.current - elapsedTime\n window.clearTimeout(closeTimerRef.current)\n onPause?.()\n }, [onPause])\n\n React.useEffect(() => {\n if (!isWeb) return\n\n if (viewport) {\n viewport.addEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.addEventListener(VIEWPORT_RESUME, handleResume)\n return () => {\n viewport.removeEventListener(VIEWPORT_PAUSE, handlePause)\n viewport.removeEventListener(VIEWPORT_RESUME, handleResume)\n }\n }\n }, [viewport, duration, onPause, onResume, startTimer])\n\n // start timer when toast opens or duration changes.\n // we include `open` in deps because closed !== unmounted when animating\n // so it could reopen before being completely unmounted\n React.useEffect(() => {\n if (open && !context.isClosePausedRef.current) {\n startTimer(duration)\n }\n }, [open, duration, context.isClosePausedRef, startTimer])\n\n React.useEffect(() => {\n onToastAdd()\n return () => onToastRemove()\n }, [onToastAdd, onToastRemove])\n\n const announceTextContent = React.useMemo(() => {\n if (!isWeb) return null\n return node ? getAnnounceTextContent(node as HTMLDivElement) : null\n }, [node])\n\n const isHorizontalSwipe = ['left', 'right', 'horizontal'].includes(\n context.swipeDirection\n )\n\n const driver = useAnimationDriver()\n if (!driver) {\n throw new Error('Must set animations in tamagui.config.ts')\n }\n\n const { useAnimatedNumber, useAnimatedNumberStyle } = driver\n\n const animatedNumber = useAnimatedNumber(0)\n\n // temp until reanimated useAnimatedNumber fix\n const AnimatedView = (driver['NumberView'] ?? driver.View) as typeof Animated.View\n\n const animatedStyles = useAnimatedNumberStyle(animatedNumber, (val) => {\n return {\n transform: [isHorizontalSwipe ? { translateX: val } : { translateY: val }],\n }\n })\n\n const panResponder = React.useMemo(() => {\n return PanResponder.create({\n onMoveShouldSetPanResponder: (e) => {\n onSwipeStart?.(e)\n return true\n },\n onPanResponderGrant: (e) => {\n if (!isWeb) {\n handlePause?.()\n }\n },\n onPanResponderMove: (e, { dy, dx }) => {\n let y = 0\n let x = 0\n if (context.swipeDirection === 'horizontal') x = dx\n else if (context.swipeDirection === 'left') x = Math.min(0, dx)\n else if (context.swipeDirection === 'right') x = Math.max(0, dx)\n else if (context.swipeDirection === 'vertical') y = dy\n else if (context.swipeDirection === 'up') y = Math.min(0, dy)\n else if (context.swipeDirection === 'down') y = Math.max(0, dy)\n\n onSwipeMove?.(e)\n\n const delta = { x, y }\n animatedNumber.setValue(isHorizontalSwipe ? x : y, { type: 'direct' })\n if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {\n onSwipeEnd?.(e)\n }\n },\n onPanResponderEnd: (e, { dx, dy }) => {\n if (\n !isDeltaInDirection(\n { x: dx, y: dy },\n context.swipeDirection,\n context.swipeThreshold\n )\n ) {\n if (!isWeb) {\n handleResume?.()\n }\n onSwipeCancel?.(e)\n animatedNumber.setValue(0, { type: 'spring' })\n }\n },\n })\n }, [handlePause, handleResume])\n\n // need to get the theme name from context and apply it again since portals don't retain the theme\n const themeName = useThemeName()\n\n return (\n <>\n {announceTextContent && (\n <ToastAnnounce\n __scopeToast={__scopeToast}\n // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.\n role=\"status\"\n aria-live={type === 'foreground' ? 'assertive' : 'polite'}\n aria-atomic\n >\n {announceTextContent}\n </ToastAnnounce>\n )}\n\n <PortalItem hostName={viewportName ?? 'default'}>\n <ToastInteractiveProvider\n key={props.id}\n scope={__scopeToast}\n onClose={() => {\n handleClose()\n }}\n >\n <Dismissable\n // asChild\n onEscapeKeyDown={composeEventHandlers(onEscapeKeyDown, () => {\n if (!context.isFocusedToastEscapeKeyDownRef.current) {\n handleClose()\n }\n context.isFocusedToastEscapeKeyDownRef.current = false\n })}\n >\n <Theme forceClassName name={themeName}>\n <AnimatedView\n {...panResponder?.panHandlers}\n style={[{ margin: 'auto' }, animatedStyles]}\n >\n <Collection.ItemSlot scope={__scopeToast}>\n <ToastImplFrame\n // Ensure toasts are announced as status list or status when focused\n role=\"status\"\n aria-live=\"off\"\n aria-atomic\n data-state={open ? 'open' : 'closed'}\n data-swipe-direction={context.swipeDirection}\n pointerEvents=\"auto\"\n // touchAction=\"none\"\n userSelect=\"none\"\n {...toastProps}\n ref={composedRefs}\n {...(isWeb && {\n onKeyDown: composeEventHandlers(\n (props as any).onKeyDown,\n (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n onEscapeKeyDown?.(event)\n onEscapeKeyDown?.(event)\n if (!event.defaultPrevented) {\n context.isFocusedToastEscapeKeyDownRef.current = true\n handleClose()\n }\n }\n ),\n })}\n />\n </Collection.ItemSlot>\n </AnimatedView>\n </Theme>\n </Dismissable>\n </ToastInteractiveProvider>\n </PortalItem>\n </>\n )\n }\n)\n\nToastImpl.propTypes = {\n type(props) {\n if (props.type && !['foreground', 'background'].includes(props.type)) {\n const error = `Invalid prop \\`type\\` supplied to \\`${TOAST_NAME}\\`. Expected \\`foreground | background\\`.`\n return new Error(error)\n }\n return null\n },\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\nconst isDeltaInDirection = (\n delta: { x: number; y: number },\n direction: SwipeDirection,\n threshold = 0\n) => {\n const deltaX = Math.abs(delta.x)\n const deltaY = Math.abs(delta.y)\n const isDeltaX = deltaX > deltaY\n if (direction === 'left' || direction === 'right' || direction === 'horizontal') {\n return isDeltaX && deltaX > threshold\n } else {\n return !isDeltaX && deltaY > threshold\n }\n}\n\nfunction getAnnounceTextContent(container: HTMLElement) {\n if (!isWeb) return ''\n const textContent: string[] = []\n const childNodes = Array.from(container.childNodes)\n\n childNodes.forEach((node) => {\n if (node.nodeType === node.TEXT_NODE && node.textContent)\n textContent.push(node.textContent)\n if (isHTMLElement(node)) {\n const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none'\n const isExcluded = node.dataset.toastAnnounceExclude === ''\n\n if (!isHidden) {\n if (isExcluded) {\n const altText = node.dataset.toastAnnounceAlt\n if (altText) textContent.push(altText)\n } else {\n textContent.push(...getAnnounceTextContent(node))\n }\n }\n }\n })\n\n // We return a collection of text rather than a single concatenated string.\n // This allows SR VO to naturally pause break between nodes while announcing.\n return textContent\n}\n\nfunction isHTMLElement(node: any): node is HTMLElement {\n return node.nodeType === node.ELEMENT_NODE\n}\n\nexport { ToastImpl, ToastImplFrame, ToastImplProps, useToastInteractiveContext }\nexport type { ToastProps }\n"],
|
|
5
|
+
"mappings": "AAmTM,mBAEI,KAFJ;AAnTN,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAqC;AAC9C,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,YAAY,WAAW;AACvB,SAA0C,oBAAoB;AAE9D,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB,uBAAuB;AAEhD,MAAM,iBAAiB,OAAO,gBAAgB;AAAA,EAC5C,MAAM;AAAA,EACN,UAAU;AAAA,IACR,UAAU;AAAA,MACR,OAAO;AAAA,QACL,WAAW;AAAA,QACX,iBAAiB;AAAA,QACjB,cAAc;AAAA,QACd,mBAAmB;AAAA,QACnB,iBAAiB;AAAA,Q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