@cognitap/radiant 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -6
- package/dist/library/ContextMenu.d.ts +38 -0
- package/dist/library/ContextMenu.d.ts.map +1 -0
- package/dist/library/ContextMenu.js +169 -0
- package/dist/library/ContextMenu.js.map +1 -0
- package/dist/library/Menu.d.ts +88 -4
- package/dist/library/Menu.d.ts.map +1 -1
- package/dist/library/Menu.js +215 -27
- package/dist/library/Menu.js.map +1 -1
- package/dist/library/Menubar.d.ts +53 -0
- package/dist/library/Menubar.d.ts.map +1 -0
- package/dist/library/Menubar.js +246 -0
- package/dist/library/Menubar.js.map +1 -0
- package/dist/library/Popover.d.ts +18 -2
- package/dist/library/Popover.d.ts.map +1 -1
- package/dist/library/Popover.js +24 -4
- package/dist/library/Popover.js.map +1 -1
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +4 -0
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +6 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +3 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/react/usePopoverSurface.d.ts +4 -0
- package/dist/library/react/usePopoverSurface.d.ts.map +1 -1
- package/dist/library/react/usePopoverSurface.js +13 -4
- package/dist/library/react/usePopoverSurface.js.map +1 -1
- package/dist/library/react/useRovingFocus.d.ts +3 -1
- package/dist/library/react/useRovingFocus.d.ts.map +1 -1
- package/dist/library/react/useRovingFocus.js +3 -2
- package/dist/library/react/useRovingFocus.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +9 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +2 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +36 -31
- package/package.json +1 -1
- package/src/ContextMenu.tsx +354 -0
- package/src/Menu.tsx +516 -43
- package/src/Menubar.tsx +496 -0
- package/src/Popover.tsx +46 -4
- package/src/cn.ts +4 -0
- package/src/index.ts +95 -0
- package/src/react/usePopoverSurface.ts +17 -4
- package/src/react/useRovingFocus.ts +5 -2
- package/src/themes/components.ts +2 -0
package/src/Menubar.tsx
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
type ComponentProps,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
type RefObject
|
|
12
|
+
} from 'react'
|
|
13
|
+
import {
|
|
14
|
+
MenuRoot,
|
|
15
|
+
MenuTrigger,
|
|
16
|
+
MenuContentRoot,
|
|
17
|
+
MenuPortal,
|
|
18
|
+
MenuItem,
|
|
19
|
+
MenuGroup,
|
|
20
|
+
MenuLabel,
|
|
21
|
+
MenuSeparator,
|
|
22
|
+
MenuCheckboxItem,
|
|
23
|
+
MenuRadioGroup,
|
|
24
|
+
MenuRadioItem,
|
|
25
|
+
MenuSub,
|
|
26
|
+
MenuSubTrigger,
|
|
27
|
+
MenuSubContent,
|
|
28
|
+
useMenuContext,
|
|
29
|
+
useMenuFamily,
|
|
30
|
+
type MenuTriggerProps,
|
|
31
|
+
type MenuContentProps,
|
|
32
|
+
type MenuPortalProps,
|
|
33
|
+
type MenuItemProps,
|
|
34
|
+
type MenuGroupProps,
|
|
35
|
+
type MenuLabelProps,
|
|
36
|
+
type MenuSeparatorProps,
|
|
37
|
+
type MenuCheckboxItemProps,
|
|
38
|
+
type MenuRadioGroupProps,
|
|
39
|
+
type MenuRadioItemProps,
|
|
40
|
+
type MenuSubProps,
|
|
41
|
+
type MenuSubTriggerProps,
|
|
42
|
+
type MenuSubContentProps,
|
|
43
|
+
type MenuRenderProps
|
|
44
|
+
} from './Menu.js'
|
|
45
|
+
import { useControllableState } from './react/useControllableState.js'
|
|
46
|
+
import { useComposedRefs } from './react/useComposedRefs.js'
|
|
47
|
+
import { useRovingFocus } from './react/useRovingFocus.js'
|
|
48
|
+
import { requireAccessibleName, type AccessibleName } from './internal/accessibleName.js'
|
|
49
|
+
import type { ValueOwner } from './react/useNativeOwner.js'
|
|
50
|
+
import type { DistributiveOmit } from './internal/types.js'
|
|
51
|
+
import type { ThemeStyle } from './themes/defineTheme.js'
|
|
52
|
+
import { cn } from './cn.js'
|
|
53
|
+
import { joinIds } from './internal/ids.js'
|
|
54
|
+
import { composeAction } from './internal/events.js'
|
|
55
|
+
|
|
56
|
+
type Intent = 'first' | 'last' | 'none'
|
|
57
|
+
export type MenubarProps = Omit<
|
|
58
|
+
ComponentProps<'div'>,
|
|
59
|
+
| 'role'
|
|
60
|
+
| 'aria-orientation'
|
|
61
|
+
| 'tabIndex'
|
|
62
|
+
| 'style'
|
|
63
|
+
| 'defaultValue'
|
|
64
|
+
| 'value'
|
|
65
|
+
| 'contentEditable'
|
|
66
|
+
| 'dangerouslySetInnerHTML'
|
|
67
|
+
> &
|
|
68
|
+
AccessibleName &
|
|
69
|
+
ValueOwner<string | null> & {
|
|
70
|
+
onValueChange?: (value: string | null) => void
|
|
71
|
+
loop?: boolean
|
|
72
|
+
style?: ThemeStyle
|
|
73
|
+
'data-slot'?: string
|
|
74
|
+
}
|
|
75
|
+
export type MenubarState = {
|
|
76
|
+
value: string | null
|
|
77
|
+
controlled: boolean
|
|
78
|
+
loop: boolean
|
|
79
|
+
setValue: (value: string | null) => void
|
|
80
|
+
}
|
|
81
|
+
export type MenubarMenuProps = { value: string; children?: ReactNode }
|
|
82
|
+
export type MenubarTriggerProps = DistributiveOmit<
|
|
83
|
+
MenuTriggerProps,
|
|
84
|
+
| 'role'
|
|
85
|
+
| 'tabIndex'
|
|
86
|
+
| 'aria-disabled'
|
|
87
|
+
| 'pressed'
|
|
88
|
+
| 'defaultPressed'
|
|
89
|
+
| 'onPressedChange'
|
|
90
|
+
| 'aria-pressed'
|
|
91
|
+
>
|
|
92
|
+
export type MenubarContentProps = MenuContentProps
|
|
93
|
+
export type MenubarPortalProps = MenuPortalProps
|
|
94
|
+
export type MenubarItemProps = MenuItemProps
|
|
95
|
+
export type MenubarGroupProps = MenuGroupProps
|
|
96
|
+
export type MenubarLabelProps = MenuLabelProps
|
|
97
|
+
export type MenubarSeparatorProps = MenuSeparatorProps
|
|
98
|
+
export type MenubarCheckboxItemProps = MenuCheckboxItemProps
|
|
99
|
+
export type MenubarRadioGroupProps = MenuRadioGroupProps
|
|
100
|
+
export type MenubarRadioItemProps = MenuRadioItemProps
|
|
101
|
+
export type MenubarSubProps = MenuSubProps
|
|
102
|
+
export type MenubarSubTriggerProps = MenuSubTriggerProps
|
|
103
|
+
export type MenubarSubContentProps = MenuSubContentProps
|
|
104
|
+
export type MenubarRenderProps = MenuRenderProps
|
|
105
|
+
type Context = MenubarState & {
|
|
106
|
+
host: RefObject<HTMLDivElement | null>
|
|
107
|
+
intent: Intent
|
|
108
|
+
setIntent: (intent: Intent) => void
|
|
109
|
+
request: (value: string | null) => void
|
|
110
|
+
select: (value: string | null, intent?: Intent) => void
|
|
111
|
+
move: (from: string, step: -1 | 1 | 'first' | 'last') => void
|
|
112
|
+
}
|
|
113
|
+
const MenubarContext = createContext<Context | null>(null),
|
|
114
|
+
MenuValueContext = createContext<string | null>(null)
|
|
115
|
+
export function useMenubar(): MenubarState | null {
|
|
116
|
+
return useContext(MenubarContext)
|
|
117
|
+
}
|
|
118
|
+
function useBar() {
|
|
119
|
+
const bar = useContext(MenubarContext)
|
|
120
|
+
if (!bar) throw new Error('Menubar parts must render inside Menubar.')
|
|
121
|
+
return bar
|
|
122
|
+
}
|
|
123
|
+
function useOwner() {
|
|
124
|
+
const bar = useBar(),
|
|
125
|
+
value = useContext(MenuValueContext),
|
|
126
|
+
family = useMenuFamily()
|
|
127
|
+
if (value === null || family !== 'menubar')
|
|
128
|
+
throw new Error('Menubar parts must render inside MenubarMenu.')
|
|
129
|
+
return { bar, value }
|
|
130
|
+
}
|
|
131
|
+
const selector = 'button[data-slot~="menubar-trigger"]'
|
|
132
|
+
export function Menubar({
|
|
133
|
+
ref,
|
|
134
|
+
value,
|
|
135
|
+
defaultValue,
|
|
136
|
+
onValueChange,
|
|
137
|
+
loop = true,
|
|
138
|
+
className,
|
|
139
|
+
onFocus,
|
|
140
|
+
onBlur,
|
|
141
|
+
onKeyDown,
|
|
142
|
+
children,
|
|
143
|
+
...props
|
|
144
|
+
}: MenubarProps) {
|
|
145
|
+
requireAccessibleName('Menubar', props)
|
|
146
|
+
const state = useControllableState<string | null>({
|
|
147
|
+
name: 'Menubar',
|
|
148
|
+
value,
|
|
149
|
+
defaultValue,
|
|
150
|
+
initialValue: null,
|
|
151
|
+
onChange: onValueChange
|
|
152
|
+
}),
|
|
153
|
+
[intent, setIntent] = useState<Intent>('first'),
|
|
154
|
+
host = useRef<HTMLDivElement>(null),
|
|
155
|
+
composed = useComposedRefs(host, ref)
|
|
156
|
+
if (state.value !== null && typeof state.value !== 'string')
|
|
157
|
+
throw new TypeError('Menubar value must be a string or null.')
|
|
158
|
+
const roving = useRovingFocus({
|
|
159
|
+
host,
|
|
160
|
+
selector,
|
|
161
|
+
scope: '[data-slot~="menubar"]',
|
|
162
|
+
orientation: 'horizontal',
|
|
163
|
+
loop,
|
|
164
|
+
preferred: state.value,
|
|
165
|
+
includeAriaDisabled: true
|
|
166
|
+
})
|
|
167
|
+
const select = (next: string | null, edge: Intent = 'first') => {
|
|
168
|
+
setIntent(edge)
|
|
169
|
+
state.request(next)
|
|
170
|
+
}
|
|
171
|
+
const move = (from: string, step: -1 | 1 | 'first' | 'last') => {
|
|
172
|
+
const node = host.current
|
|
173
|
+
if (!node) return
|
|
174
|
+
const triggers = roving.items(node),
|
|
175
|
+
index = triggers.findIndex(trigger => trigger.dataset.value === from)
|
|
176
|
+
if (index < 0 || !triggers.length) return
|
|
177
|
+
const nextIndex =
|
|
178
|
+
step === 'first'
|
|
179
|
+
? 0
|
|
180
|
+
: step === 'last'
|
|
181
|
+
? triggers.length - 1
|
|
182
|
+
: loop
|
|
183
|
+
? (index + step + triggers.length) % triggers.length
|
|
184
|
+
: Math.max(0, Math.min(triggers.length - 1, index + step))
|
|
185
|
+
const next = triggers[nextIndex]
|
|
186
|
+
if (!next || next === triggers[index]) return
|
|
187
|
+
if (next.getAttribute('aria-disabled') === 'true' || next.getAttribute('aria-busy') === 'true')
|
|
188
|
+
next.focus({ preventScroll: true })
|
|
189
|
+
else if (next.dataset.value !== undefined) select(next.dataset.value, 'first')
|
|
190
|
+
}
|
|
191
|
+
return (
|
|
192
|
+
<MenubarContext.Provider
|
|
193
|
+
value={{
|
|
194
|
+
value: state.value,
|
|
195
|
+
controlled: state.controlled,
|
|
196
|
+
loop,
|
|
197
|
+
setValue: next => select(next),
|
|
198
|
+
host,
|
|
199
|
+
intent,
|
|
200
|
+
setIntent,
|
|
201
|
+
select,
|
|
202
|
+
request: state.request,
|
|
203
|
+
move
|
|
204
|
+
}}
|
|
205
|
+
>
|
|
206
|
+
<div
|
|
207
|
+
{...props}
|
|
208
|
+
ref={composed}
|
|
209
|
+
role="menubar"
|
|
210
|
+
aria-orientation="horizontal"
|
|
211
|
+
tabIndex={-1}
|
|
212
|
+
contentEditable={undefined}
|
|
213
|
+
dangerouslySetInnerHTML={undefined}
|
|
214
|
+
data-slot={joinIds('menubar', props['data-slot'])}
|
|
215
|
+
data-state={state.value === null ? 'closed' : 'open'}
|
|
216
|
+
className={cn(
|
|
217
|
+
'inline-flex w-fit max-w-full flex-wrap items-center gap-[var(--rad-menubar-gap,0.25rem)] p-[var(--rad-menubar-padding,0.25rem)] rounded-[var(--rad-menubar-radius,var(--rad-control-radius,0.5rem))] bg-[var(--rad-menubar-background,var(--rad-color-surface))]',
|
|
218
|
+
className
|
|
219
|
+
)}
|
|
220
|
+
onFocus={event => {
|
|
221
|
+
onFocus?.(event)
|
|
222
|
+
roving.onFocus(event)
|
|
223
|
+
}}
|
|
224
|
+
onBlur={event => {
|
|
225
|
+
onBlur?.(event)
|
|
226
|
+
roving.onBlur(event)
|
|
227
|
+
}}
|
|
228
|
+
onKeyDown={event => {
|
|
229
|
+
onKeyDown?.(event)
|
|
230
|
+
if (event.defaultPrevented) return
|
|
231
|
+
const target = event.target as HTMLElement,
|
|
232
|
+
current = target.closest<HTMLElement>(selector)
|
|
233
|
+
if (
|
|
234
|
+
state.value !== null &&
|
|
235
|
+
current?.closest('[data-slot~="menubar"]') === event.currentTarget &&
|
|
236
|
+
!target.closest('[role="menu"]') &&
|
|
237
|
+
!event.altKey &&
|
|
238
|
+
!event.ctrlKey &&
|
|
239
|
+
!event.metaKey &&
|
|
240
|
+
!event.nativeEvent.isComposing
|
|
241
|
+
) {
|
|
242
|
+
const rtl =
|
|
243
|
+
event.currentTarget.ownerDocument.defaultView!.getComputedStyle(event.currentTarget)
|
|
244
|
+
.direction === 'rtl',
|
|
245
|
+
step =
|
|
246
|
+
event.key === 'Home'
|
|
247
|
+
? 'first'
|
|
248
|
+
: event.key === 'End'
|
|
249
|
+
? 'last'
|
|
250
|
+
: event.key === (rtl ? 'ArrowLeft' : 'ArrowRight')
|
|
251
|
+
? 1
|
|
252
|
+
: event.key === (rtl ? 'ArrowRight' : 'ArrowLeft')
|
|
253
|
+
? -1
|
|
254
|
+
: null
|
|
255
|
+
if (step !== null && current.dataset.value !== undefined) {
|
|
256
|
+
event.preventDefault()
|
|
257
|
+
move(current.dataset.value, step)
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
roving.onKeyDown(event)
|
|
262
|
+
}}
|
|
263
|
+
>
|
|
264
|
+
{children}
|
|
265
|
+
</div>
|
|
266
|
+
</MenubarContext.Provider>
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
export function MenubarMenu({ value, children }: MenubarMenuProps) {
|
|
270
|
+
const bar = useBar()
|
|
271
|
+
if (typeof value !== 'string') throw new TypeError('MenubarMenu requires a string value.')
|
|
272
|
+
return (
|
|
273
|
+
<MenuRoot
|
|
274
|
+
open={bar.value === value}
|
|
275
|
+
onOpenChange={next => {
|
|
276
|
+
if (next) bar.request(value)
|
|
277
|
+
else if (bar.value === value) bar.request(null)
|
|
278
|
+
}}
|
|
279
|
+
family="menubar"
|
|
280
|
+
parent={undefined}
|
|
281
|
+
anchorPoint={undefined}
|
|
282
|
+
focusIntent={bar.intent}
|
|
283
|
+
>
|
|
284
|
+
<MenuOwner value={value}>{children}</MenuOwner>
|
|
285
|
+
</MenuRoot>
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
function MenuOwner({ value, children }: MenubarMenuProps) {
|
|
289
|
+
const bar = useBar(),
|
|
290
|
+
menu = useMenuContext(),
|
|
291
|
+
intent = useRef(bar.intent)
|
|
292
|
+
useLayoutEffect(() => {
|
|
293
|
+
intent.current = bar.intent
|
|
294
|
+
})
|
|
295
|
+
useLayoutEffect(() => {
|
|
296
|
+
if (menu.open && intent.current === 'none') menu.trigger.current?.focus({ preventScroll: true })
|
|
297
|
+
}, [menu.open, menu.trigger])
|
|
298
|
+
return <MenuValueContext.Provider value={value}>{children}</MenuValueContext.Provider>
|
|
299
|
+
}
|
|
300
|
+
export function MenubarTrigger({
|
|
301
|
+
disabled = false,
|
|
302
|
+
pending = false,
|
|
303
|
+
ref,
|
|
304
|
+
onClick,
|
|
305
|
+
onKeyDown,
|
|
306
|
+
onPointerMove,
|
|
307
|
+
className,
|
|
308
|
+
variant = 'ghost',
|
|
309
|
+
tone = 'neutral',
|
|
310
|
+
motion,
|
|
311
|
+
...props
|
|
312
|
+
}: MenubarTriggerProps) {
|
|
313
|
+
const { bar, value } = useOwner(),
|
|
314
|
+
menu = useMenuContext()
|
|
315
|
+
if (menu.parent) throw new Error('MenubarTrigger belongs directly to MenubarMenu.')
|
|
316
|
+
return (
|
|
317
|
+
<MenuTrigger
|
|
318
|
+
{...props}
|
|
319
|
+
ref={ref}
|
|
320
|
+
disabled={undefined}
|
|
321
|
+
motion={disabled ? 'off' : motion}
|
|
322
|
+
pending={pending}
|
|
323
|
+
role="menuitem"
|
|
324
|
+
tabIndex={-1}
|
|
325
|
+
aria-disabled={disabled || undefined}
|
|
326
|
+
pressed={undefined}
|
|
327
|
+
defaultPressed={undefined}
|
|
328
|
+
onPressedChange={undefined}
|
|
329
|
+
aria-pressed={undefined}
|
|
330
|
+
variant={variant}
|
|
331
|
+
tone={tone}
|
|
332
|
+
data-value={value}
|
|
333
|
+
data-slot={joinIds('menubar-trigger', props['data-slot'])}
|
|
334
|
+
className={cn(
|
|
335
|
+
'aria-expanded:bg-[var(--rad-menu-item-focus-background,color-mix(in_oklab,var(--rad-color-accent)_12%,var(--rad-color-surface)))] aria-expanded:[color:var(--rad-menu-item-focus-color,color-mix(in_oklab,var(--rad-color-accent)_25%,var(--rad-color-foreground)))] aria-disabled:cursor-not-allowed aria-disabled:opacity-[var(--rad-state-disabled-opacity,0.5)] forced-colors:aria-disabled:text-[GrayText] forced-colors:aria-disabled:opacity-100',
|
|
336
|
+
className
|
|
337
|
+
)}
|
|
338
|
+
onClick={composeAction(
|
|
339
|
+
onClick,
|
|
340
|
+
() => bar.setIntent('first'),
|
|
341
|
+
() => disabled
|
|
342
|
+
)}
|
|
343
|
+
onKeyDown={event => {
|
|
344
|
+
onKeyDown?.(event)
|
|
345
|
+
if (event.defaultPrevented) return
|
|
346
|
+
if (['Enter', ' ', 'ArrowDown', 'ArrowUp'].includes(event.key)) {
|
|
347
|
+
if (disabled || pending || event.currentTarget.matches(':disabled')) {
|
|
348
|
+
event.preventDefault()
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
bar.setIntent(event.key === 'ArrowUp' ? 'last' : 'first')
|
|
352
|
+
}
|
|
353
|
+
}}
|
|
354
|
+
onPointerMove={event => {
|
|
355
|
+
onPointerMove?.(event)
|
|
356
|
+
if (
|
|
357
|
+
event.defaultPrevented ||
|
|
358
|
+
event.pointerType === 'touch' ||
|
|
359
|
+
disabled ||
|
|
360
|
+
pending ||
|
|
361
|
+
event.currentTarget.matches(':disabled') ||
|
|
362
|
+
bar.value === null ||
|
|
363
|
+
bar.value === value
|
|
364
|
+
)
|
|
365
|
+
return
|
|
366
|
+
bar.select(value, 'none')
|
|
367
|
+
}}
|
|
368
|
+
/>
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
export function MenubarContent({ onKeyDown, ...props }: MenubarContentProps) {
|
|
372
|
+
const { bar, value } = useOwner()
|
|
373
|
+
return (
|
|
374
|
+
<MenuContentRoot
|
|
375
|
+
{...props}
|
|
376
|
+
onFocusOutside={() => {
|
|
377
|
+
const node = bar.host.current
|
|
378
|
+
if (node && !node.contains(node.ownerDocument.activeElement)) bar.select(null)
|
|
379
|
+
}}
|
|
380
|
+
data-slot={joinIds('menubar-content', props['data-slot'])}
|
|
381
|
+
onKeyDown={event => {
|
|
382
|
+
onKeyDown?.(event)
|
|
383
|
+
if (
|
|
384
|
+
event.defaultPrevented ||
|
|
385
|
+
event.altKey ||
|
|
386
|
+
event.ctrlKey ||
|
|
387
|
+
event.metaKey ||
|
|
388
|
+
event.nativeEvent.isComposing
|
|
389
|
+
)
|
|
390
|
+
return
|
|
391
|
+
const node = bar.host.current
|
|
392
|
+
if (!node) return
|
|
393
|
+
const rtl = node.ownerDocument.defaultView!.getComputedStyle(node).direction === 'rtl'
|
|
394
|
+
if (event.key === (rtl ? 'ArrowLeft' : 'ArrowRight')) {
|
|
395
|
+
event.preventDefault()
|
|
396
|
+
bar.move(value, 1)
|
|
397
|
+
} else if (
|
|
398
|
+
event.key === (rtl ? 'ArrowRight' : 'ArrowLeft') &&
|
|
399
|
+
(event.target as HTMLElement).closest('[role="menu"]') === event.currentTarget
|
|
400
|
+
) {
|
|
401
|
+
event.preventDefault()
|
|
402
|
+
bar.move(value, -1)
|
|
403
|
+
}
|
|
404
|
+
}}
|
|
405
|
+
/>
|
|
406
|
+
)
|
|
407
|
+
}
|
|
408
|
+
export function MenubarPortal(props: MenubarPortalProps) {
|
|
409
|
+
useOwner()
|
|
410
|
+
return <MenuPortal {...props} />
|
|
411
|
+
}
|
|
412
|
+
export function MenubarItem(props: MenubarItemProps) {
|
|
413
|
+
useOwner()
|
|
414
|
+
return (
|
|
415
|
+
<MenuItem
|
|
416
|
+
{...props}
|
|
417
|
+
data-slot={joinIds('menubar-item', props['data-slot'])}
|
|
418
|
+
/>
|
|
419
|
+
)
|
|
420
|
+
}
|
|
421
|
+
export function MenubarGroup(props: MenubarGroupProps) {
|
|
422
|
+
useOwner()
|
|
423
|
+
return (
|
|
424
|
+
<MenuGroup
|
|
425
|
+
{...props}
|
|
426
|
+
data-slot={joinIds('menubar-group', props['data-slot'])}
|
|
427
|
+
/>
|
|
428
|
+
)
|
|
429
|
+
}
|
|
430
|
+
export function MenubarLabel(props: MenubarLabelProps) {
|
|
431
|
+
useOwner()
|
|
432
|
+
return (
|
|
433
|
+
<MenuLabel
|
|
434
|
+
{...props}
|
|
435
|
+
data-slot={joinIds('menubar-label', props['data-slot'])}
|
|
436
|
+
/>
|
|
437
|
+
)
|
|
438
|
+
}
|
|
439
|
+
export function MenubarSeparator(props: MenubarSeparatorProps) {
|
|
440
|
+
useOwner()
|
|
441
|
+
return (
|
|
442
|
+
<MenuSeparator
|
|
443
|
+
{...props}
|
|
444
|
+
data-slot={joinIds('menubar-separator', props['data-slot'])}
|
|
445
|
+
/>
|
|
446
|
+
)
|
|
447
|
+
}
|
|
448
|
+
export function MenubarCheckboxItem(props: MenubarCheckboxItemProps) {
|
|
449
|
+
useOwner()
|
|
450
|
+
return (
|
|
451
|
+
<MenuCheckboxItem
|
|
452
|
+
{...props}
|
|
453
|
+
data-slot={joinIds('menubar-checkbox-item', props['data-slot'])}
|
|
454
|
+
/>
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
export function MenubarRadioGroup(props: MenubarRadioGroupProps) {
|
|
458
|
+
useOwner()
|
|
459
|
+
return (
|
|
460
|
+
<MenuRadioGroup
|
|
461
|
+
{...props}
|
|
462
|
+
data-slot={joinIds('menubar-radio-group', props['data-slot'])}
|
|
463
|
+
/>
|
|
464
|
+
)
|
|
465
|
+
}
|
|
466
|
+
export function MenubarRadioItem(props: MenubarRadioItemProps) {
|
|
467
|
+
useOwner()
|
|
468
|
+
return (
|
|
469
|
+
<MenuRadioItem
|
|
470
|
+
{...props}
|
|
471
|
+
data-slot={joinIds('menubar-radio-item', props['data-slot'])}
|
|
472
|
+
/>
|
|
473
|
+
)
|
|
474
|
+
}
|
|
475
|
+
export function MenubarSub(props: MenubarSubProps) {
|
|
476
|
+
useOwner()
|
|
477
|
+
return <MenuSub {...props} />
|
|
478
|
+
}
|
|
479
|
+
export function MenubarSubTrigger(props: MenubarSubTriggerProps) {
|
|
480
|
+
useOwner()
|
|
481
|
+
return (
|
|
482
|
+
<MenuSubTrigger
|
|
483
|
+
{...props}
|
|
484
|
+
data-slot={joinIds('menubar-sub-trigger', props['data-slot'])}
|
|
485
|
+
/>
|
|
486
|
+
)
|
|
487
|
+
}
|
|
488
|
+
export function MenubarSubContent(props: MenubarSubContentProps) {
|
|
489
|
+
useOwner()
|
|
490
|
+
return (
|
|
491
|
+
<MenuSubContent
|
|
492
|
+
{...props}
|
|
493
|
+
data-slot={joinIds('menubar-sub-content', props['data-slot'])}
|
|
494
|
+
/>
|
|
495
|
+
)
|
|
496
|
+
}
|
package/src/Popover.tsx
CHANGED
|
@@ -32,6 +32,7 @@ export type PopoverProps = (
|
|
|
32
32
|
}
|
|
33
33
|
export type PopoverState = { open: boolean; setOpen: (open: boolean) => void; contentId: string }
|
|
34
34
|
type Context = PopoverState & {
|
|
35
|
+
anchorPoint?: { x: number; y: number }
|
|
35
36
|
trigger: HTMLElement | null
|
|
36
37
|
setTrigger: (node: HTMLElement | null) => void
|
|
37
38
|
content: RefObject<HTMLDivElement | null>
|
|
@@ -48,7 +49,22 @@ export function usePopoverContext() {
|
|
|
48
49
|
if (!value) throw new Error('Popover parts must render inside Popover.')
|
|
49
50
|
return value
|
|
50
51
|
}
|
|
51
|
-
export function Popover(
|
|
52
|
+
export function Popover(props: PopoverProps) {
|
|
53
|
+
return (
|
|
54
|
+
<PopoverRoot
|
|
55
|
+
{...props}
|
|
56
|
+
anchorPoint={undefined}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
/** Private pointer anchor for composed context menus; the real source retains focus ownership. */
|
|
61
|
+
export function PopoverRoot({
|
|
62
|
+
open,
|
|
63
|
+
defaultOpen,
|
|
64
|
+
onOpenChange,
|
|
65
|
+
children,
|
|
66
|
+
anchorPoint
|
|
67
|
+
}: PopoverProps & { anchorPoint?: { x: number; y: number } }) {
|
|
52
68
|
const state = useControllableState({
|
|
53
69
|
name: 'Popover',
|
|
54
70
|
value: open,
|
|
@@ -74,6 +90,7 @@ export function Popover({ open, defaultOpen, onOpenChange, children }: PopoverPr
|
|
|
74
90
|
open: state.value,
|
|
75
91
|
setOpen,
|
|
76
92
|
contentId,
|
|
93
|
+
anchorPoint,
|
|
77
94
|
trigger,
|
|
78
95
|
setTrigger,
|
|
79
96
|
content,
|
|
@@ -118,7 +135,22 @@ export function PopoverTrigger({ ref, onClick, ...props }: PopoverTriggerProps)
|
|
|
118
135
|
/>
|
|
119
136
|
)
|
|
120
137
|
}
|
|
121
|
-
export function PopoverClose(
|
|
138
|
+
export function PopoverClose(props: PopoverCloseProps) {
|
|
139
|
+
return (
|
|
140
|
+
<PopoverCloseRoot
|
|
141
|
+
{...props}
|
|
142
|
+
requestClose={undefined}
|
|
143
|
+
closeOnClick={undefined}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
/** Private close-action policy for composed menus; keeps the real Button and identities. */
|
|
148
|
+
export function PopoverCloseRoot({
|
|
149
|
+
onClick,
|
|
150
|
+
requestClose,
|
|
151
|
+
closeOnClick = true,
|
|
152
|
+
...props
|
|
153
|
+
}: PopoverCloseProps & { requestClose?: () => void; closeOnClick?: boolean }) {
|
|
122
154
|
const popover = usePopoverContext()
|
|
123
155
|
return (
|
|
124
156
|
<Button
|
|
@@ -126,7 +158,9 @@ export function PopoverClose({ onClick, ...props }: PopoverCloseProps) {
|
|
|
126
158
|
popoverTarget={undefined}
|
|
127
159
|
popoverTargetAction={undefined}
|
|
128
160
|
data-slot={joinIds('popover-close', props['data-slot'])}
|
|
129
|
-
onClick={composeAction(onClick, () =>
|
|
161
|
+
onClick={composeAction(onClick, () => {
|
|
162
|
+
if (closeOnClick) (requestClose ?? (() => popover.close(true)))()
|
|
163
|
+
})}
|
|
130
164
|
/>
|
|
131
165
|
)
|
|
132
166
|
}
|
|
@@ -190,7 +224,15 @@ export function PopoverContentRoot({
|
|
|
190
224
|
popover.open,
|
|
191
225
|
popover.close,
|
|
192
226
|
popover.restoreFocus,
|
|
193
|
-
{
|
|
227
|
+
{
|
|
228
|
+
side,
|
|
229
|
+
align,
|
|
230
|
+
sideOffset,
|
|
231
|
+
collisionPadding,
|
|
232
|
+
initialFocusRef,
|
|
233
|
+
onFocusOutside,
|
|
234
|
+
anchorPoint: popover.anchorPoint
|
|
235
|
+
}
|
|
194
236
|
)
|
|
195
237
|
return (
|
|
196
238
|
<div
|
package/src/cn.ts
CHANGED
|
@@ -63,6 +63,7 @@ export const cn: CnFunction = createCn({
|
|
|
63
63
|
'h-(--rad-slider-length)'
|
|
64
64
|
],
|
|
65
65
|
w: [
|
|
66
|
+
'w-(--rad-context-menu-width)',
|
|
66
67
|
'w-(--rad-hover-card-width)',
|
|
67
68
|
'w-(--rad-scroll-area-size)',
|
|
68
69
|
'w-(--rad-skeleton-width)',
|
|
@@ -87,6 +88,7 @@ export const cn: CnFunction = createCn({
|
|
|
87
88
|
],
|
|
88
89
|
mb: ['mb-(--rad-fieldset-gap)'],
|
|
89
90
|
gap: [
|
|
91
|
+
'gap-(--rad-menubar-gap)',
|
|
90
92
|
'gap-(--rad-toolbar-gap)',
|
|
91
93
|
'gap-(--rad-toggle-group-gap)',
|
|
92
94
|
'gap-(--rad-checkbox-group-gap)',
|
|
@@ -115,6 +117,7 @@ export const cn: CnFunction = createCn({
|
|
|
115
117
|
'px-(--rad-tabs-trigger-padding)'
|
|
116
118
|
],
|
|
117
119
|
p: [
|
|
120
|
+
'p-(--rad-menubar-padding)',
|
|
118
121
|
'p-(--rad-toolbar-padding)',
|
|
119
122
|
'p-(--rad-toggle-group-padding)',
|
|
120
123
|
'p-(--rad-toast-padding)',
|
|
@@ -129,6 +132,7 @@ export const cn: CnFunction = createCn({
|
|
|
129
132
|
'p-(--rad-tabs-content-padding)'
|
|
130
133
|
],
|
|
131
134
|
rounded: [
|
|
135
|
+
'rounded-(--rad-menubar-radius)',
|
|
132
136
|
'rounded-(--rad-toolbar-radius)',
|
|
133
137
|
'rounded-(--rad-toggle-group-radius)',
|
|
134
138
|
'rounded-(--rad-toggle-group-indicator-radius)',
|