@auto-engineer/generate-react-client 1.64.0 → 1.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/starter/.storybook/main.ts +17 -22
- package/dist/starter/.storybook/manager-head.html +31 -31
- package/dist/starter/.storybook/manager.ts +133 -133
- package/dist/starter/.storybook/preview-head.html +12 -12
- package/dist/starter/.storybook/preview.tsx +79 -79
- package/dist/starter/biome.json +126 -0
- package/dist/starter/codegen.ts +11 -11
- package/dist/starter/components.json +27 -27
- package/dist/starter/package.json +86 -80
- package/dist/starter/public/mockServiceWorker.js +261 -261
- package/dist/starter/scripts/build-component-db.ts +17 -20
- package/dist/starter/src/App.tsx +15 -17
- package/dist/starter/src/components/ui/Accordion.stories.tsx +35 -35
- package/dist/starter/src/components/ui/Accordion.tsx +33 -33
- package/dist/starter/src/components/ui/Alert.stories.tsx +15 -15
- package/dist/starter/src/components/ui/Alert.tsx +32 -32
- package/dist/starter/src/components/ui/AlertDialog.stories.tsx +50 -50
- package/dist/starter/src/components/ui/AlertDialog.tsx +114 -115
- package/dist/starter/src/components/ui/AspectRatio.stories.tsx +20 -20
- package/dist/starter/src/components/ui/AspectRatio.tsx +1 -1
- package/dist/starter/src/components/ui/Avatar.stories.tsx +27 -27
- package/dist/starter/src/components/ui/Avatar.tsx +63 -63
- package/dist/starter/src/components/ui/Badge.stories.tsx +14 -14
- package/dist/starter/src/components/ui/Badge.tsx +27 -27
- package/dist/starter/src/components/ui/Breadcrumb.stories.tsx +38 -38
- package/dist/starter/src/components/ui/Breadcrumb.tsx +63 -62
- package/dist/starter/src/components/ui/Button.stories.tsx +55 -55
- package/dist/starter/src/components/ui/Button.tsx +49 -49
- package/dist/starter/src/components/ui/ButtonGroup.stories.tsx +17 -17
- package/dist/starter/src/components/ui/ButtonGroup.tsx +52 -53
- package/dist/starter/src/components/ui/Calendar.stories.tsx +20 -19
- package/dist/starter/src/components/ui/Calendar.tsx +142 -143
- package/dist/starter/src/components/ui/Card.stories.tsx +29 -29
- package/dist/starter/src/components/ui/Card.tsx +31 -31
- package/dist/starter/src/components/ui/Carousel.stories.tsx +41 -41
- package/dist/starter/src/components/ui/Carousel.tsx +171 -172
- package/dist/starter/src/components/ui/Chart.stories.tsx +21 -21
- package/dist/starter/src/components/ui/Chart.tsx +244 -247
- package/dist/starter/src/components/ui/Checkbox.stories.tsx +11 -11
- package/dist/starter/src/components/ui/Checkbox.tsx +18 -18
- package/dist/starter/src/components/ui/Collapsible.stories.tsx +40 -40
- package/dist/starter/src/components/ui/Collapsible.tsx +3 -3
- package/dist/starter/src/components/ui/Combobox.stories.tsx +48 -48
- package/dist/starter/src/components/ui/Combobox.tsx +204 -205
- package/dist/starter/src/components/ui/Command.stories.tsx +55 -55
- package/dist/starter/src/components/ui/Command.tsx +102 -103
- package/dist/starter/src/components/ui/ContextMenu.stories.tsx +52 -52
- package/dist/starter/src/components/ui/ContextMenu.tsx +151 -151
- package/dist/starter/src/components/ui/DesignSystem-Colors.stories.tsx +92 -92
- package/dist/starter/src/components/ui/DesignSystem-Layout.stories.tsx +139 -139
- package/dist/starter/src/components/ui/DesignSystem-Overview.stories.tsx +676 -657
- package/dist/starter/src/components/ui/DesignSystem-Typography.stories.tsx +59 -59
- package/dist/starter/src/components/ui/Dialog.stories.tsx +56 -56
- package/dist/starter/src/components/ui/Dialog.tsx +97 -98
- package/dist/starter/src/components/ui/Direction.stories.tsx +20 -20
- package/dist/starter/src/components/ui/Direction.tsx +7 -7
- package/dist/starter/src/components/ui/Drawer.stories.tsx +54 -54
- package/dist/starter/src/components/ui/Drawer.tsx +70 -70
- package/dist/starter/src/components/ui/DropdownMenu.stories.tsx +58 -58
- package/dist/starter/src/components/ui/DropdownMenu.tsx +157 -157
- package/dist/starter/src/components/ui/Empty.stories.tsx +22 -22
- package/dist/starter/src/components/ui/Empty.tsx +58 -58
- package/dist/starter/src/components/ui/Field.stories.tsx +31 -31
- package/dist/starter/src/components/ui/Field.tsx +180 -181
- package/dist/starter/src/components/ui/Form.stories.tsx +29 -29
- package/dist/starter/src/components/ui/Form.tsx +93 -96
- package/dist/starter/src/components/ui/HoverCard.stories.tsx +34 -34
- package/dist/starter/src/components/ui/HoverCard.tsx +21 -21
- package/dist/starter/src/components/ui/Input.stories.tsx +18 -18
- package/dist/starter/src/components/ui/Input.tsx +14 -14
- package/dist/starter/src/components/ui/InputGroup.stories.tsx +34 -34
- package/dist/starter/src/components/ui/InputGroup.tsx +110 -111
- package/dist/starter/src/components/ui/InputOTP.stories.tsx +28 -28
- package/dist/starter/src/components/ui/InputOTP.tsx +43 -43
- package/dist/starter/src/components/ui/Item.stories.tsx +45 -45
- package/dist/starter/src/components/ui/Item.tsx +113 -114
- package/dist/starter/src/components/ui/Kbd.stories.tsx +31 -31
- package/dist/starter/src/components/ui/Kbd.tsx +11 -11
- package/dist/starter/src/components/ui/Label.stories.tsx +62 -62
- package/dist/starter/src/components/ui/Label.tsx +26 -25
- package/dist/starter/src/components/ui/Menubar.stories.tsx +62 -62
- package/dist/starter/src/components/ui/Menubar.tsx +173 -173
- package/dist/starter/src/components/ui/NativeSelect.stories.tsx +26 -26
- package/dist/starter/src/components/ui/NativeSelect.tsx +29 -29
- package/dist/starter/src/components/ui/NavigationMenu.stories.tsx +64 -64
- package/dist/starter/src/components/ui/NavigationMenu.tsx +103 -103
- package/dist/starter/src/components/ui/Pagination.stories.tsx +61 -61
- package/dist/starter/src/components/ui/Pagination.tsx +69 -71
- package/dist/starter/src/components/ui/Popover.stories.tsx +38 -38
- package/dist/starter/src/components/ui/Popover.tsx +25 -25
- package/dist/starter/src/components/ui/Progress.stories.tsx +9 -9
- package/dist/starter/src/components/ui/Progress.tsx +14 -14
- package/dist/starter/src/components/ui/RadioGroup.stories.tsx +35 -35
- package/dist/starter/src/components/ui/RadioGroup.tsx +19 -19
- package/dist/starter/src/components/ui/Resizable.stories.tsx +54 -54
- package/dist/starter/src/components/ui/Resizable.tsx +29 -29
- package/dist/starter/src/components/ui/ScrollArea.stories.tsx +27 -27
- package/dist/starter/src/components/ui/ScrollArea.tsx +34 -34
- package/dist/starter/src/components/ui/Select.stories.tsx +43 -43
- package/dist/starter/src/components/ui/Select.tsx +120 -120
- package/dist/starter/src/components/ui/Separator.stories.tsx +27 -27
- package/dist/starter/src/components/ui/Separator.tsx +17 -17
- package/dist/starter/src/components/ui/Sheet.stories.tsx +53 -53
- package/dist/starter/src/components/ui/Sheet.tsx +69 -69
- package/dist/starter/src/components/ui/Sidebar.stories.tsx +77 -77
- package/dist/starter/src/components/ui/Sidebar.tsx +563 -564
- package/dist/starter/src/components/ui/Skeleton.stories.tsx +25 -25
- package/dist/starter/src/components/ui/Skeleton.tsx +1 -1
- package/dist/starter/src/components/ui/Slider.stories.tsx +5 -5
- package/dist/starter/src/components/ui/Slider.tsx +45 -44
- package/dist/starter/src/components/ui/Sonner.stories.tsx +32 -32
- package/dist/starter/src/components/ui/Sonner.tsx +23 -23
- package/dist/starter/src/components/ui/Spinner.stories.tsx +8 -8
- package/dist/starter/src/components/ui/Spinner.tsx +1 -1
- package/dist/starter/src/components/ui/Switch.stories.tsx +16 -17
- package/dist/starter/src/components/ui/Switch.tsx +24 -24
- package/dist/starter/src/components/ui/Table.stories.tsx +50 -50
- package/dist/starter/src/components/ui/Table.tsx +45 -45
- package/dist/starter/src/components/ui/Tabs.stories.tsx +39 -39
- package/dist/starter/src/components/ui/Tabs.tsx +47 -47
- package/dist/starter/src/components/ui/Textarea.stories.tsx +9 -9
- package/dist/starter/src/components/ui/Textarea.tsx +11 -11
- package/dist/starter/src/components/ui/Toast.stories.tsx +77 -77
- package/dist/starter/src/components/ui/Toast.tsx +75 -75
- package/dist/starter/src/components/ui/Toaster.tsx +17 -19
- package/dist/starter/src/components/ui/Toggle.stories.tsx +20 -20
- package/dist/starter/src/components/ui/Toggle.tsx +26 -26
- package/dist/starter/src/components/ui/ToggleGroup.stories.tsx +41 -41
- package/dist/starter/src/components/ui/ToggleGroup.tsx +61 -62
- package/dist/starter/src/components/ui/Tooltip.stories.tsx +26 -26
- package/dist/starter/src/components/ui/Tooltip.tsx +24 -24
- package/dist/starter/src/gql/execute.ts +1 -1
- package/dist/starter/src/gql/fragment-masking.ts +1 -1
- package/dist/starter/src/gql/graphql.ts +3 -0
- package/dist/starter/src/hooks/use-mobile.ts +11 -11
- package/dist/starter/src/hooks/use-toast.ts +135 -135
- package/dist/starter/src/index.css +105 -105
- package/dist/starter/src/lib/utils.ts +1 -1
- package/dist/starter/src/main.tsx +4 -1
- package/dist/starter/tsconfig.app.json +24 -24
- package/dist/starter/tsconfig.json +8 -8
- package/dist/starter/vite.config.ts +38 -37
- package/package.json +3 -3
|
@@ -3,40 +3,40 @@ import { Button } from '@/components/ui/Button';
|
|
|
3
3
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/Tooltip';
|
|
4
4
|
|
|
5
5
|
const meta: Meta<typeof Tooltip> = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
title: 'UI Components/Tooltip',
|
|
7
|
+
component: Tooltip,
|
|
8
8
|
};
|
|
9
9
|
export default meta;
|
|
10
10
|
type Story = StoryObj<typeof Tooltip>;
|
|
11
11
|
|
|
12
12
|
/** Shows a basic tooltip appearing on hover over a button. */
|
|
13
13
|
export const Default: Story = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
render: () => (
|
|
15
|
+
<TooltipProvider>
|
|
16
|
+
<Tooltip>
|
|
17
|
+
<TooltipTrigger asChild>
|
|
18
|
+
<Button variant="outline">Hover me</Button>
|
|
19
|
+
</TooltipTrigger>
|
|
20
|
+
<TooltipContent>
|
|
21
|
+
<p>This is a tooltip</p>
|
|
22
|
+
</TooltipContent>
|
|
23
|
+
</Tooltip>
|
|
24
|
+
</TooltipProvider>
|
|
25
|
+
),
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
/** Shows a tooltip with additional spacing between the trigger and content via sideOffset. */
|
|
29
29
|
export const WithSideOffset: Story = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
render: () => (
|
|
31
|
+
<TooltipProvider>
|
|
32
|
+
<Tooltip>
|
|
33
|
+
<TooltipTrigger asChild>
|
|
34
|
+
<Button variant="outline">With offset</Button>
|
|
35
|
+
</TooltipTrigger>
|
|
36
|
+
<TooltipContent sideOffset={8}>
|
|
37
|
+
<p>Tooltip with side offset</p>
|
|
38
|
+
</TooltipContent>
|
|
39
|
+
</Tooltip>
|
|
40
|
+
</TooltipProvider>
|
|
41
|
+
),
|
|
42
42
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { Tooltip as TooltipPrimitive } from 'radix-ui';
|
|
2
|
+
import type * as React from 'react';
|
|
3
3
|
|
|
4
4
|
import { cn } from '@/lib/utils';
|
|
5
5
|
|
|
@@ -7,42 +7,42 @@ import { cn } from '@/lib/utils';
|
|
|
7
7
|
|
|
8
8
|
/** Provides shared tooltip configuration (e.g., delay duration) for all nested Tooltip instances. */
|
|
9
9
|
function TooltipProvider({ delayDuration = 0, ...props }: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
|
10
|
-
|
|
10
|
+
return <TooltipPrimitive.Provider data-slot="tooltip-provider" delayDuration={delayDuration} {...props} />;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/** The root component that manages open/close state for a single tooltip. */
|
|
14
14
|
function Tooltip({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
|
15
|
-
|
|
15
|
+
return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** The element that triggers the tooltip on hover or focus. */
|
|
19
19
|
function TooltipTrigger({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
|
20
|
-
|
|
20
|
+
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/** The popup content panel rendered via a portal with an arrow indicator. */
|
|
24
24
|
function TooltipContent({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
className,
|
|
26
|
+
sideOffset = 0,
|
|
27
|
+
children,
|
|
28
|
+
...props
|
|
29
29
|
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
return (
|
|
31
|
+
<TooltipPrimitive.Portal>
|
|
32
|
+
<TooltipPrimitive.Content
|
|
33
|
+
data-slot="tooltip-content"
|
|
34
|
+
sideOffset={sideOffset}
|
|
35
|
+
className={cn(
|
|
36
|
+
'bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance',
|
|
37
|
+
className,
|
|
38
|
+
)}
|
|
39
|
+
{...props}
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
<TooltipPrimitive.Arrow className="bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
|
|
43
|
+
</TooltipPrimitive.Content>
|
|
44
|
+
</TooltipPrimitive.Portal>
|
|
45
|
+
);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
@@ -3,7 +3,7 @@ import type { TypedDocumentString } from './graphql';
|
|
|
3
3
|
|
|
4
4
|
const GRAPHQL_ENDPOINT = 'http://localhost:4000/graphql';
|
|
5
5
|
|
|
6
|
-
export async function execute<TResult, TVariables
|
|
6
|
+
export async function execute<TResult, TVariables extends Record<string, unknown>>(
|
|
7
7
|
query: TypedDocumentString<TResult, TVariables>,
|
|
8
8
|
...[variables]: TVariables extends Record<string, never> ? [] : [TVariables]
|
|
9
9
|
): Promise<TResult> {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
+
interface DocumentTypeDecoration<TResult, TVariables> {
|
|
3
|
+
__apiType?: (variables: TVariables) => TResult;
|
|
4
|
+
}
|
|
2
5
|
export type Maybe<T> = T | null;
|
|
3
6
|
export type InputMaybe<T> = T | null | undefined;
|
|
4
7
|
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
|
|
@@ -3,17 +3,17 @@ import * as React from 'react';
|
|
|
3
3
|
const MOBILE_BREAKPOINT = 768;
|
|
4
4
|
|
|
5
5
|
export function useIsMobile() {
|
|
6
|
-
|
|
6
|
+
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined);
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
10
|
+
const onChange = () => {
|
|
11
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
12
|
+
};
|
|
13
|
+
mql.addEventListener('change', onChange);
|
|
14
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
15
|
+
return () => mql.removeEventListener('change', onChange);
|
|
16
|
+
}, []);
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
return !!isMobile;
|
|
19
19
|
}
|
|
@@ -8,117 +8,117 @@ const TOAST_LIMIT = 1;
|
|
|
8
8
|
const TOAST_REMOVE_DELAY = 1000000;
|
|
9
9
|
|
|
10
10
|
type ToasterToast = ToastProps & {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
id: string;
|
|
12
|
+
title?: React.ReactNode;
|
|
13
|
+
description?: React.ReactNode;
|
|
14
|
+
action?: ToastActionElement;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
const actionTypes = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
ADD_TOAST: 'ADD_TOAST',
|
|
19
|
+
UPDATE_TOAST: 'UPDATE_TOAST',
|
|
20
|
+
DISMISS_TOAST: 'DISMISS_TOAST',
|
|
21
|
+
REMOVE_TOAST: 'REMOVE_TOAST',
|
|
22
22
|
} as const;
|
|
23
23
|
|
|
24
24
|
let count = 0;
|
|
25
25
|
|
|
26
26
|
function genId() {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
count = (count + 1) % Number.MAX_SAFE_INTEGER;
|
|
28
|
+
return count.toString();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
type ActionType = typeof actionTypes;
|
|
32
32
|
|
|
33
33
|
type Action =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
| {
|
|
35
|
+
type: ActionType['ADD_TOAST'];
|
|
36
|
+
toast: ToasterToast;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
type: ActionType['UPDATE_TOAST'];
|
|
40
|
+
toast: Partial<ToasterToast>;
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
type: ActionType['DISMISS_TOAST'];
|
|
44
|
+
toastId?: ToasterToast['id'];
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
type: ActionType['REMOVE_TOAST'];
|
|
48
|
+
toastId?: ToasterToast['id'];
|
|
49
|
+
};
|
|
50
50
|
|
|
51
51
|
interface State {
|
|
52
|
-
|
|
52
|
+
toasts: ToasterToast[];
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>();
|
|
56
56
|
|
|
57
57
|
const addToRemoveQueue = (toastId: string) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
if (toastTimeouts.has(toastId)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const timeout = setTimeout(() => {
|
|
63
|
+
toastTimeouts.delete(toastId);
|
|
64
|
+
dispatch({
|
|
65
|
+
type: 'REMOVE_TOAST',
|
|
66
|
+
toastId: toastId,
|
|
67
|
+
});
|
|
68
|
+
}, TOAST_REMOVE_DELAY);
|
|
69
|
+
|
|
70
|
+
toastTimeouts.set(toastId, timeout);
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
export const reducer = (state: State, action: Action): State => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
74
|
+
switch (action.type) {
|
|
75
|
+
case 'ADD_TOAST':
|
|
76
|
+
return {
|
|
77
|
+
...state,
|
|
78
|
+
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
case 'UPDATE_TOAST':
|
|
82
|
+
return {
|
|
83
|
+
...state,
|
|
84
|
+
toasts: state.toasts.map((t) => (t.id === action.toast.id ? { ...t, ...action.toast } : t)),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
case 'DISMISS_TOAST': {
|
|
88
|
+
const { toastId } = action;
|
|
89
|
+
|
|
90
|
+
if (toastId) {
|
|
91
|
+
addToRemoveQueue(toastId);
|
|
92
|
+
} else {
|
|
93
|
+
for (const toast of state.toasts) {
|
|
94
|
+
addToRemoveQueue(toast.id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
...state,
|
|
100
|
+
toasts: state.toasts.map((t) =>
|
|
101
|
+
t.id === toastId || toastId === undefined
|
|
102
|
+
? {
|
|
103
|
+
...t,
|
|
104
|
+
open: false,
|
|
105
|
+
}
|
|
106
|
+
: t,
|
|
107
|
+
),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
case 'REMOVE_TOAST':
|
|
111
|
+
if (action.toastId === undefined) {
|
|
112
|
+
return {
|
|
113
|
+
...state,
|
|
114
|
+
toasts: [],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
...state,
|
|
119
|
+
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
const listeners: Array<(state: State) => void> = [];
|
|
@@ -126,61 +126,61 @@ const listeners: Array<(state: State) => void> = [];
|
|
|
126
126
|
let memoryState: State = { toasts: [] };
|
|
127
127
|
|
|
128
128
|
function dispatch(action: Action) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
memoryState = reducer(memoryState, action);
|
|
130
|
+
for (const listener of listeners) {
|
|
131
|
+
listener(memoryState);
|
|
132
|
+
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
type Toast = Omit<ToasterToast, 'id'>;
|
|
136
136
|
|
|
137
137
|
function toast({ ...props }: Toast) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
138
|
+
const id = genId();
|
|
139
|
+
|
|
140
|
+
const update = (props: ToasterToast) =>
|
|
141
|
+
dispatch({
|
|
142
|
+
type: 'UPDATE_TOAST',
|
|
143
|
+
toast: { ...props, id },
|
|
144
|
+
});
|
|
145
|
+
const dismiss = () => dispatch({ type: 'DISMISS_TOAST', toastId: id });
|
|
146
|
+
|
|
147
|
+
dispatch({
|
|
148
|
+
type: 'ADD_TOAST',
|
|
149
|
+
toast: {
|
|
150
|
+
...props,
|
|
151
|
+
id,
|
|
152
|
+
open: true,
|
|
153
|
+
onOpenChange: (open) => {
|
|
154
|
+
if (!open) dismiss();
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
id: id,
|
|
161
|
+
dismiss,
|
|
162
|
+
update,
|
|
163
|
+
};
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
function useToast() {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
167
|
+
const [state, setState] = React.useState<State>(memoryState);
|
|
168
|
+
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
listeners.push(setState);
|
|
171
|
+
return () => {
|
|
172
|
+
const index = listeners.indexOf(setState);
|
|
173
|
+
if (index > -1) {
|
|
174
|
+
listeners.splice(index, 1);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
...state,
|
|
181
|
+
toast,
|
|
182
|
+
dismiss: (toastId?: string) => dispatch({ type: 'DISMISS_TOAST', toastId }),
|
|
183
|
+
};
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
export { useToast, toast };
|