@designa8/vibedesign-v6 1.15.3 → 1.20.12

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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +3232 -1994
  3. package/dist/index.js +3242 -2004
  4. package/dist/styles.css +266 -28
  5. package/package.json +51 -1
  6. package/src/atoms/AppLayout/AppLayout.tsx +401 -395
  7. package/src/atoms/AppLayout/preview.tsx +29 -0
  8. package/src/atoms/AppSidebar/AppSidebar.tsx +182 -94
  9. package/src/atoms/AppSidebar/preview.tsx +20 -59
  10. package/src/atoms/AppSidebarMobile/AppSidebarMobile.tsx +27 -73
  11. package/src/atoms/AppSidebarMobile/preview.tsx +18 -18
  12. package/src/atoms/AuthLogin/AuthLogin.tsx +200 -0
  13. package/src/atoms/AuthLogin/index.ts +2 -0
  14. package/src/atoms/AuthLogin/preview.tsx +22 -0
  15. package/src/atoms/AuthScreen/AuthScreen.tsx +7 -7
  16. package/src/atoms/AuthSignUp/AuthSignUp.tsx +243 -0
  17. package/src/atoms/AuthSignUp/index.ts +2 -0
  18. package/src/atoms/AuthSignUp/preview.tsx +22 -0
  19. package/src/atoms/BillingToggle/BillingToggle.tsx +65 -0
  20. package/src/atoms/BillingToggle/index.ts +2 -0
  21. package/src/atoms/BillingToggle/preview.tsx +23 -0
  22. package/src/atoms/Button/Button.tsx +33 -17
  23. package/src/atoms/Button/preview.tsx +16 -0
  24. package/src/atoms/ChatHistorySidebar/ChatHistorySidebar.tsx +370 -0
  25. package/src/atoms/ChatHistorySidebar/index.ts +2 -0
  26. package/src/atoms/ChatHistorySidebar/preview.tsx +60 -0
  27. package/src/atoms/ChatScreen/ChatScreen.tsx +331 -134
  28. package/src/atoms/ChatScreen/preview.tsx +123 -2
  29. package/src/atoms/Checkbox/Checkbox.tsx +89 -0
  30. package/src/atoms/Checkbox/index.ts +2 -0
  31. package/src/atoms/Checkbox/preview.tsx +60 -0
  32. package/src/atoms/Dropdown/Dropdown.tsx +195 -0
  33. package/src/atoms/Dropdown/index.ts +2 -0
  34. package/src/atoms/Dropdown/preview.tsx +56 -0
  35. package/src/atoms/FaqAccordionItem/FaqAccordionItem.tsx +60 -0
  36. package/src/atoms/FaqAccordionItem/index.ts +2 -0
  37. package/src/atoms/FaqAccordionItem/preview.tsx +26 -0
  38. package/src/atoms/FilterTabBar/FilterTabBar.tsx +8 -22
  39. package/src/atoms/HomePageTemplate/HomePageTemplate.tsx +20 -33
  40. package/src/atoms/HomePageTemplate/preview.tsx +2 -2
  41. package/src/atoms/Icon/Icon.tsx +7 -5
  42. package/src/atoms/Icon/icons.data.ts +51 -0
  43. package/src/atoms/Input/Input.tsx +17 -9
  44. package/src/atoms/Input/preview.tsx +24 -25
  45. package/src/atoms/Menu/Menu.tsx +320 -0
  46. package/src/atoms/Menu/index.ts +2 -0
  47. package/src/atoms/Menu/preview.tsx +63 -0
  48. package/src/atoms/Modal/Modal.tsx +43 -37
  49. package/src/atoms/Modal/preview.tsx +13 -0
  50. package/src/atoms/NavItem/NavItem.tsx +33 -45
  51. package/src/atoms/NavItem/preview.tsx +21 -26
  52. package/src/atoms/PreviewToolbar/PreviewToolbar.tsx +144 -192
  53. package/src/atoms/PreviewToolbar/preview.tsx +24 -4
  54. package/src/atoms/PricingCard/PricingCard.tsx +164 -0
  55. package/src/atoms/PricingCard/index.ts +2 -0
  56. package/src/atoms/PricingCard/preview.tsx +45 -0
  57. package/src/atoms/PricingPageTemplate/PricingPageTemplate.tsx +219 -0
  58. package/src/atoms/PricingPageTemplate/index.ts +2 -0
  59. package/src/atoms/PricingPageTemplate/preview.tsx +10 -0
  60. package/src/atoms/PromptInputBar/PromptInputBar.tsx +117 -158
  61. package/src/atoms/WorkspaceMenu/WorkspaceMenu.tsx +41 -167
  62. package/src/index.ts +10 -0
  63. package/src/tokens.css +5 -0
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { Button } from "../Button";
3
3
  import { Input } from "../Input";
4
+ import { Icon } from "../Icon";
4
5
 
5
6
  export type PromptMode = "Build" | "Chat" | "Design";
6
7
 
@@ -28,6 +29,12 @@ export interface PromptInputBarProps {
28
29
  mode?: PromptMode;
29
30
  /** Called when mode selection changes */
30
31
  onModeChange?: (mode: PromptMode) => void;
32
+ /**
33
+ * Whether to render the Build/Chat/Design mode dropdown in the toolbar.
34
+ * Default: true. Set to false for consumers (like ChatScreen) that don't
35
+ * need mode switching.
36
+ */
37
+ showModeSelector?: boolean;
31
38
  /** Called when the send button is clicked */
32
39
  onSend?: (value: string, images: PastedImage[]) => void;
33
40
  /**
@@ -69,27 +76,20 @@ export interface PromptInputBarProps {
69
76
  pastedImages?: PastedImage[];
70
77
  /** Called when the internal image list changes (add / remove) */
71
78
  onImagesChange?: (images: PastedImage[]) => void;
79
+ /**
80
+ * Whether the compact "Suggest Designs" switch (rendered immediately to
81
+ * the right of the model dropdown) is on. Controlled — omit for an
82
+ * uncontrolled switch that defaults to off and is never persisted across
83
+ * remounts.
84
+ */
85
+ suggestDesigns?: boolean;
86
+ /** Called when the Suggest Designs switch is toggled */
87
+ onSuggestDesignsChange?: (on: boolean) => void;
72
88
  className?: string;
73
89
  }
74
90
 
75
91
  const MODES: PromptMode[] = ["Build", "Chat", "Design"];
76
92
 
77
- // Small inline X icon reused for the image remove button overlay
78
- const XIcon = () => (
79
- <svg
80
- viewBox="0 0 16 16"
81
- fill="none"
82
- stroke="currentColor"
83
- strokeWidth={2.5}
84
- strokeLinecap="round"
85
- className="w-2.5 h-2.5"
86
- aria-hidden="true"
87
- >
88
- <line x1="4" y1="4" x2="12" y2="12" />
89
- <line x1="12" y1="4" x2="4" y2="12" />
90
- </svg>
91
- );
92
-
93
93
  /** Generic hook: calls `onClose` when a mousedown/touchstart fires outside `ref`. */
94
94
  function useClickOutside(
95
95
  ref: React.RefObject<HTMLElement | null>,
@@ -123,6 +123,7 @@ export const PromptInputBar = React.forwardRef<
123
123
  onChange,
124
124
  mode = "Build",
125
125
  onModeChange,
126
+ showModeSelector = true,
126
127
  onSend,
127
128
  onAttach,
128
129
  onFilesSelected,
@@ -136,6 +137,8 @@ export const PromptInputBar = React.forwardRef<
136
137
  onModelChange,
137
138
  pastedImages,
138
139
  onImagesChange,
140
+ suggestDesigns,
141
+ onSuggestDesignsChange,
139
142
  className,
140
143
  },
141
144
  ref,
@@ -144,6 +147,9 @@ export const PromptInputBar = React.forwardRef<
144
147
  const [internalImages, setInternalImages] = React.useState<PastedImage[]>([]);
145
148
  const [modeOpen, setModeOpen] = React.useState(false);
146
149
  const [modelOpen, setModelOpen] = React.useState(false);
150
+ // Uncontrolled fallback for the Suggest Designs switch. Always starts
151
+ // off and is never persisted across remounts.
152
+ const [internalSuggestDesigns, setInternalSuggestDesigns] = React.useState(false);
147
153
 
148
154
  const fileInputRef = React.useRef<HTMLInputElement>(null);
149
155
  const modeRef = React.useRef<HTMLDivElement>(null);
@@ -155,6 +161,7 @@ export const PromptInputBar = React.forwardRef<
155
161
 
156
162
  const textValue = value !== undefined ? value : internalValue;
157
163
  const images = pastedImages !== undefined ? pastedImages : internalImages;
164
+ const suggestDesignsOn = suggestDesigns !== undefined ? suggestDesigns : internalSuggestDesigns;
158
165
 
159
166
  const selectedModel = models?.find((m) => m.id === selectedModelId) ?? models?.[0];
160
167
 
@@ -248,6 +255,12 @@ export const PromptInputBar = React.forwardRef<
248
255
  }
249
256
  };
250
257
 
258
+ const toggleSuggestDesigns = () => {
259
+ const next = !suggestDesignsOn;
260
+ if (suggestDesigns === undefined) setInternalSuggestDesigns(next);
261
+ onSuggestDesignsChange?.(next);
262
+ };
263
+
251
264
  const canSend =
252
265
  (textValue.trim().length > 0 || images.length > 0) && !disabled && !isStreaming;
253
266
  const textareaDisabled = disabled || isStreaming;
@@ -297,7 +310,7 @@ export const PromptInputBar = React.forwardRef<
297
310
  aria-label={`Remove image ${img.name}`}
298
311
  className="absolute -top-1.5 -right-1.5 !p-0 !w-5 !h-5 !min-w-0 !rounded-full bg-ink text-on-primary hover:bg-body opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity duration-150 shadow-sm flex items-center justify-center"
299
312
  >
300
- <XIcon />
313
+ <Icon name="close" size={10} strokeWidth={2.5} />
301
314
  </Button>
302
315
  </div>
303
316
  ))}
@@ -330,20 +343,7 @@ export const PromptInputBar = React.forwardRef<
330
343
  aria-label="Attach"
331
344
  className="flex items-center justify-center size-8 rounded-full bg-surface-soft border border-hairline text-ink hover:bg-surface-strong active:bg-surface-strong transition-colors duration-150 flex-shrink-0 cursor-pointer"
332
345
  >
333
- <svg
334
- xmlns="http://www.w3.org/2000/svg"
335
- viewBox="0 0 24 24"
336
- fill="none"
337
- stroke="currentColor"
338
- strokeWidth="2"
339
- strokeLinecap="round"
340
- strokeLinejoin="round"
341
- className="size-4"
342
- aria-hidden="true"
343
- >
344
- <line x1="12" y1="5" x2="12" y2="19" />
345
- <line x1="5" y1="12" x2="19" y2="12" />
346
- </svg>
346
+ <Icon name="plus-add" size={16} />
347
347
  </span>
348
348
 
349
349
  {/* Visual Edits pill */}
@@ -355,22 +355,7 @@ export const PromptInputBar = React.forwardRef<
355
355
  aria-label="Visual edits"
356
356
  className="rounded-full px-md gap-xs"
357
357
  >
358
- <svg
359
- xmlns="http://www.w3.org/2000/svg"
360
- viewBox="0 0 24 24"
361
- fill="none"
362
- stroke="currentColor"
363
- strokeWidth="2"
364
- strokeLinecap="round"
365
- strokeLinejoin="round"
366
- className="size-4 flex-shrink-0"
367
- aria-hidden="true"
368
- >
369
- <path d="M17 1l4 4-4 4" />
370
- <path d="M3 11V9a4 4 0 0 1 4-4h14" />
371
- <path d="M7 23l-4-4 4-4" />
372
- <path d="M21 13v2a4 4 0 0 1-4 4H3" />
373
- </svg>
358
+ <Icon name="visual-edits-swap-arrows" size={16} />
374
359
  Visual edits
375
360
  </Button>
376
361
  )}
@@ -392,26 +377,14 @@ export const PromptInputBar = React.forwardRef<
392
377
  className="flex items-center gap-xs text-body-sm font-weight-heading-sm text-muted hover:text-ink transition-colors duration-150 cursor-pointer select-none rounded-sm px-xs py-xxs"
393
378
  >
394
379
  {(models.find((m) => m.id === selectedModelId) ?? models[0])?.name ?? "Model"}
395
- <svg
396
- xmlns="http://www.w3.org/2000/svg"
397
- viewBox="0 0 24 24"
398
- fill="none"
399
- stroke="currentColor"
400
- strokeWidth="2.5"
401
- strokeLinecap="round"
402
- strokeLinejoin="round"
403
- className="size-3"
404
- aria-hidden="true"
405
- >
406
- <polyline points="6 9 12 15 18 9" />
407
- </svg>
380
+ <Icon name="chevron-down" size={12} strokeWidth={2.5} />
408
381
  </span>
409
382
 
410
383
  {modelOpen && (
411
384
  <ul
412
385
  role="listbox"
413
386
  aria-label="Model options"
414
- className="absolute bottom-full mb-xs left-0 bg-canvas border border-hairline rounded-md shadow-md min-w-[12rem] max-h-[250px] overflow-y-auto"
387
+ className="absolute bottom-full mb-xs left-0 bg-canvas border border-hairline rounded-md shadow-md min-w-48 max-h-64 overflow-y-auto"
415
388
  style={{ zIndex: "var(--z-dropdown, 50)" }}
416
389
  >
417
390
  {models.map((m) => (
@@ -466,76 +439,98 @@ export const PromptInputBar = React.forwardRef<
466
439
  )}
467
440
  </div>
468
441
  )}
469
- </div>
470
442
 
471
- {/* Right actions */}
472
- <div className="flex items-center gap-sm">
473
- {/* ── Mode selector dropdown ── */}
474
- <div ref={modeRef} className="relative">
443
+ {/* ── Suggest Designs switch (immediately right of the model dropdown) ── */}
444
+ <span className="flex items-center gap-xs pl-xs">
475
445
  <span
476
- role="button"
446
+ role="switch"
477
447
  tabIndex={0}
478
- onClick={() => setModeOpen((o) => !o)}
448
+ aria-checked={suggestDesignsOn}
449
+ aria-label="Suggest Designs"
450
+ onClick={toggleSuggestDesigns}
479
451
  onKeyDown={(e) => {
480
- if (e.key === "Enter") setModeOpen((o) => !o);
481
- if (e.key === "Escape") setModeOpen(false);
452
+ if (e.key === " " || e.key === "Enter") {
453
+ e.preventDefault();
454
+ toggleSuggestDesigns();
455
+ }
482
456
  }}
483
- aria-haspopup="listbox"
484
- aria-expanded={modeOpen}
485
- className="flex items-center gap-xs text-body-md font-weight-heading-sm text-ink hover:text-muted transition-colors duration-150 cursor-pointer select-none"
457
+ className={[
458
+ "relative inline-flex items-center h-4 w-7 flex-shrink-0 rounded-full transition-colors duration-150 cursor-pointer",
459
+ suggestDesignsOn ? "bg-primary" : "bg-surface-strong",
460
+ ].join(" ")}
486
461
  >
487
- {mode}
488
- <svg
489
- xmlns="http://www.w3.org/2000/svg"
490
- viewBox="0 0 24 24"
491
- fill="none"
492
- stroke="currentColor"
493
- strokeWidth="2.5"
494
- strokeLinecap="round"
495
- strokeLinejoin="round"
496
- className="size-4"
462
+ <span
497
463
  aria-hidden="true"
498
- >
499
- <polyline points="6 9 12 15 18 9" />
500
- </svg>
464
+ className={[
465
+ "inline-block size-3 rounded-full shadow-sm transform transition-transform duration-150",
466
+ suggestDesignsOn
467
+ ? "translate-x-3.5 bg-on-primary"
468
+ : "translate-x-0.5 bg-canvas",
469
+ ].join(" ")}
470
+ />
501
471
  </span>
472
+ <span className="text-body-sm text-muted select-none">Suggest Designs</span>
473
+ </span>
474
+ </div>
502
475
 
503
- {modeOpen && (
504
- <ul
505
- role="listbox"
506
- className="absolute bottom-full mb-xs right-0 bg-canvas border border-hairline rounded-md shadow-md py-xs min-w-[8rem]"
507
- style={{ zIndex: "var(--z-dropdown, 50)" }}
476
+ {/* Right actions */}
477
+ <div className="flex items-center gap-sm">
478
+ {/* ── Mode selector dropdown ── */}
479
+ {showModeSelector && (
480
+ <div ref={modeRef} className="relative">
481
+ <span
482
+ role="button"
483
+ tabIndex={0}
484
+ onClick={() => setModeOpen((o) => !o)}
485
+ onKeyDown={(e) => {
486
+ if (e.key === "Enter") setModeOpen((o) => !o);
487
+ if (e.key === "Escape") setModeOpen(false);
488
+ }}
489
+ aria-haspopup="listbox"
490
+ aria-expanded={modeOpen}
491
+ className="flex items-center gap-xs text-body-md font-weight-heading-sm text-ink hover:text-muted transition-colors duration-150 cursor-pointer select-none"
508
492
  >
509
- {MODES.map((m) => (
510
- <li key={m} role="option" aria-selected={m === mode}>
511
- <span
512
- role="button"
513
- tabIndex={0}
514
- onClick={() => {
515
- onModeChange?.(m);
516
- setModeOpen(false);
517
- }}
518
- onKeyDown={(e) => {
519
- if (e.key === "Enter") {
493
+ {mode}
494
+ <Icon name="chevron-down" size={16} strokeWidth={2.5} />
495
+ </span>
496
+
497
+ {modeOpen && (
498
+ <ul
499
+ role="listbox"
500
+ className="absolute bottom-full mb-xs right-0 bg-canvas border border-hairline rounded-md shadow-md py-xs min-w-32"
501
+ style={{ zIndex: "var(--z-dropdown, 50)" }}
502
+ >
503
+ {MODES.map((m) => (
504
+ <li key={m} role="option" aria-selected={m === mode}>
505
+ <span
506
+ role="button"
507
+ tabIndex={0}
508
+ onClick={() => {
520
509
  onModeChange?.(m);
521
510
  setModeOpen(false);
522
- }
523
- if (e.key === "Escape") setModeOpen(false);
524
- }}
525
- className={[
526
- "block w-full text-left px-md py-xs text-body-sm transition-colors duration-100 cursor-pointer",
527
- m === mode
528
- ? "text-ink font-weight-heading-sm bg-surface-soft"
529
- : "text-muted hover:bg-surface-soft",
530
- ].join(" ")}
531
- >
532
- {m}
533
- </span>
534
- </li>
535
- ))}
536
- </ul>
537
- )}
538
- </div>
511
+ }}
512
+ onKeyDown={(e) => {
513
+ if (e.key === "Enter") {
514
+ onModeChange?.(m);
515
+ setModeOpen(false);
516
+ }
517
+ if (e.key === "Escape") setModeOpen(false);
518
+ }}
519
+ className={[
520
+ "block w-full text-left px-md py-xs text-body-sm transition-colors duration-100 cursor-pointer",
521
+ m === mode
522
+ ? "text-ink font-weight-heading-sm bg-surface-soft"
523
+ : "text-muted hover:bg-surface-soft",
524
+ ].join(" ")}
525
+ >
526
+ {m}
527
+ </span>
528
+ </li>
529
+ ))}
530
+ </ul>
531
+ )}
532
+ </div>
533
+ )}
539
534
 
540
535
  {/* Mic button */}
541
536
  <span
@@ -546,22 +541,7 @@ export const PromptInputBar = React.forwardRef<
546
541
  aria-label="Voice input"
547
542
  className="flex items-center justify-center size-9 rounded-full bg-surface-soft border border-hairline text-ink hover:bg-surface-strong active:bg-surface-strong transition-colors duration-150 flex-shrink-0 cursor-pointer"
548
543
  >
549
- <svg
550
- xmlns="http://www.w3.org/2000/svg"
551
- viewBox="0 0 24 24"
552
- fill="none"
553
- stroke="currentColor"
554
- strokeWidth="1.75"
555
- strokeLinecap="round"
556
- strokeLinejoin="round"
557
- className="size-4"
558
- aria-hidden="true"
559
- >
560
- <rect x="9" y="2" width="6" height="11" rx="3" />
561
- <path d="M19 10a7 7 0 0 1-14 0" />
562
- <line x1="12" y1="19" x2="12" y2="22" />
563
- <line x1="8" y1="22" x2="16" y2="22" />
564
- </svg>
544
+ <Icon name="microphone" size={16} strokeWidth={1.75} />
565
545
  </span>
566
546
 
567
547
  {/* Send / Stop button */}
@@ -574,15 +554,7 @@ export const PromptInputBar = React.forwardRef<
574
554
  aria-label="Stop generation"
575
555
  className="flex items-center justify-center size-9 rounded-full bg-ink text-on-primary hover:bg-body transition-colors duration-150 flex-shrink-0 cursor-pointer"
576
556
  >
577
- <svg
578
- xmlns="http://www.w3.org/2000/svg"
579
- viewBox="0 0 24 24"
580
- fill="currentColor"
581
- className="size-4"
582
- aria-hidden="true"
583
- >
584
- <rect x="5" y="5" width="14" height="14" rx="2" />
585
- </svg>
557
+ <Icon name="stop-square" size={16} strokeWidth={0} className="fill-current" />
586
558
  </span>
587
559
  ) : (
588
560
  <span
@@ -599,20 +571,7 @@ export const PromptInputBar = React.forwardRef<
599
571
  : "bg-surface-strong text-muted-soft cursor-not-allowed",
600
572
  ].join(" ")}
601
573
  >
602
- <svg
603
- xmlns="http://www.w3.org/2000/svg"
604
- viewBox="0 0 24 24"
605
- fill="none"
606
- stroke="currentColor"
607
- strokeWidth="2.25"
608
- strokeLinecap="round"
609
- strokeLinejoin="round"
610
- className="size-4"
611
- aria-hidden="true"
612
- >
613
- <line x1="12" y1="19" x2="12" y2="5" />
614
- <polyline points="5 12 12 5 19 12" />
615
- </svg>
574
+ <Icon name="arrow-up-send" size={16} strokeWidth={2.25} />
616
575
  </span>
617
576
  )}
618
577
  </div>
@@ -1,5 +1,7 @@
1
1
  import React from "react";
2
2
  import { Button } from "../Button";
3
+ import { Icon } from "../Icon";
4
+ import { Menu, type MenuItem } from "../Menu";
3
5
 
4
6
  export interface WorkspaceMenuProps
5
7
  extends React.HTMLAttributes<HTMLDivElement> {
@@ -13,65 +15,6 @@ export interface WorkspaceMenuProps
13
15
  defaultOpen?: boolean;
14
16
  }
15
17
 
16
- const RenameIcon = () => (
17
- <svg
18
- aria-hidden="true"
19
- xmlns="http://www.w3.org/2000/svg"
20
- viewBox="0 0 24 24"
21
- fill="none"
22
- stroke="currentColor"
23
- strokeWidth="2"
24
- strokeLinecap="round"
25
- strokeLinejoin="round"
26
- style={{ width: "16px", height: "16px", flexShrink: 0 }}
27
- >
28
- <path d="M12 20h9" />
29
- <path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z" />
30
- </svg>
31
- );
32
-
33
- const DeleteIcon = () => (
34
- <svg
35
- aria-hidden="true"
36
- xmlns="http://www.w3.org/2000/svg"
37
- viewBox="0 0 24 24"
38
- fill="none"
39
- stroke="currentColor"
40
- strokeWidth="2"
41
- strokeLinecap="round"
42
- strokeLinejoin="round"
43
- style={{ width: "16px", height: "16px", flexShrink: 0 }}
44
- >
45
- <polyline points="3 6 5 6 21 6" />
46
- <path d="M19 6l-1 14H6L5 6" />
47
- <path d="M10 11v6" />
48
- <path d="M14 11v6" />
49
- <path d="M9 6V4h6v2" />
50
- </svg>
51
- );
52
-
53
- const ChevronIcon = ({ open }: { open: boolean }) => (
54
- <svg
55
- aria-hidden="true"
56
- xmlns="http://www.w3.org/2000/svg"
57
- viewBox="0 0 24 24"
58
- fill="none"
59
- stroke="currentColor"
60
- strokeWidth="2"
61
- strokeLinecap="round"
62
- strokeLinejoin="round"
63
- style={{
64
- width: "16px",
65
- height: "16px",
66
- flexShrink: 0,
67
- transition: "transform 180ms ease-in-out",
68
- transform: open ? "rotate(180deg)" : "rotate(0deg)",
69
- }}
70
- >
71
- <polyline points="6 9 12 15 18 9" />
72
- </svg>
73
- );
74
-
75
18
  export const WorkspaceMenu = React.forwardRef<
76
19
  HTMLDivElement,
77
20
  WorkspaceMenuProps
@@ -88,126 +31,57 @@ export const WorkspaceMenu = React.forwardRef<
88
31
  ref,
89
32
  ) => {
90
33
  const [open, setOpen] = React.useState(defaultOpen);
91
- const [mounted, setMounted] = React.useState(defaultOpen);
92
- const [visible, setVisible] = React.useState(false);
93
- const containerRef = React.useRef<HTMLDivElement>(null);
94
34
 
95
- const setRefs = React.useCallback(
96
- (node: HTMLDivElement | null) => {
97
- (containerRef as React.MutableRefObject<HTMLDivElement | null>).current = node;
98
- if (typeof ref === "function") ref(node);
99
- else if (ref)
100
- (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;
35
+ const items: MenuItem[] = [
36
+ {
37
+ id: "rename",
38
+ label: "Rename",
39
+ icon: "pencil-edit",
40
+ onSelect: () => onRename?.(),
101
41
  },
102
- [ref],
103
- );
104
-
105
- React.useEffect(() => {
106
- if (open) {
107
- setMounted(true);
108
- const raf = requestAnimationFrame(() => {
109
- requestAnimationFrame(() => setVisible(true));
110
- });
111
- return () => cancelAnimationFrame(raf);
112
- }
113
-
114
- setVisible(false);
115
- const timer = window.setTimeout(() => setMounted(false), 220);
116
- return () => window.clearTimeout(timer);
117
- }, [open]);
118
-
119
- React.useEffect(() => {
120
- if (!open) return;
121
- const handler = (e: MouseEvent) => {
122
- if (
123
- containerRef.current &&
124
- !containerRef.current.contains(e.target as Node)
125
- ) {
126
- setOpen(false);
127
- }
128
- };
129
- document.addEventListener("mousedown", handler);
130
- return () => document.removeEventListener("mousedown", handler);
131
- }, [open]);
132
-
133
- React.useEffect(() => {
134
- if (!open) return;
135
- const handler = (e: KeyboardEvent) => {
136
- if (e.key === "Escape") setOpen(false);
137
- };
138
- document.addEventListener("keydown", handler);
139
- return () => document.removeEventListener("keydown", handler);
140
- }, [open]);
42
+ {
43
+ id: "delete",
44
+ label: "Delete",
45
+ icon: "trash-delete",
46
+ destructive: true,
47
+ onSelect: () => onDelete?.(),
48
+ },
49
+ ];
141
50
 
142
51
  return (
143
52
  <div
144
- ref={setRefs}
145
- className={["relative inline-block", className].filter(Boolean).join(" ")}
53
+ ref={ref}
54
+ className={["inline-block", className].filter(Boolean).join(" ")}
146
55
  {...rest}
147
56
  >
148
- <Button
149
- type="button"
150
- variant="secondary"
151
- size="sm"
152
- aria-haspopup="menu"
153
- aria-expanded={open}
154
- aria-label={`Workspace options: ${workspaceName}`}
155
- onClick={() => setOpen((v) => !v)}
156
- className="!gap-sm !pr-sm"
157
- style={{ minWidth: "200px" }}
158
- >
159
- <span className="flex-1 text-left truncate text-body-sm font-weight-heading-sm">
160
- {workspaceName}
161
- </span>
162
- <ChevronIcon open={open} />
163
- </Button>
164
-
165
- {mounted && (
166
- <div
167
- role="menu"
168
- aria-label="Workspace actions"
169
- aria-hidden={!open}
170
- className={[
171
- "absolute left-0 mt-xs origin-top rounded-xl bg-surface border border-hairline-soft shadow-card z-10 py-xs overflow-hidden",
172
- "transition-all duration-200 ease-in-out will-change-transform",
173
- visible
174
- ? "pointer-events-auto opacity-100 translate-y-0 scale-y-100"
175
- : "pointer-events-none opacity-0 -translate-y-1 scale-y-95",
176
- ].join(" ")}
177
- style={{ minWidth: "200px" }}
178
- >
179
- <Button
180
- role="menuitem"
181
- type="button"
182
- variant="ghost"
183
- size="sm"
184
- onClick={() => {
185
- setOpen(false);
186
- onRename?.();
187
- }}
188
- className="!w-full !justify-start !rounded-none !px-md !gap-sm text-muted"
189
- >
190
- <RenameIcon />
191
- <span className="text-ink">Rename</span>
192
- </Button>
193
-
57
+ <Menu
58
+ items={items}
59
+ open={open}
60
+ onOpenChange={setOpen}
61
+ portal={true}
62
+ aria-label="Workspace actions"
63
+ trigger={
194
64
  <Button
195
- role="menuitem"
196
65
  type="button"
197
- variant="ghost"
66
+ variant="secondary"
198
67
  size="sm"
199
- onClick={() => {
200
- setOpen(false);
201
- onDelete?.();
202
- }}
203
- className="!w-full !justify-start !rounded-none !px-md !gap-sm"
204
- style={{ color: "var(--color-semantic-error)" }}
68
+ aria-haspopup="menu"
69
+ aria-expanded={open}
70
+ aria-label={`Workspace options: ${workspaceName}`}
71
+ className="!gap-sm !pr-sm !rounded-sm"
72
+ style={{ minWidth: "200px" }}
205
73
  >
206
- <DeleteIcon />
207
- <span>Delete</span>
74
+ <span className="flex-1 text-left truncate text-body-sm font-weight-heading-sm">
75
+ {workspaceName}
76
+ </span>
77
+ <Icon
78
+ name="chevron-down"
79
+ className="size-4 shrink-0 transition-transform duration-180 ease-in-out"
80
+ style={{ transform: open ? "rotate(180deg)" : "rotate(0deg)" }}
81
+ />
208
82
  </Button>
209
- </div>
210
- )}
83
+ }
84
+ />
211
85
  </div>
212
86
  );
213
87
  },