@dinachi/cli 0.12.0 → 1.1.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 (74) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/dist/index.js +73 -7
  3. package/package.json +1 -1
  4. package/templates/accordion/accordion.tsx +70 -12
  5. package/templates/agent/agent.tsx +1865 -0
  6. package/templates/agent/index.ts +52 -0
  7. package/templates/alert-dialog/alert-dialog.tsx +59 -19
  8. package/templates/alert-dialog/index.ts +2 -0
  9. package/templates/animated-icon/animated-icon.tsx +1 -0
  10. package/templates/animated-list/animated-list.tsx +2 -1
  11. package/templates/animated-tabs/animated-tabs.tsx +69 -5
  12. package/templates/autocomplete/autocomplete.tsx +188 -21
  13. package/templates/avatar/avatar.tsx +3 -0
  14. package/templates/badge/badge.tsx +1 -0
  15. package/templates/button/button.tsx +1 -0
  16. package/templates/card/card.tsx +6 -1
  17. package/templates/carousel/carousel.tsx +109 -24
  18. package/templates/checkbox/checkbox.tsx +61 -4
  19. package/templates/checkbox-group/checkbox-group.tsx +83 -8
  20. package/templates/collapsible/collapsible.tsx +15 -4
  21. package/templates/combobox/combobox.tsx +312 -26
  22. package/templates/compare-slider/compare-slider.tsx +104 -28
  23. package/templates/compare-slider/index.ts +1 -1
  24. package/templates/context-menu/context-menu.tsx +93 -24
  25. package/templates/dialog/dialog.tsx +53 -14
  26. package/templates/drawer/drawer.tsx +36 -8
  27. package/templates/expandable-card/expandable-card.tsx +70 -43
  28. package/templates/field/field.tsx +7 -1
  29. package/templates/fieldset/fieldset.tsx +2 -0
  30. package/templates/form/form.tsx +1 -0
  31. package/templates/hold-to-confirm/hold-to-confirm.tsx +100 -16
  32. package/templates/hold-to-confirm/index.ts +1 -1
  33. package/templates/input/input.tsx +60 -1
  34. package/templates/label/label.tsx +1 -0
  35. package/templates/link/link.tsx +1 -0
  36. package/templates/load-transition/load-transition.tsx +1 -0
  37. package/templates/marquee/marquee.tsx +1 -0
  38. package/templates/menu/menu.tsx +45 -12
  39. package/templates/menubar/menubar.tsx +41 -11
  40. package/templates/meter/meter.tsx +5 -1
  41. package/templates/navigation-menu/navigation-menu.tsx +79 -24
  42. package/templates/number-field/index.ts +1 -0
  43. package/templates/number-field/number-field.tsx +77 -2
  44. package/templates/number-ticker/number-ticker.tsx +3 -0
  45. package/templates/otp-field/otp-field.tsx +61 -11
  46. package/templates/popover/popover.tsx +36 -7
  47. package/templates/preview-card/preview-card.tsx +27 -5
  48. package/templates/progress/progress.tsx +5 -1
  49. package/templates/progress-ring/progress-ring.tsx +1 -0
  50. package/templates/radio/radio.tsx +74 -6
  51. package/templates/scroll-area/scroll-area.tsx +14 -4
  52. package/templates/scroll-progress/scroll-progress.tsx +1 -0
  53. package/templates/scroll-reveal/scroll-reveal.tsx +1 -0
  54. package/templates/select/select.tsx +241 -12
  55. package/templates/separator/separator.tsx +1 -0
  56. package/templates/skeleton/skeleton.tsx +1 -0
  57. package/templates/slider/slider.tsx +84 -8
  58. package/templates/sortable/sortable.tsx +79 -9
  59. package/templates/stagger-list/stagger-list.tsx +2 -0
  60. package/templates/streaming-text/streaming-text.tsx +1 -0
  61. package/templates/swipeable-row/index.ts +1 -1
  62. package/templates/swipeable-row/swipeable-row.tsx +126 -41
  63. package/templates/switch/switch.tsx +43 -4
  64. package/templates/tabs/tabs.tsx +79 -10
  65. package/templates/text/text.tsx +1 -0
  66. package/templates/text-morph/text-morph.tsx +2 -0
  67. package/templates/text-shimmer/text-shimmer.tsx +1 -0
  68. package/templates/textarea/index.ts +1 -1
  69. package/templates/textarea/textarea.tsx +71 -4
  70. package/templates/toast/toast.tsx +13 -2
  71. package/templates/toggle/toggle.tsx +40 -7
  72. package/templates/toggle-group/toggle-group.tsx +98 -18
  73. package/templates/toolbar/toolbar.tsx +6 -0
  74. package/templates/tooltip/tooltip.tsx +9 -3
@@ -4,10 +4,27 @@ import * as React from "react"
4
4
  import { Menu as MenuPrimitive } from "@base-ui/react/menu"
5
5
  import { Check, ChevronRight, Circle, Search, X } from "lucide-react"
6
6
  import { cn } from "@/lib/utils"
7
+ import { type AgentOpenParts, useAgentOpen, useHasAgent, useMergedRef } from "@/components/ui/agent"
7
8
 
8
- const Menu: React.FC<React.ComponentProps<typeof MenuPrimitive.Root>> = (props) => (
9
- <MenuPrimitive.Root {...props} />
10
- )
9
+ const MenuAgentContext = React.createContext<AgentOpenParts | null>(null)
10
+
11
+ /**
12
+ * Base UI's root, holding its own open state so an agent can open and close it. Closed,
13
+ * the agent sees the trigger; open, the popup, with its items listed as menu items.
14
+ */
15
+ const Menu: React.FC<React.ComponentProps<typeof MenuPrimitive.Root>> = ({
16
+ open,
17
+ defaultOpen,
18
+ onOpenChange,
19
+ ...props
20
+ }) => {
21
+ const [state, change, parts] = useAgentOpen("menu", open, defaultOpen, onOpenChange)
22
+ return (
23
+ <MenuAgentContext.Provider value={useHasAgent() ? parts : null}>
24
+ <MenuPrimitive.Root {...props} open={state} onOpenChange={change} />
25
+ </MenuAgentContext.Provider>
26
+ )
27
+ }
11
28
  Menu.displayName = "Menu"
12
29
 
13
30
  const MenuTrigger = React.forwardRef<
@@ -15,7 +32,7 @@ const MenuTrigger = React.forwardRef<
15
32
  React.ComponentProps<typeof MenuPrimitive.Trigger>
16
33
  >(({ className, ...props }, ref) => (
17
34
  <MenuPrimitive.Trigger
18
- ref={ref}
35
+ ref={useMergedRef(ref, React.useContext(MenuAgentContext)?.trigger)}
19
36
  className={cn(
20
37
  "inline-flex h-10 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium",
21
38
  "hover:bg-accent hover:text-accent-foreground",
@@ -24,6 +41,7 @@ const MenuTrigger = React.forwardRef<
24
41
  "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
25
42
  className
26
43
  )}
44
+ data-slot="menu-trigger"
27
45
  {...props}
28
46
  />
29
47
  ))
@@ -31,7 +49,7 @@ MenuTrigger.displayName = "MenuTrigger"
31
49
 
32
50
  const MenuPortal: React.FC<
33
51
  React.ComponentProps<typeof MenuPrimitive.Portal>
34
- > = (props) => <MenuPrimitive.Portal {...props} />
52
+ > = (props) => <MenuPrimitive.Portal data-slot="menu-portal" {...props} />
35
53
  MenuPortal.displayName = "MenuPortal"
36
54
 
37
55
  const MenuPositioner = React.forwardRef<
@@ -40,8 +58,9 @@ const MenuPositioner = React.forwardRef<
40
58
  >(({ className, ...props }, ref) => (
41
59
  <MenuPrimitive.Positioner
42
60
  ref={ref}
43
- className={cn("outline-none", className)}
61
+ className={cn("z-50 outline-none", className)}
44
62
  sideOffset={6}
63
+ data-slot="menu-positioner"
45
64
  {...props}
46
65
  />
47
66
  ))
@@ -54,9 +73,9 @@ const MenuContent = React.forwardRef<
54
73
  <MenuPortal>
55
74
  <MenuPositioner>
56
75
  <MenuPrimitive.Popup
57
- ref={ref}
76
+ ref={useMergedRef(ref, React.useContext(MenuAgentContext)?.popup)}
58
77
  className={cn(
59
- "z-50 min-w-40 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
78
+ "min-w-40 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
60
79
  "origin-[var(--transform-origin)] outline-none",
61
80
  "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
62
81
  "data-[starting-style]:scale-95 data-[starting-style]:opacity-0",
@@ -64,6 +83,7 @@ const MenuContent = React.forwardRef<
64
83
  "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
65
84
  className
66
85
  )}
86
+ data-slot="menu-content"
67
87
  {...props}
68
88
  />
69
89
  </MenuPositioner>
@@ -87,6 +107,7 @@ const MenuItem = React.forwardRef<
87
107
  inset && "pl-8",
88
108
  className
89
109
  )}
110
+ data-slot="menu-item"
90
111
  {...props}
91
112
  />
92
113
  ))
@@ -104,6 +125,7 @@ const MenuLinkItem = React.forwardRef<
104
125
  "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
105
126
  className
106
127
  )}
128
+ data-slot="menu-link-item"
107
129
  {...props}
108
130
  />
109
131
  ))
@@ -122,6 +144,7 @@ const MenuCheckboxItem = React.forwardRef<
122
144
  "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
123
145
  className
124
146
  )}
147
+ data-slot="menu-checkbox-item"
125
148
  {...props}
126
149
  >
127
150
  <MenuPrimitive.CheckboxItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
@@ -136,7 +159,7 @@ const MenuRadioGroup = React.forwardRef<
136
159
  React.ComponentRef<typeof MenuPrimitive.RadioGroup>,
137
160
  React.ComponentProps<typeof MenuPrimitive.RadioGroup>
138
161
  >(({ className, ...props }, ref) => (
139
- <MenuPrimitive.RadioGroup ref={ref} className={className} {...props} />
162
+ <MenuPrimitive.RadioGroup ref={ref} className={className} data-slot="menu-radio-group" {...props} />
140
163
  ))
141
164
  MenuRadioGroup.displayName = "MenuRadioGroup"
142
165
 
@@ -153,6 +176,7 @@ const MenuRadioItem = React.forwardRef<
153
176
  "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
154
177
  className
155
178
  )}
179
+ data-slot="menu-radio-item"
156
180
  {...props}
157
181
  >
158
182
  <MenuPrimitive.RadioItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
@@ -167,7 +191,7 @@ const MenuGroup = React.forwardRef<
167
191
  React.ComponentRef<typeof MenuPrimitive.Group>,
168
192
  React.ComponentProps<typeof MenuPrimitive.Group>
169
193
  >(({ className, ...props }, ref) => (
170
- <MenuPrimitive.Group ref={ref} className={className} {...props} />
194
+ <MenuPrimitive.Group ref={ref} className={className} data-slot="menu-group" {...props} />
171
195
  ))
172
196
  MenuGroup.displayName = "MenuGroup"
173
197
 
@@ -180,6 +204,7 @@ const MenuLabel = React.forwardRef<
180
204
  <MenuPrimitive.GroupLabel
181
205
  ref={ref}
182
206
  className={cn("px-2 py-1.5 text-sm font-medium", inset && "pl-8", className)}
207
+ data-slot="menu-label"
183
208
  {...props}
184
209
  />
185
210
  ))
@@ -192,6 +217,7 @@ const MenuSeparator = React.forwardRef<
192
217
  <MenuPrimitive.Separator
193
218
  ref={ref}
194
219
  className={cn("-mx-1 my-1 h-px bg-border", className)}
220
+ data-slot="menu-separator"
195
221
  {...props}
196
222
  />
197
223
  ))
@@ -203,6 +229,7 @@ const MenuShortcut = ({
203
229
  }: React.HTMLAttributes<HTMLSpanElement>) => (
204
230
  <span
205
231
  className={cn("ml-auto text-xs tracking-widest text-muted-foreground", className)}
232
+ data-slot="menu-shortcut"
206
233
  {...props}
207
234
  />
208
235
  )
@@ -230,6 +257,7 @@ const MenuSubTrigger = React.forwardRef<
230
257
  inset && "pl-8",
231
258
  className
232
259
  )}
260
+ data-slot="menu-sub-trigger"
233
261
  {...props}
234
262
  >
235
263
  {children}
@@ -243,11 +271,11 @@ const MenuSubContent = React.forwardRef<
243
271
  React.ComponentProps<typeof MenuPrimitive.Popup>
244
272
  >(({ className, ...props }, ref) => (
245
273
  <MenuPrimitive.Portal>
246
- <MenuPrimitive.Positioner className="outline-none" alignOffset={-4} sideOffset={8}>
274
+ <MenuPrimitive.Positioner className="z-50 outline-none" alignOffset={-4} sideOffset={8}>
247
275
  <MenuPrimitive.Popup
248
276
  ref={ref}
249
277
  className={cn(
250
- "z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
278
+ "min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
251
279
  "origin-[var(--transform-origin)] outline-none",
252
280
  "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
253
281
  "data-[starting-style]:scale-95 data-[starting-style]:opacity-0",
@@ -255,6 +283,7 @@ const MenuSubContent = React.forwardRef<
255
283
  "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
256
284
  className
257
285
  )}
286
+ data-slot="menu-sub-content"
258
287
  {...props}
259
288
  />
260
289
  </MenuPrimitive.Positioner>
@@ -281,6 +310,7 @@ const MenuInput = React.forwardRef<
281
310
  "disabled:cursor-not-allowed disabled:opacity-50",
282
311
  className
283
312
  )}
313
+ data-slot="menu-input"
284
314
  {...props}
285
315
  />
286
316
  {children}
@@ -300,6 +330,7 @@ const MenuClear = React.forwardRef<
300
330
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
301
331
  className
302
332
  )}
333
+ data-slot="menu-clear"
303
334
  {...props}
304
335
  >
305
336
  {children ?? <X className="h-4 w-4" />}
@@ -314,6 +345,7 @@ const MenuEmpty = React.forwardRef<
314
345
  <MenuPrimitive.Empty
315
346
  ref={ref}
316
347
  className={cn("py-6 text-center text-sm text-muted-foreground", className)}
348
+ data-slot="menu-empty"
317
349
  {...props}
318
350
  />
319
351
  ))
@@ -330,6 +362,7 @@ const MenuList = React.forwardRef<
330
362
  "[&>[data-filter-section]:not([hidden])~[data-filter-section]:not([hidden])>[data-filter-separator]]:block",
331
363
  className
332
364
  )}
365
+ data-slot="menu-list"
333
366
  {...props}
334
367
  />
335
368
  ))
@@ -5,6 +5,7 @@ import { Menubar as BaseMenubar } from "@base-ui/react/menubar"
5
5
  import { Menu } from "@base-ui/react/menu"
6
6
  import { cn } from "@/lib/utils"
7
7
  import { Check, ChevronRight, Circle } from "lucide-react"
8
+ import { useAgentOpen, useHasAgent, useMergedRef } from "@/components/ui/agent"
8
9
 
9
10
  const Menubar = React.forwardRef<
10
11
  React.ComponentRef<typeof BaseMenubar>,
@@ -16,14 +17,32 @@ const Menubar = React.forwardRef<
16
17
  "flex h-10 items-center space-x-1 rounded-md border bg-background p-1",
17
18
  className
18
19
  )}
20
+ data-slot="menubar"
19
21
  {...props}
20
22
  />
21
23
  ))
22
24
  Menubar.displayName = "Menubar"
23
25
 
24
- const MenubarMenu: React.FC<React.ComponentProps<typeof Menu.Root>> = (props) => (
25
- <Menu.Root {...props} />
26
- )
26
+ const MenubarAgentContext = React.createContext<React.RefCallback<HTMLElement> | null>(null)
27
+
28
+ /**
29
+ * Base UI's menu, holding its own open state so an agent can open and close it. The agent
30
+ * sees it as its trigger, open or closed, so it stays in the menubar; its items are in the
31
+ * trigger's menu.
32
+ */
33
+ const MenubarMenu: React.FC<React.ComponentProps<typeof Menu.Root>> = ({
34
+ open,
35
+ defaultOpen,
36
+ onOpenChange,
37
+ ...props
38
+ }) => {
39
+ const [state, change, parts] = useAgentOpen("menu", open, defaultOpen, onOpenChange)
40
+ return (
41
+ <MenubarAgentContext.Provider value={useHasAgent() ? parts.trigger : null}>
42
+ <Menu.Root {...props} open={state} onOpenChange={change} />
43
+ </MenubarAgentContext.Provider>
44
+ )
45
+ }
27
46
  MenubarMenu.displayName = "MenubarMenu"
28
47
 
29
48
  const MenubarTrigger = React.forwardRef<
@@ -31,7 +50,7 @@ const MenubarTrigger = React.forwardRef<
31
50
  React.ComponentProps<typeof Menu.Trigger>
32
51
  >(({ className, ...props }, ref) => (
33
52
  <Menu.Trigger
34
- ref={ref}
53
+ ref={useMergedRef(ref, React.useContext(MenubarAgentContext))}
35
54
  className={cn(
36
55
  "flex cursor-default select-none items-center rounded-sm px-3 py-1.5 text-sm font-medium outline-none",
37
56
  "focus:bg-accent focus:text-accent-foreground",
@@ -40,6 +59,7 @@ const MenubarTrigger = React.forwardRef<
40
59
  "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
41
60
  className
42
61
  )}
62
+ data-slot="menubar-trigger"
43
63
  {...props}
44
64
  />
45
65
  ))
@@ -47,7 +67,7 @@ MenubarTrigger.displayName = "MenubarTrigger"
47
67
 
48
68
  const MenubarPortal: React.FC<
49
69
  React.ComponentProps<typeof Menu.Portal>
50
- > = (props) => <Menu.Portal {...props} />
70
+ > = (props) => <Menu.Portal data-slot="menubar-portal" {...props} />
51
71
  MenubarPortal.displayName = "MenubarPortal"
52
72
 
53
73
  const MenubarPositioner = React.forwardRef<
@@ -56,8 +76,9 @@ const MenubarPositioner = React.forwardRef<
56
76
  >(({ className, ...props }, ref) => (
57
77
  <Menu.Positioner
58
78
  ref={ref}
59
- className={cn("outline-none", className)}
79
+ className={cn("z-50 outline-none", className)}
60
80
  sideOffset={4}
81
+ data-slot="menubar-positioner"
61
82
  {...props}
62
83
  />
63
84
  ))
@@ -70,7 +91,7 @@ const MenubarContent = React.forwardRef<
70
91
  <Menu.Popup
71
92
  ref={ref}
72
93
  className={cn(
73
- "z-50 min-w-48 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
94
+ "min-w-48 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
74
95
  "origin-[var(--transform-origin)]",
75
96
  "outline-none focus:outline-none focus-visible:outline-none",
76
97
  "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
@@ -79,6 +100,7 @@ const MenubarContent = React.forwardRef<
79
100
  "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
80
101
  className
81
102
  )}
103
+ data-slot="menubar-content"
82
104
  {...props}
83
105
  />
84
106
  ))
@@ -100,6 +122,7 @@ const MenubarItem = React.forwardRef<
100
122
  inset && "pl-8",
101
123
  className
102
124
  )}
125
+ data-slot="menubar-item"
103
126
  {...props}
104
127
  />
105
128
  ))
@@ -118,6 +141,7 @@ const MenubarCheckboxItem = React.forwardRef<
118
141
  "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
119
142
  className
120
143
  )}
144
+ data-slot="menubar-checkbox-item"
121
145
  {...props}
122
146
  >
123
147
  <Menu.CheckboxItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
@@ -132,7 +156,7 @@ const MenubarRadioGroup = React.forwardRef<
132
156
  React.ComponentRef<typeof Menu.RadioGroup>,
133
157
  React.ComponentProps<typeof Menu.RadioGroup>
134
158
  >(({ className, ...props }, ref) => (
135
- <Menu.RadioGroup ref={ref} className={className} {...props} />
159
+ <Menu.RadioGroup ref={ref} className={className} data-slot="menubar-radio-group" {...props} />
136
160
  ))
137
161
  MenubarRadioGroup.displayName = "MenubarRadioGroup"
138
162
 
@@ -149,6 +173,7 @@ const MenubarRadioItem = React.forwardRef<
149
173
  "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
150
174
  className
151
175
  )}
176
+ data-slot="menubar-radio-item"
152
177
  {...props}
153
178
  >
154
179
  <Menu.RadioItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
@@ -163,7 +188,7 @@ const MenubarGroup = React.forwardRef<
163
188
  React.ComponentRef<typeof Menu.Group>,
164
189
  React.ComponentProps<typeof Menu.Group>
165
190
  >(({ className, ...props }, ref) => (
166
- <Menu.Group ref={ref} className={className} {...props} />
191
+ <Menu.Group ref={ref} className={className} data-slot="menubar-group" {...props} />
167
192
  ))
168
193
  MenubarGroup.displayName = "MenubarGroup"
169
194
 
@@ -180,6 +205,7 @@ const MenubarLabel = React.forwardRef<
180
205
  inset && "pl-8",
181
206
  className
182
207
  )}
208
+ data-slot="menubar-label"
183
209
  {...props}
184
210
  />
185
211
  ))
@@ -192,6 +218,7 @@ const MenubarSeparator = React.forwardRef<
192
218
  <Menu.Separator
193
219
  ref={ref}
194
220
  className={cn("-mx-1 my-1 h-px bg-border", className)}
221
+ data-slot="menubar-separator"
195
222
  {...props}
196
223
  />
197
224
  ))
@@ -206,6 +233,7 @@ const MenubarShortcut = ({
206
233
  "ml-auto text-xs tracking-widest text-muted-foreground",
207
234
  className
208
235
  )}
236
+ data-slot="menubar-shortcut"
209
237
  {...props}
210
238
  />
211
239
  )
@@ -233,6 +261,7 @@ const MenubarSubTrigger = React.forwardRef<
233
261
  inset && "pl-8",
234
262
  className
235
263
  )}
264
+ data-slot="menubar-sub-trigger"
236
265
  {...props}
237
266
  >
238
267
  {children}
@@ -246,11 +275,11 @@ const MenubarSubContent = React.forwardRef<
246
275
  React.ComponentProps<typeof Menu.Popup>
247
276
  >(({ className, ...props }, ref) => (
248
277
  <Menu.Portal>
249
- <Menu.Positioner className="outline-none" alignOffset={-4} sideOffset={8}>
278
+ <Menu.Positioner className="z-50 outline-none" alignOffset={-4} sideOffset={8}>
250
279
  <Menu.Popup
251
280
  ref={ref}
252
281
  className={cn(
253
- "z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg",
282
+ "min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg",
254
283
  "origin-[var(--transform-origin)]",
255
284
  "outline-none focus:outline-none focus-visible:outline-none",
256
285
  "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
@@ -259,6 +288,7 @@ const MenubarSubContent = React.forwardRef<
259
288
  "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
260
289
  className
261
290
  )}
291
+ data-slot="menubar-sub-content"
262
292
  {...props}
263
293
  />
264
294
  </Menu.Positioner>
@@ -8,7 +8,7 @@ const Meter = React.forwardRef<
8
8
  React.ComponentRef<typeof MeterPrimitive.Root>,
9
9
  React.ComponentPropsWithoutRef<typeof MeterPrimitive.Root>
10
10
  >(({ className, ...props }, ref) => (
11
- <MeterPrimitive.Root ref={ref} className={cn("grid gap-2", className)} {...props} />
11
+ <MeterPrimitive.Root data-slot="meter" ref={ref} className={cn("grid gap-2", className)} {...props} />
12
12
  ))
13
13
  Meter.displayName = "Meter"
14
14
 
@@ -17,6 +17,7 @@ const MeterTrack = React.forwardRef<
17
17
  React.ComponentPropsWithoutRef<typeof MeterPrimitive.Track>
18
18
  >(({ className, ...props }, ref) => (
19
19
  <MeterPrimitive.Track
20
+ data-slot="meter-track"
20
21
  ref={ref}
21
22
  className={cn("relative h-2 w-full overflow-hidden rounded-full bg-secondary", className)}
22
23
  {...props}
@@ -29,6 +30,7 @@ const MeterIndicator = React.forwardRef<
29
30
  React.ComponentPropsWithoutRef<typeof MeterPrimitive.Indicator>
30
31
  >(({ className, ...props }, ref) => (
31
32
  <MeterPrimitive.Indicator
33
+ data-slot="meter-indicator"
32
34
  ref={ref}
33
35
  className={cn("h-full rounded-full bg-primary transition-[width] duration-[var(--motion-duration-base,200ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))] motion-reduce:transition-none", className)}
34
36
  {...props}
@@ -41,6 +43,7 @@ const MeterLabel = React.forwardRef<
41
43
  React.ComponentPropsWithoutRef<typeof MeterPrimitive.Label>
42
44
  >(({ className, ...props }, ref) => (
43
45
  <MeterPrimitive.Label
46
+ data-slot="meter-label"
44
47
  ref={ref}
45
48
  className={cn("text-sm font-medium leading-none", className)}
46
49
  {...props}
@@ -53,6 +56,7 @@ const MeterValue = React.forwardRef<
53
56
  React.ComponentPropsWithoutRef<typeof MeterPrimitive.Value>
54
57
  >(({ className, ...props }, ref) => (
55
58
  <MeterPrimitive.Value
59
+ data-slot="meter-value"
56
60
  ref={ref}
57
61
  className={cn("text-xs text-muted-foreground", className)}
58
62
  {...props}
@@ -4,22 +4,46 @@ import * as React from "react"
4
4
  import { NavigationMenu as BaseNavigationMenu } from "@base-ui/react/navigation-menu"
5
5
  import { cn } from "@/lib/utils"
6
6
  import { ChevronDown } from "lucide-react"
7
+ import { changeAsAgent, useAgentControl, useAgentState, useHasAgent, useMergedRef } from "@/components/ui/agent"
8
+
9
+ type NavigationMenuDetails = BaseNavigationMenu.Root.ChangeEventDetails
10
+
11
+ interface NavigationMenuAgent {
12
+ value: unknown
13
+ change: (value: unknown, details: NavigationMenuDetails) => void
14
+ }
15
+
16
+ const NavigationMenuAgentContext = React.createContext<NavigationMenuAgent | null>(null)
17
+ const NavigationMenuItemAgentContext = React.createContext<React.RefObject<HTMLElement | null> | null>(null)
7
18
 
8
19
  const NavigationMenu = React.forwardRef<
9
20
  React.ComponentRef<typeof BaseNavigationMenu.Root>,
10
21
  React.ComponentProps<typeof BaseNavigationMenu.Root>
11
- >(({ className, children, ...props }, ref) => (
12
- <BaseNavigationMenu.Root
13
- ref={ref}
14
- className={cn(
15
- "relative z-10 flex max-w-max flex-1 items-center justify-center",
16
- className
17
- )}
18
- {...props}
19
- >
20
- {children}
21
- </BaseNavigationMenu.Root>
22
- ))
22
+ >(({ className, children, value: valueProp, defaultValue, onValueChange, ...props }, ref) => {
23
+ // Base UI's root, holding which item is open so an agent can open one the way a parent would.
24
+ const [value, change] = useAgentState<unknown, NavigationMenuDetails>(
25
+ valueProp,
26
+ defaultValue ?? null,
27
+ onValueChange as NavigationMenuAgent["change"] | undefined
28
+ )
29
+ return (
30
+ <NavigationMenuAgentContext.Provider value={useHasAgent() ? { value, change } : null}>
31
+ <BaseNavigationMenu.Root
32
+ ref={ref}
33
+ className={cn(
34
+ "relative z-10 flex max-w-max flex-1 items-center justify-center",
35
+ className
36
+ )}
37
+ value={value}
38
+ onValueChange={change}
39
+ data-slot="navigation-menu"
40
+ {...props}
41
+ >
42
+ {children}
43
+ </BaseNavigationMenu.Root>
44
+ </NavigationMenuAgentContext.Provider>
45
+ )
46
+ })
23
47
  NavigationMenu.displayName = "NavigationMenu"
24
48
 
25
49
  const NavigationMenuList = React.forwardRef<
@@ -32,6 +56,7 @@ const NavigationMenuList = React.forwardRef<
32
56
  "group flex flex-1 list-none items-center justify-center space-x-1",
33
57
  className
34
58
  )}
59
+ data-slot="navigation-menu-list"
35
60
  {...props}
36
61
  />
37
62
  ))
@@ -40,13 +65,30 @@ NavigationMenuList.displayName = "NavigationMenuList"
40
65
  const NavigationMenuItem = React.forwardRef<
41
66
  React.ComponentRef<typeof BaseNavigationMenu.Item>,
42
67
  React.ComponentProps<typeof BaseNavigationMenu.Item>
43
- >(({ className, ...props }, ref) => (
44
- <BaseNavigationMenu.Item
45
- ref={ref}
46
- className={className}
47
- {...props}
48
- />
49
- ))
68
+ >(({ className, value: valueProp, ...props }, ref) => {
69
+ const root = React.useContext(NavigationMenuAgentContext)
70
+ const id = React.useId()
71
+ const value = valueProp ?? id
72
+ const trigger = React.useRef<HTMLElement | null>(null)
73
+
74
+ // An item with a trigger is one menu, open while the root's value is this item's.
75
+ useAgentControl(() => {
76
+ if (!root) return null
77
+ const open = root.value === value
78
+ return {
79
+ kind: "menu",
80
+ element: trigger.current,
81
+ open,
82
+ actions: { [open ? "close" : "open"]: () => changeAsAgent(root.change, open ? null : value) },
83
+ }
84
+ })
85
+
86
+ return (
87
+ <NavigationMenuItemAgentContext.Provider value={root ? trigger : null}>
88
+ <BaseNavigationMenu.Item ref={ref} className={className} value={value} data-slot="navigation-menu-item" {...props} />
89
+ </NavigationMenuItemAgentContext.Provider>
90
+ )
91
+ })
50
92
  NavigationMenuItem.displayName = "NavigationMenuItem"
51
93
 
52
94
  const NavigationMenuTrigger = React.forwardRef<
@@ -54,7 +96,7 @@ const NavigationMenuTrigger = React.forwardRef<
54
96
  React.ComponentProps<typeof BaseNavigationMenu.Trigger>
55
97
  >(({ className, children, ...props }, ref) => (
56
98
  <BaseNavigationMenu.Trigger
57
- ref={ref}
99
+ ref={useMergedRef(ref, React.useContext(NavigationMenuItemAgentContext))}
58
100
  className={cn(
59
101
  "group inline-flex h-10 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium transition-colors",
60
102
  "hover:bg-accent hover:text-accent-foreground",
@@ -63,6 +105,7 @@ const NavigationMenuTrigger = React.forwardRef<
63
105
  "data-[popup-open]:bg-accent/50",
64
106
  className
65
107
  )}
108
+ data-slot="navigation-menu-trigger"
66
109
  {...props}
67
110
  >
68
111
  {children}{" "}
@@ -87,6 +130,7 @@ const NavigationMenuContent = React.forwardRef<
87
130
  "data-[starting-style]:opacity-0 data-[ending-style]:opacity-0",
88
131
  className
89
132
  )}
133
+ data-slot="navigation-menu-content"
90
134
  {...props}
91
135
  />
92
136
  ))
@@ -95,23 +139,28 @@ NavigationMenuContent.displayName = "NavigationMenuContent"
95
139
  const NavigationMenuLink = React.forwardRef<
96
140
  React.ComponentRef<typeof BaseNavigationMenu.Link>,
97
141
  React.ComponentProps<typeof BaseNavigationMenu.Link>
98
- >(({ className, ...props }, ref) => (
142
+ >(({ className, ...props }, ref) => {
143
+ const element = React.useRef<HTMLAnchorElement | null>(null)
144
+ useAgentControl(() => ({ kind: "link", element: element.current, actions: { press: () => element.current?.click() } }))
145
+ return (
99
146
  <BaseNavigationMenu.Link
100
- ref={ref}
147
+ ref={useMergedRef(ref, element)}
101
148
  className={cn(
102
149
  "block select-none space-y-1 rounded-md p-3 leading-none no-underline outline-none transition-colors",
103
150
  "hover:bg-accent hover:text-accent-foreground",
104
151
  "focus:bg-accent focus:text-accent-foreground",
105
152
  className
106
153
  )}
154
+ data-slot="navigation-menu-link"
107
155
  {...props}
108
156
  />
109
- ))
157
+ )
158
+ })
110
159
  NavigationMenuLink.displayName = "NavigationMenuLink"
111
160
 
112
161
  const NavigationMenuPortal: React.FC<
113
162
  React.ComponentProps<typeof BaseNavigationMenu.Portal>
114
- > = (props) => <BaseNavigationMenu.Portal {...props} />
163
+ > = (props) => <BaseNavigationMenu.Portal data-slot="navigation-menu-portal" {...props} />
115
164
  NavigationMenuPortal.displayName = "NavigationMenuPortal"
116
165
 
117
166
  const NavigationMenuPositioner = React.forwardRef<
@@ -121,6 +170,7 @@ const NavigationMenuPositioner = React.forwardRef<
121
170
  <BaseNavigationMenu.Positioner
122
171
  ref={ref}
123
172
  className={cn("absolute left-0 top-full z-50 flex justify-center", className)}
173
+ data-slot="navigation-menu-positioner"
124
174
  {...props}
125
175
  />
126
176
  ))
@@ -140,6 +190,7 @@ const NavigationMenuPopup = React.forwardRef<
140
190
  "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
141
191
  className
142
192
  )}
193
+ data-slot="navigation-menu-popup"
143
194
  {...props}
144
195
  />
145
196
  ))
@@ -158,6 +209,7 @@ const NavigationMenuViewport = React.forwardRef<
158
209
  style={{
159
210
  perspective: "2000px",
160
211
  }}
212
+ data-slot="navigation-menu-viewport"
161
213
  {...props}
162
214
  />
163
215
  ))
@@ -176,6 +228,7 @@ const NavigationMenuArrow = React.forwardRef<
176
228
  "data-[side=top]:bottom-[-8px] data-[side=top]:rotate-180",
177
229
  className
178
230
  )}
231
+ data-slot="navigation-menu-arrow"
179
232
  {...props}
180
233
  >
181
234
  {children || (
@@ -210,6 +263,7 @@ const NavigationMenuBackdrop = React.forwardRef<
210
263
  "transition-opacity duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
211
264
  className
212
265
  )}
266
+ data-slot="navigation-menu-backdrop"
213
267
  {...props}
214
268
  />
215
269
  ))
@@ -225,6 +279,7 @@ const NavigationMenuIndicator = React.forwardRef<
225
279
  "top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden",
226
280
  className
227
281
  )}
282
+ data-slot="navigation-menu-indicator"
228
283
  {...props}
229
284
  >
230
285
  <div className="relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md" />
@@ -7,3 +7,4 @@ export {
7
7
  NumberFieldScrubArea,
8
8
  NumberFieldScrubAreaCursor,
9
9
  } from "./number-field"
10
+ export type { NumberFieldProps } from "./number-field"