@radix-ui/react-toast 0.0.0-20250116175529

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # `react-toast`
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ yarn add @radix-ui/react-toast
7
+ # or
8
+ $ npm install @radix-ui/react-toast
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ View docs [here](https://radix-ui.com/primitives/docs/components/toast).
@@ -0,0 +1,120 @@
1
+ import * as _radix_ui_react_context from '@radix-ui/react-context';
2
+ import * as React from 'react';
3
+ import * as DismissableLayer from '@radix-ui/react-dismissable-layer';
4
+ import { Primitive } from '@radix-ui/react-primitive';
5
+
6
+ type SwipeDirection = 'up' | 'down' | 'left' | 'right';
7
+ declare const createToastScope: _radix_ui_react_context.CreateScope;
8
+ interface ToastProviderProps {
9
+ children?: React.ReactNode;
10
+ /**
11
+ * An author-localized label for each toast. Used to help screen reader users
12
+ * associate the interruption with a toast.
13
+ * @defaultValue 'Notification'
14
+ */
15
+ label?: string;
16
+ /**
17
+ * Time in milliseconds that each toast should remain visible for.
18
+ * @defaultValue 5000
19
+ */
20
+ duration?: number;
21
+ /**
22
+ * Direction of pointer swipe that should close the toast.
23
+ * @defaultValue 'right'
24
+ */
25
+ swipeDirection?: SwipeDirection;
26
+ /**
27
+ * Distance in pixels that the swipe must pass before a close is triggered.
28
+ * @defaultValue 50
29
+ */
30
+ swipeThreshold?: number;
31
+ }
32
+ declare const ToastProvider: React.FC<ToastProviderProps>;
33
+ type PrimitiveOrderedListProps = React.ComponentPropsWithoutRef<typeof Primitive.ol>;
34
+ interface ToastViewportProps extends PrimitiveOrderedListProps {
35
+ /**
36
+ * The keys to use as the keyboard shortcut that will move focus to the toast viewport.
37
+ * @defaultValue ['F8']
38
+ */
39
+ hotkey?: string[];
40
+ /**
41
+ * An author-localized label for the toast viewport to provide context for screen reader users
42
+ * when navigating page landmarks. The available `{hotkey}` placeholder will be replaced for you.
43
+ * @defaultValue 'Notifications ({hotkey})'
44
+ */
45
+ label?: string;
46
+ }
47
+ declare const ToastViewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
48
+ type ToastElement = ToastImplElement;
49
+ interface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {
50
+ open?: boolean;
51
+ defaultOpen?: boolean;
52
+ onOpenChange?(open: boolean): void;
53
+ /**
54
+ * Used to force mounting when more control is needed. Useful when
55
+ * controlling animation with React animation libraries.
56
+ */
57
+ forceMount?: true;
58
+ }
59
+ declare const Toast: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
60
+ type SwipeEvent = {
61
+ currentTarget: EventTarget & ToastElement;
62
+ } & Omit<CustomEvent<{
63
+ originalEvent: React.PointerEvent;
64
+ delta: {
65
+ x: number;
66
+ y: number;
67
+ };
68
+ }>, 'currentTarget'>;
69
+ type ToastImplElement = React.ElementRef<typeof Primitive.li>;
70
+ type DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer.Root>;
71
+ type ToastImplPrivateProps = {
72
+ open: boolean;
73
+ onClose(): void;
74
+ };
75
+ type PrimitiveListItemProps = React.ComponentPropsWithoutRef<typeof Primitive.li>;
76
+ interface ToastImplProps extends ToastImplPrivateProps, PrimitiveListItemProps {
77
+ type?: 'foreground' | 'background';
78
+ /**
79
+ * Time in milliseconds that toast should remain visible for. Overrides value
80
+ * given to `ToastProvider`.
81
+ */
82
+ duration?: number;
83
+ onEscapeKeyDown?: DismissableLayerProps['onEscapeKeyDown'];
84
+ onPause?(): void;
85
+ onResume?(): void;
86
+ onSwipeStart?(event: SwipeEvent): void;
87
+ onSwipeMove?(event: SwipeEvent): void;
88
+ onSwipeCancel?(event: SwipeEvent): void;
89
+ onSwipeEnd?(event: SwipeEvent): void;
90
+ }
91
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
92
+ interface ToastTitleProps extends PrimitiveDivProps {
93
+ }
94
+ declare const ToastTitle: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
95
+ interface ToastDescriptionProps extends PrimitiveDivProps {
96
+ }
97
+ declare const ToastDescription: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
98
+ interface ToastActionProps extends ToastCloseProps {
99
+ /**
100
+ * A short description for an alternate way to carry out the action. For screen reader users
101
+ * who will not be able to navigate to the button easily/quickly.
102
+ * @example <ToastAction altText="Goto account settings to upgrade">Upgrade</ToastAction>
103
+ * @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
104
+ */
105
+ altText: string;
106
+ }
107
+ declare const ToastAction: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
108
+ type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
109
+ interface ToastCloseProps extends PrimitiveButtonProps {
110
+ }
111
+ declare const ToastClose: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
112
+ declare const Provider: React.FC<ToastProviderProps>;
113
+ declare const Viewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
114
+ declare const Root: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
115
+ declare const Title: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
116
+ declare const Description: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
117
+ declare const Action: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
118
+ declare const Close: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
119
+
120
+ export { Action, Close, Description, Provider, Root, Title, Toast, ToastAction, type ToastActionProps, ToastClose, type ToastCloseProps, ToastDescription, type ToastDescriptionProps, type ToastProps, ToastProvider, type ToastProviderProps, ToastTitle, type ToastTitleProps, ToastViewport, type ToastViewportProps, Viewport, createToastScope };
@@ -0,0 +1,120 @@
1
+ import * as _radix_ui_react_context from '@radix-ui/react-context';
2
+ import * as React from 'react';
3
+ import * as DismissableLayer from '@radix-ui/react-dismissable-layer';
4
+ import { Primitive } from '@radix-ui/react-primitive';
5
+
6
+ type SwipeDirection = 'up' | 'down' | 'left' | 'right';
7
+ declare const createToastScope: _radix_ui_react_context.CreateScope;
8
+ interface ToastProviderProps {
9
+ children?: React.ReactNode;
10
+ /**
11
+ * An author-localized label for each toast. Used to help screen reader users
12
+ * associate the interruption with a toast.
13
+ * @defaultValue 'Notification'
14
+ */
15
+ label?: string;
16
+ /**
17
+ * Time in milliseconds that each toast should remain visible for.
18
+ * @defaultValue 5000
19
+ */
20
+ duration?: number;
21
+ /**
22
+ * Direction of pointer swipe that should close the toast.
23
+ * @defaultValue 'right'
24
+ */
25
+ swipeDirection?: SwipeDirection;
26
+ /**
27
+ * Distance in pixels that the swipe must pass before a close is triggered.
28
+ * @defaultValue 50
29
+ */
30
+ swipeThreshold?: number;
31
+ }
32
+ declare const ToastProvider: React.FC<ToastProviderProps>;
33
+ type PrimitiveOrderedListProps = React.ComponentPropsWithoutRef<typeof Primitive.ol>;
34
+ interface ToastViewportProps extends PrimitiveOrderedListProps {
35
+ /**
36
+ * The keys to use as the keyboard shortcut that will move focus to the toast viewport.
37
+ * @defaultValue ['F8']
38
+ */
39
+ hotkey?: string[];
40
+ /**
41
+ * An author-localized label for the toast viewport to provide context for screen reader users
42
+ * when navigating page landmarks. The available `{hotkey}` placeholder will be replaced for you.
43
+ * @defaultValue 'Notifications ({hotkey})'
44
+ */
45
+ label?: string;
46
+ }
47
+ declare const ToastViewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
48
+ type ToastElement = ToastImplElement;
49
+ interface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {
50
+ open?: boolean;
51
+ defaultOpen?: boolean;
52
+ onOpenChange?(open: boolean): void;
53
+ /**
54
+ * Used to force mounting when more control is needed. Useful when
55
+ * controlling animation with React animation libraries.
56
+ */
57
+ forceMount?: true;
58
+ }
59
+ declare const Toast: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
60
+ type SwipeEvent = {
61
+ currentTarget: EventTarget & ToastElement;
62
+ } & Omit<CustomEvent<{
63
+ originalEvent: React.PointerEvent;
64
+ delta: {
65
+ x: number;
66
+ y: number;
67
+ };
68
+ }>, 'currentTarget'>;
69
+ type ToastImplElement = React.ElementRef<typeof Primitive.li>;
70
+ type DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer.Root>;
71
+ type ToastImplPrivateProps = {
72
+ open: boolean;
73
+ onClose(): void;
74
+ };
75
+ type PrimitiveListItemProps = React.ComponentPropsWithoutRef<typeof Primitive.li>;
76
+ interface ToastImplProps extends ToastImplPrivateProps, PrimitiveListItemProps {
77
+ type?: 'foreground' | 'background';
78
+ /**
79
+ * Time in milliseconds that toast should remain visible for. Overrides value
80
+ * given to `ToastProvider`.
81
+ */
82
+ duration?: number;
83
+ onEscapeKeyDown?: DismissableLayerProps['onEscapeKeyDown'];
84
+ onPause?(): void;
85
+ onResume?(): void;
86
+ onSwipeStart?(event: SwipeEvent): void;
87
+ onSwipeMove?(event: SwipeEvent): void;
88
+ onSwipeCancel?(event: SwipeEvent): void;
89
+ onSwipeEnd?(event: SwipeEvent): void;
90
+ }
91
+ type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
92
+ interface ToastTitleProps extends PrimitiveDivProps {
93
+ }
94
+ declare const ToastTitle: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
95
+ interface ToastDescriptionProps extends PrimitiveDivProps {
96
+ }
97
+ declare const ToastDescription: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
98
+ interface ToastActionProps extends ToastCloseProps {
99
+ /**
100
+ * A short description for an alternate way to carry out the action. For screen reader users
101
+ * who will not be able to navigate to the button easily/quickly.
102
+ * @example <ToastAction altText="Goto account settings to upgrade">Upgrade</ToastAction>
103
+ * @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
104
+ */
105
+ altText: string;
106
+ }
107
+ declare const ToastAction: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
108
+ type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
109
+ interface ToastCloseProps extends PrimitiveButtonProps {
110
+ }
111
+ declare const ToastClose: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
112
+ declare const Provider: React.FC<ToastProviderProps>;
113
+ declare const Viewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
114
+ declare const Root: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
115
+ declare const Title: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
116
+ declare const Description: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
117
+ declare const Action: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
118
+ declare const Close: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
119
+
120
+ export { Action, Close, Description, Provider, Root, Title, Toast, ToastAction, type ToastActionProps, ToastClose, type ToastCloseProps, ToastDescription, type ToastDescriptionProps, type ToastProps, ToastProvider, type ToastProviderProps, ToastTitle, type ToastTitleProps, ToastViewport, type ToastViewportProps, Viewport, createToastScope };