@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.
Files changed (144) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/starter/.storybook/main.ts +17 -22
  3. package/dist/starter/.storybook/manager-head.html +31 -31
  4. package/dist/starter/.storybook/manager.ts +133 -133
  5. package/dist/starter/.storybook/preview-head.html +12 -12
  6. package/dist/starter/.storybook/preview.tsx +79 -79
  7. package/dist/starter/biome.json +126 -0
  8. package/dist/starter/codegen.ts +11 -11
  9. package/dist/starter/components.json +27 -27
  10. package/dist/starter/package.json +86 -80
  11. package/dist/starter/public/mockServiceWorker.js +261 -261
  12. package/dist/starter/scripts/build-component-db.ts +17 -20
  13. package/dist/starter/src/App.tsx +15 -17
  14. package/dist/starter/src/components/ui/Accordion.stories.tsx +35 -35
  15. package/dist/starter/src/components/ui/Accordion.tsx +33 -33
  16. package/dist/starter/src/components/ui/Alert.stories.tsx +15 -15
  17. package/dist/starter/src/components/ui/Alert.tsx +32 -32
  18. package/dist/starter/src/components/ui/AlertDialog.stories.tsx +50 -50
  19. package/dist/starter/src/components/ui/AlertDialog.tsx +114 -115
  20. package/dist/starter/src/components/ui/AspectRatio.stories.tsx +20 -20
  21. package/dist/starter/src/components/ui/AspectRatio.tsx +1 -1
  22. package/dist/starter/src/components/ui/Avatar.stories.tsx +27 -27
  23. package/dist/starter/src/components/ui/Avatar.tsx +63 -63
  24. package/dist/starter/src/components/ui/Badge.stories.tsx +14 -14
  25. package/dist/starter/src/components/ui/Badge.tsx +27 -27
  26. package/dist/starter/src/components/ui/Breadcrumb.stories.tsx +38 -38
  27. package/dist/starter/src/components/ui/Breadcrumb.tsx +63 -62
  28. package/dist/starter/src/components/ui/Button.stories.tsx +55 -55
  29. package/dist/starter/src/components/ui/Button.tsx +49 -49
  30. package/dist/starter/src/components/ui/ButtonGroup.stories.tsx +17 -17
  31. package/dist/starter/src/components/ui/ButtonGroup.tsx +52 -53
  32. package/dist/starter/src/components/ui/Calendar.stories.tsx +20 -19
  33. package/dist/starter/src/components/ui/Calendar.tsx +142 -143
  34. package/dist/starter/src/components/ui/Card.stories.tsx +29 -29
  35. package/dist/starter/src/components/ui/Card.tsx +31 -31
  36. package/dist/starter/src/components/ui/Carousel.stories.tsx +41 -41
  37. package/dist/starter/src/components/ui/Carousel.tsx +171 -172
  38. package/dist/starter/src/components/ui/Chart.stories.tsx +21 -21
  39. package/dist/starter/src/components/ui/Chart.tsx +244 -247
  40. package/dist/starter/src/components/ui/Checkbox.stories.tsx +11 -11
  41. package/dist/starter/src/components/ui/Checkbox.tsx +18 -18
  42. package/dist/starter/src/components/ui/Collapsible.stories.tsx +40 -40
  43. package/dist/starter/src/components/ui/Collapsible.tsx +3 -3
  44. package/dist/starter/src/components/ui/Combobox.stories.tsx +48 -48
  45. package/dist/starter/src/components/ui/Combobox.tsx +204 -205
  46. package/dist/starter/src/components/ui/Command.stories.tsx +55 -55
  47. package/dist/starter/src/components/ui/Command.tsx +102 -103
  48. package/dist/starter/src/components/ui/ContextMenu.stories.tsx +52 -52
  49. package/dist/starter/src/components/ui/ContextMenu.tsx +151 -151
  50. package/dist/starter/src/components/ui/DesignSystem-Colors.stories.tsx +92 -92
  51. package/dist/starter/src/components/ui/DesignSystem-Layout.stories.tsx +139 -139
  52. package/dist/starter/src/components/ui/DesignSystem-Overview.stories.tsx +676 -657
  53. package/dist/starter/src/components/ui/DesignSystem-Typography.stories.tsx +59 -59
  54. package/dist/starter/src/components/ui/Dialog.stories.tsx +56 -56
  55. package/dist/starter/src/components/ui/Dialog.tsx +97 -98
  56. package/dist/starter/src/components/ui/Direction.stories.tsx +20 -20
  57. package/dist/starter/src/components/ui/Direction.tsx +7 -7
  58. package/dist/starter/src/components/ui/Drawer.stories.tsx +54 -54
  59. package/dist/starter/src/components/ui/Drawer.tsx +70 -70
  60. package/dist/starter/src/components/ui/DropdownMenu.stories.tsx +58 -58
  61. package/dist/starter/src/components/ui/DropdownMenu.tsx +157 -157
  62. package/dist/starter/src/components/ui/Empty.stories.tsx +22 -22
  63. package/dist/starter/src/components/ui/Empty.tsx +58 -58
  64. package/dist/starter/src/components/ui/Field.stories.tsx +31 -31
  65. package/dist/starter/src/components/ui/Field.tsx +180 -181
  66. package/dist/starter/src/components/ui/Form.stories.tsx +29 -29
  67. package/dist/starter/src/components/ui/Form.tsx +93 -96
  68. package/dist/starter/src/components/ui/HoverCard.stories.tsx +34 -34
  69. package/dist/starter/src/components/ui/HoverCard.tsx +21 -21
  70. package/dist/starter/src/components/ui/Input.stories.tsx +18 -18
  71. package/dist/starter/src/components/ui/Input.tsx +14 -14
  72. package/dist/starter/src/components/ui/InputGroup.stories.tsx +34 -34
  73. package/dist/starter/src/components/ui/InputGroup.tsx +110 -111
  74. package/dist/starter/src/components/ui/InputOTP.stories.tsx +28 -28
  75. package/dist/starter/src/components/ui/InputOTP.tsx +43 -43
  76. package/dist/starter/src/components/ui/Item.stories.tsx +45 -45
  77. package/dist/starter/src/components/ui/Item.tsx +113 -114
  78. package/dist/starter/src/components/ui/Kbd.stories.tsx +31 -31
  79. package/dist/starter/src/components/ui/Kbd.tsx +11 -11
  80. package/dist/starter/src/components/ui/Label.stories.tsx +62 -62
  81. package/dist/starter/src/components/ui/Label.tsx +26 -25
  82. package/dist/starter/src/components/ui/Menubar.stories.tsx +62 -62
  83. package/dist/starter/src/components/ui/Menubar.tsx +173 -173
  84. package/dist/starter/src/components/ui/NativeSelect.stories.tsx +26 -26
  85. package/dist/starter/src/components/ui/NativeSelect.tsx +29 -29
  86. package/dist/starter/src/components/ui/NavigationMenu.stories.tsx +64 -64
  87. package/dist/starter/src/components/ui/NavigationMenu.tsx +103 -103
  88. package/dist/starter/src/components/ui/Pagination.stories.tsx +61 -61
  89. package/dist/starter/src/components/ui/Pagination.tsx +69 -71
  90. package/dist/starter/src/components/ui/Popover.stories.tsx +38 -38
  91. package/dist/starter/src/components/ui/Popover.tsx +25 -25
  92. package/dist/starter/src/components/ui/Progress.stories.tsx +9 -9
  93. package/dist/starter/src/components/ui/Progress.tsx +14 -14
  94. package/dist/starter/src/components/ui/RadioGroup.stories.tsx +35 -35
  95. package/dist/starter/src/components/ui/RadioGroup.tsx +19 -19
  96. package/dist/starter/src/components/ui/Resizable.stories.tsx +54 -54
  97. package/dist/starter/src/components/ui/Resizable.tsx +29 -29
  98. package/dist/starter/src/components/ui/ScrollArea.stories.tsx +27 -27
  99. package/dist/starter/src/components/ui/ScrollArea.tsx +34 -34
  100. package/dist/starter/src/components/ui/Select.stories.tsx +43 -43
  101. package/dist/starter/src/components/ui/Select.tsx +120 -120
  102. package/dist/starter/src/components/ui/Separator.stories.tsx +27 -27
  103. package/dist/starter/src/components/ui/Separator.tsx +17 -17
  104. package/dist/starter/src/components/ui/Sheet.stories.tsx +53 -53
  105. package/dist/starter/src/components/ui/Sheet.tsx +69 -69
  106. package/dist/starter/src/components/ui/Sidebar.stories.tsx +77 -77
  107. package/dist/starter/src/components/ui/Sidebar.tsx +563 -564
  108. package/dist/starter/src/components/ui/Skeleton.stories.tsx +25 -25
  109. package/dist/starter/src/components/ui/Skeleton.tsx +1 -1
  110. package/dist/starter/src/components/ui/Slider.stories.tsx +5 -5
  111. package/dist/starter/src/components/ui/Slider.tsx +45 -44
  112. package/dist/starter/src/components/ui/Sonner.stories.tsx +32 -32
  113. package/dist/starter/src/components/ui/Sonner.tsx +23 -23
  114. package/dist/starter/src/components/ui/Spinner.stories.tsx +8 -8
  115. package/dist/starter/src/components/ui/Spinner.tsx +1 -1
  116. package/dist/starter/src/components/ui/Switch.stories.tsx +16 -17
  117. package/dist/starter/src/components/ui/Switch.tsx +24 -24
  118. package/dist/starter/src/components/ui/Table.stories.tsx +50 -50
  119. package/dist/starter/src/components/ui/Table.tsx +45 -45
  120. package/dist/starter/src/components/ui/Tabs.stories.tsx +39 -39
  121. package/dist/starter/src/components/ui/Tabs.tsx +47 -47
  122. package/dist/starter/src/components/ui/Textarea.stories.tsx +9 -9
  123. package/dist/starter/src/components/ui/Textarea.tsx +11 -11
  124. package/dist/starter/src/components/ui/Toast.stories.tsx +77 -77
  125. package/dist/starter/src/components/ui/Toast.tsx +75 -75
  126. package/dist/starter/src/components/ui/Toaster.tsx +17 -19
  127. package/dist/starter/src/components/ui/Toggle.stories.tsx +20 -20
  128. package/dist/starter/src/components/ui/Toggle.tsx +26 -26
  129. package/dist/starter/src/components/ui/ToggleGroup.stories.tsx +41 -41
  130. package/dist/starter/src/components/ui/ToggleGroup.tsx +61 -62
  131. package/dist/starter/src/components/ui/Tooltip.stories.tsx +26 -26
  132. package/dist/starter/src/components/ui/Tooltip.tsx +24 -24
  133. package/dist/starter/src/gql/execute.ts +1 -1
  134. package/dist/starter/src/gql/fragment-masking.ts +1 -1
  135. package/dist/starter/src/gql/graphql.ts +3 -0
  136. package/dist/starter/src/hooks/use-mobile.ts +11 -11
  137. package/dist/starter/src/hooks/use-toast.ts +135 -135
  138. package/dist/starter/src/index.css +105 -105
  139. package/dist/starter/src/lib/utils.ts +1 -1
  140. package/dist/starter/src/main.tsx +4 -1
  141. package/dist/starter/tsconfig.app.json +24 -24
  142. package/dist/starter/tsconfig.json +8 -8
  143. package/dist/starter/vite.config.ts +38 -37
  144. 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
- title: 'UI Components/Tooltip',
7
- component: Tooltip,
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
- 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
- ),
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
- 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
- ),
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
- return <TooltipPrimitive.Provider data-slot="tooltip-provider" delayDuration={delayDuration} {...props} />;
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
- return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;
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
- return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
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
- className,
26
- sideOffset = 0,
27
- children,
28
- ...props
25
+ className,
26
+ sideOffset = 0,
27
+ children,
28
+ ...props
29
29
  }: React.ComponentProps<typeof TooltipPrimitive.Content>) {
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
- );
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,5 +1,5 @@
1
1
  /* eslint-disable */
2
- import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core';
2
+ import { DocumentTypeDecoration, ResultOf } from '@graphql-typed-document-node/core';
3
3
  import { Incremental, TypedDocumentString } from './graphql';
4
4
 
5
5
 
@@ -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
- const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined);
6
+ const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined);
7
7
 
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
- }, []);
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
- return !!isMobile;
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
- id: string;
12
- title?: React.ReactNode;
13
- description?: React.ReactNode;
14
- action?: ToastActionElement;
11
+ id: string;
12
+ title?: React.ReactNode;
13
+ description?: React.ReactNode;
14
+ action?: ToastActionElement;
15
15
  };
16
16
 
17
17
  const actionTypes = {
18
- ADD_TOAST: 'ADD_TOAST',
19
- UPDATE_TOAST: 'UPDATE_TOAST',
20
- DISMISS_TOAST: 'DISMISS_TOAST',
21
- REMOVE_TOAST: 'REMOVE_TOAST',
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
- count = (count + 1) % Number.MAX_SAFE_INTEGER;
28
- return count.toString();
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
- 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
- };
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
- toasts: ToasterToast[];
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
- 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);
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
- 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
- state.toasts.forEach((toast) => {
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
- }
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
- memoryState = reducer(memoryState, action);
130
- listeners.forEach((listener) => {
131
- listener(memoryState);
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
- 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
- };
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
- 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
- }, [state]);
178
-
179
- return {
180
- ...state,
181
- toast,
182
- dismiss: (toastId?: string) => dispatch({ type: 'DISMISS_TOAST', toastId }),
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 };