@dust-tt/sparkle 0.2.576 → 0.2.577-rc-1

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 (35) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/esm/components/Dialog.d.ts +1 -0
  3. package/dist/esm/components/Dialog.d.ts.map +1 -1
  4. package/dist/esm/components/Dialog.js +10 -2
  5. package/dist/esm/components/Dialog.js.map +1 -1
  6. package/dist/esm/components/Dropdown.d.ts +1 -1
  7. package/dist/esm/components/Dropdown.d.ts.map +1 -1
  8. package/dist/esm/components/Dropdown.js +9 -3
  9. package/dist/esm/components/Dropdown.js.map +1 -1
  10. package/dist/esm/components/MultiPageDialog.d.ts +1 -0
  11. package/dist/esm/components/MultiPageDialog.d.ts.map +1 -1
  12. package/dist/esm/components/MultiPageDialog.js +2 -2
  13. package/dist/esm/components/MultiPageDialog.js.map +1 -1
  14. package/dist/esm/components/Popover.d.ts +1 -0
  15. package/dist/esm/components/Popover.d.ts.map +1 -1
  16. package/dist/esm/components/Popover.js +9 -3
  17. package/dist/esm/components/Popover.js.map +1 -1
  18. package/dist/esm/components/SearchDropdownMenu.d.ts.map +1 -1
  19. package/dist/esm/components/SearchDropdownMenu.js +1 -3
  20. package/dist/esm/components/SearchDropdownMenu.js.map +1 -1
  21. package/dist/esm/components/Sheet.d.ts +1 -0
  22. package/dist/esm/components/Sheet.d.ts.map +1 -1
  23. package/dist/esm/components/Sheet.js +8 -2
  24. package/dist/esm/components/Sheet.js.map +1 -1
  25. package/dist/esm/stories/Dropdown.stories.d.ts.map +1 -1
  26. package/dist/esm/stories/Dropdown.stories.js +1 -1
  27. package/dist/esm/stories/Dropdown.stories.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/components/Dialog.tsx +35 -17
  30. package/src/components/Dropdown.tsx +14 -1
  31. package/src/components/MultiPageDialog.tsx +3 -0
  32. package/src/components/Popover.tsx +13 -0
  33. package/src/components/SearchDropdownMenu.tsx +0 -3
  34. package/src/components/Sheet.tsx +46 -18
  35. package/src/stories/Dropdown.stories.tsx +6 -1
@@ -78,6 +78,7 @@ interface DialogContentProps
78
78
  height?: DialogHeightType;
79
79
  trapFocusScope?: boolean;
80
80
  isAlertDialog?: boolean;
81
+ preventAutoFocusOnClose?: boolean;
81
82
  }
82
83
 
83
84
  const DialogContent = React.forwardRef<
@@ -92,26 +93,43 @@ const DialogContent = React.forwardRef<
92
93
  height,
93
94
  trapFocusScope,
94
95
  isAlertDialog,
96
+ preventAutoFocusOnClose = true,
97
+ onCloseAutoFocus,
95
98
  ...props
96
99
  },
97
100
  ref
98
- ) => (
99
- <DialogPortal>
100
- <DialogOverlay />
101
- <FocusScope trapped={trapFocusScope} asChild>
102
- <DialogPrimitive.Content
103
- ref={ref}
104
- className={cn(dialogVariants({ size, height }), className)}
105
- onInteractOutside={
106
- isAlertDialog ? (e) => e.preventDefault() : props.onInteractOutside
107
- }
108
- {...props}
109
- >
110
- {children}
111
- </DialogPrimitive.Content>
112
- </FocusScope>
113
- </DialogPortal>
114
- )
101
+ ) => {
102
+ const handleCloseAutoFocus = React.useCallback(
103
+ (event: Event) => {
104
+ if (preventAutoFocusOnClose) {
105
+ event.preventDefault();
106
+ }
107
+ onCloseAutoFocus?.(event);
108
+ },
109
+ [preventAutoFocusOnClose, onCloseAutoFocus]
110
+ );
111
+
112
+ return (
113
+ <DialogPortal>
114
+ <DialogOverlay />
115
+ <FocusScope trapped={trapFocusScope} asChild>
116
+ <DialogPrimitive.Content
117
+ ref={ref}
118
+ className={cn(dialogVariants({ size, height }), className)}
119
+ onInteractOutside={
120
+ isAlertDialog
121
+ ? (e) => e.preventDefault()
122
+ : props.onInteractOutside
123
+ }
124
+ onCloseAutoFocus={handleCloseAutoFocus}
125
+ {...props}
126
+ >
127
+ {children}
128
+ </DialogPrimitive.Content>
129
+ </FocusScope>
130
+ </DialogPortal>
131
+ );
132
+ }
115
133
  );
116
134
  DialogContent.displayName = DialogPrimitive.Content.displayName;
117
135
 
@@ -244,7 +244,7 @@ interface DropdownMenuContentProps
244
244
  mountPortal?: boolean;
245
245
  mountPortalContainer?: HTMLElement;
246
246
  dropdownHeaders?: React.ReactNode;
247
- onOpenAutoFocus?: (e: React.FocusEvent<HTMLDivElement>) => void;
247
+ preventAutoFocusOnClose?: boolean;
248
248
  }
249
249
 
250
250
  const DropdownMenuContent = React.forwardRef<
@@ -258,11 +258,23 @@ const DropdownMenuContent = React.forwardRef<
258
258
  mountPortal = true,
259
259
  mountPortalContainer,
260
260
  dropdownHeaders,
261
+ preventAutoFocusOnClose = true,
262
+ onCloseAutoFocus,
261
263
  children,
262
264
  ...props
263
265
  },
264
266
  ref
265
267
  ) => {
268
+ const handleCloseAutoFocus = React.useCallback(
269
+ (event: Event) => {
270
+ if (preventAutoFocusOnClose) {
271
+ event.preventDefault();
272
+ }
273
+ onCloseAutoFocus?.(event);
274
+ },
275
+ [preventAutoFocusOnClose, onCloseAutoFocus]
276
+ );
277
+
266
278
  const content = (
267
279
  <DropdownMenuPrimitive.Content
268
280
  ref={ref}
@@ -273,6 +285,7 @@ const DropdownMenuContent = React.forwardRef<
273
285
  dropdownHeaders && "s-h-80 xs:s-h-96", // We use dropdownHeaders for putting search bar, so we can set the height for the container
274
286
  className
275
287
  )}
288
+ onCloseAutoFocus={handleCloseAutoFocus}
276
289
  {...props}
277
290
  >
278
291
  <div className="s-sticky s-top-0 s-bg-background dark:s-bg-background-night">
@@ -85,6 +85,7 @@ interface MultiPageDialogProps {
85
85
  height?: React.ComponentProps<typeof DialogContent>["height"];
86
86
  trapFocusScope?: boolean;
87
87
  isAlertDialog?: boolean;
88
+ preventAutoFocusOnClose?: boolean;
88
89
  showNavigation?: boolean;
89
90
  showHeaderNavigation?: boolean;
90
91
  className?: string;
@@ -113,6 +114,7 @@ const MultiPageDialogContent = React.forwardRef<
113
114
  height,
114
115
  trapFocusScope,
115
116
  isAlertDialog,
117
+ preventAutoFocusOnClose,
116
118
  showNavigation = true,
117
119
  showHeaderNavigation = true,
118
120
  className,
@@ -179,6 +181,7 @@ const MultiPageDialogContent = React.forwardRef<
179
181
  height={height}
180
182
  trapFocusScope={trapFocusScope}
181
183
  isAlertDialog={isAlertDialog}
184
+ preventAutoFocusOnClose={preventAutoFocusOnClose}
182
185
  className={className}
183
186
  {...props}
184
187
  >
@@ -14,6 +14,7 @@ export interface PopoverContentProps
14
14
  fullWidth?: boolean;
15
15
  mountPortal?: boolean;
16
16
  mountPortalContainer?: HTMLElement;
17
+ preventAutoFocusOnClose?: boolean;
17
18
  }
18
19
 
19
20
  const PopoverContent = React.forwardRef<
@@ -28,10 +29,21 @@ const PopoverContent = React.forwardRef<
28
29
  mountPortal = true,
29
30
  mountPortalContainer,
30
31
  fullWidth = false,
32
+ preventAutoFocusOnClose = true,
33
+ onCloseAutoFocus,
31
34
  ...props
32
35
  },
33
36
  ref
34
37
  ) => {
38
+ const handleCloseAutoFocus = React.useCallback(
39
+ (event: Event) => {
40
+ if (preventAutoFocusOnClose) {
41
+ event.preventDefault();
42
+ }
43
+ onCloseAutoFocus?.(event);
44
+ },
45
+ [preventAutoFocusOnClose, onCloseAutoFocus]
46
+ );
35
47
  const content = (
36
48
  <PopoverPrimitive.Content
37
49
  ref={ref}
@@ -51,6 +63,7 @@ const PopoverContent = React.forwardRef<
51
63
  fullWidth ? "s-grow" : "s-w-72 s-p-4",
52
64
  className
53
65
  )}
66
+ onCloseAutoFocus={handleCloseAutoFocus}
54
67
  {...props}
55
68
  />
56
69
  );
@@ -79,9 +79,6 @@ export function SearchDropdownMenu({
79
79
  />
80
80
  </DropdownMenuTrigger>
81
81
  <DropdownMenuContent
82
- onOpenAutoFocus={(e) => {
83
- e.preventDefault();
84
- }}
85
82
  side="bottom"
86
83
  align="start"
87
84
  className="s-w-[--radix-popper-anchor-width]"
@@ -87,29 +87,57 @@ interface SheetContentProps
87
87
  size?: SheetSizeType;
88
88
  trapFocusScope?: boolean;
89
89
  side?: SheetSideType;
90
+ preventAutoFocusOnClose?: boolean;
90
91
  }
91
92
 
92
93
  const SheetContent = React.forwardRef<
93
94
  React.ElementRef<typeof SheetPrimitive.Content>,
94
95
  SheetContentProps
95
- >(({ className, children, size, side, trapFocusScope, ...props }, ref) => (
96
- <SheetPortal>
97
- <SheetOverlay />
98
- <FocusScope trapped={trapFocusScope} asChild>
99
- <SheetPrimitive.Content
100
- ref={ref}
101
- className={cn(
102
- sheetVariants({ size, side }),
103
- className,
104
- "s-sheet s-text-foreground dark:s-text-foreground-night"
105
- )}
106
- {...props}
107
- >
108
- {children}
109
- </SheetPrimitive.Content>
110
- </FocusScope>
111
- </SheetPortal>
112
- ));
96
+ >(
97
+ (
98
+ {
99
+ className,
100
+ children,
101
+ size,
102
+ side,
103
+ trapFocusScope,
104
+ preventAutoFocusOnClose = true,
105
+ onCloseAutoFocus,
106
+ ...props
107
+ },
108
+ ref
109
+ ) => {
110
+ const handleCloseAutoFocus = React.useCallback(
111
+ (event: Event) => {
112
+ if (preventAutoFocusOnClose) {
113
+ event.preventDefault();
114
+ }
115
+ onCloseAutoFocus?.(event);
116
+ },
117
+ [preventAutoFocusOnClose, onCloseAutoFocus]
118
+ );
119
+
120
+ return (
121
+ <SheetPortal>
122
+ <SheetOverlay />
123
+ <FocusScope trapped={trapFocusScope} asChild>
124
+ <SheetPrimitive.Content
125
+ ref={ref}
126
+ className={cn(
127
+ sheetVariants({ size, side }),
128
+ className,
129
+ "s-sheet s-text-foreground dark:s-text-foreground-night"
130
+ )}
131
+ onCloseAutoFocus={handleCloseAutoFocus}
132
+ {...props}
133
+ >
134
+ {children}
135
+ </SheetPrimitive.Content>
136
+ </FocusScope>
137
+ </SheetPortal>
138
+ );
139
+ }
140
+ );
113
141
  SheetContent.displayName = SheetPrimitive.Content.displayName;
114
142
 
115
143
  interface SheetHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
@@ -309,7 +309,12 @@ function ModelsDropdownDemo() {
309
309
  return (
310
310
  <DropdownMenu>
311
311
  <DropdownMenuTrigger asChild>
312
- <Button label={selectedModel} variant="outline" size="sm" />
312
+ <Button
313
+ label={selectedModel}
314
+ variant="outline"
315
+ size="sm"
316
+ tooltip="Test"
317
+ />
313
318
  </DropdownMenuTrigger>
314
319
  <DropdownMenuContent>
315
320
  <DropdownMenuLabel label="Best performing models" />