@cognitap/radiant 0.0.36 → 0.0.38
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 +9 -1
- package/dist/library/Dialog.d.ts +4 -4
- package/dist/library/Dialog.d.ts.map +1 -1
- package/dist/library/Dialog.js +7 -11
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/Drawer.d.ts +50 -0
- package/dist/library/Drawer.d.ts.map +1 -0
- package/dist/library/Drawer.js +146 -0
- package/dist/library/Drawer.js.map +1 -0
- package/dist/library/Menu.d.ts +5 -1
- package/dist/library/Menu.d.ts.map +1 -1
- package/dist/library/Menu.js +7 -3
- 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/cn.d.ts.map +1 -1
- package/dist/library/cn.js +5 -0
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +4 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/internal/drawer.d.ts +39 -0
- package/dist/library/internal/drawer.d.ts.map +1 -0
- package/dist/library/internal/drawer.js +286 -0
- package/dist/library/internal/drawer.js.map +1 -0
- package/dist/library/motion/drawer.d.ts +8 -0
- package/dist/library/motion/drawer.d.ts.map +1 -0
- package/dist/library/motion/drawer.js +37 -0
- package/dist/library/motion/drawer.js.map +1 -0
- package/dist/library/motion/host.d.ts +6 -0
- package/dist/library/motion/host.d.ts.map +1 -1
- package/dist/library/motion/host.js +29 -0
- package/dist/library/motion/host.js.map +1 -1
- package/dist/library/motion/react.d.ts.map +1 -1
- package/dist/library/motion/react.js +2 -0
- package/dist/library/motion/react.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 +24 -19
- package/package.json +1 -1
- package/src/Dialog.tsx +14 -13
- package/src/Drawer.tsx +288 -0
- package/src/Menu.tsx +20 -3
- package/src/Menubar.tsx +496 -0
- package/src/cn.ts +5 -0
- package/src/index.ts +61 -0
- package/src/internal/drawer.ts +336 -0
- package/src/motion/drawer.ts +43 -0
- package/src/motion/host.ts +44 -0
- package/src/motion/react.ts +2 -0
- 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/cn.ts
CHANGED
|
@@ -53,6 +53,7 @@ export const cn: CnFunction = createCn({
|
|
|
53
53
|
'text-(--rad-tabs-font-size)'
|
|
54
54
|
],
|
|
55
55
|
h: [
|
|
56
|
+
'h-(--rad-drawer-size)',
|
|
56
57
|
'h-(--rad-scroll-area-size)',
|
|
57
58
|
'h-(--rad-skeleton-height)',
|
|
58
59
|
'h-(--rad-progress-height)',
|
|
@@ -63,6 +64,7 @@ export const cn: CnFunction = createCn({
|
|
|
63
64
|
'h-(--rad-slider-length)'
|
|
64
65
|
],
|
|
65
66
|
w: [
|
|
67
|
+
'w-(--rad-drawer-size)',
|
|
66
68
|
'w-(--rad-context-menu-width)',
|
|
67
69
|
'w-(--rad-hover-card-width)',
|
|
68
70
|
'w-(--rad-scroll-area-size)',
|
|
@@ -88,6 +90,7 @@ export const cn: CnFunction = createCn({
|
|
|
88
90
|
],
|
|
89
91
|
mb: ['mb-(--rad-fieldset-gap)'],
|
|
90
92
|
gap: [
|
|
93
|
+
'gap-(--rad-menubar-gap)',
|
|
91
94
|
'gap-(--rad-toolbar-gap)',
|
|
92
95
|
'gap-(--rad-toggle-group-gap)',
|
|
93
96
|
'gap-(--rad-checkbox-group-gap)',
|
|
@@ -116,6 +119,7 @@ export const cn: CnFunction = createCn({
|
|
|
116
119
|
'px-(--rad-tabs-trigger-padding)'
|
|
117
120
|
],
|
|
118
121
|
p: [
|
|
122
|
+
'p-(--rad-menubar-padding)',
|
|
119
123
|
'p-(--rad-toolbar-padding)',
|
|
120
124
|
'p-(--rad-toggle-group-padding)',
|
|
121
125
|
'p-(--rad-toast-padding)',
|
|
@@ -130,6 +134,7 @@ export const cn: CnFunction = createCn({
|
|
|
130
134
|
'p-(--rad-tabs-content-padding)'
|
|
131
135
|
],
|
|
132
136
|
rounded: [
|
|
137
|
+
'rounded-(--rad-menubar-radius)',
|
|
133
138
|
'rounded-(--rad-toolbar-radius)',
|
|
134
139
|
'rounded-(--rad-toggle-group-radius)',
|
|
135
140
|
'rounded-(--rad-toggle-group-indicator-radius)',
|
package/src/index.ts
CHANGED
|
@@ -469,3 +469,64 @@ export type {
|
|
|
469
469
|
ContextMenuSubContentProps,
|
|
470
470
|
ContextMenuState
|
|
471
471
|
} from './ContextMenu.js'
|
|
472
|
+
|
|
473
|
+
export {
|
|
474
|
+
Menubar,
|
|
475
|
+
MenubarMenu,
|
|
476
|
+
MenubarTrigger,
|
|
477
|
+
MenubarPortal,
|
|
478
|
+
MenubarContent,
|
|
479
|
+
MenubarItem,
|
|
480
|
+
MenubarGroup,
|
|
481
|
+
MenubarLabel,
|
|
482
|
+
MenubarSeparator,
|
|
483
|
+
MenubarCheckboxItem,
|
|
484
|
+
MenubarRadioGroup,
|
|
485
|
+
MenubarRadioItem,
|
|
486
|
+
MenubarSub,
|
|
487
|
+
MenubarSubTrigger,
|
|
488
|
+
MenubarSubContent,
|
|
489
|
+
useMenubar
|
|
490
|
+
} from './Menubar.js'
|
|
491
|
+
export type {
|
|
492
|
+
MenubarProps,
|
|
493
|
+
MenubarMenuProps,
|
|
494
|
+
MenubarTriggerProps,
|
|
495
|
+
MenubarPortalProps,
|
|
496
|
+
MenubarContentProps,
|
|
497
|
+
MenubarItemProps,
|
|
498
|
+
MenubarGroupProps,
|
|
499
|
+
MenubarLabelProps,
|
|
500
|
+
MenubarSeparatorProps,
|
|
501
|
+
MenubarCheckboxItemProps,
|
|
502
|
+
MenubarRadioGroupProps,
|
|
503
|
+
MenubarRadioItemProps,
|
|
504
|
+
MenubarSubProps,
|
|
505
|
+
MenubarSubTriggerProps,
|
|
506
|
+
MenubarSubContentProps,
|
|
507
|
+
MenubarState,
|
|
508
|
+
MenubarRenderProps
|
|
509
|
+
} from './Menubar.js'
|
|
510
|
+
|
|
511
|
+
export {
|
|
512
|
+
Drawer,
|
|
513
|
+
DrawerTrigger,
|
|
514
|
+
DrawerContent,
|
|
515
|
+
DrawerTitle,
|
|
516
|
+
DrawerDescription,
|
|
517
|
+
DrawerClose,
|
|
518
|
+
DrawerHandle,
|
|
519
|
+
useDrawer
|
|
520
|
+
} from './Drawer.js'
|
|
521
|
+
export type {
|
|
522
|
+
DrawerProps,
|
|
523
|
+
DrawerTriggerProps,
|
|
524
|
+
DrawerRenderProps,
|
|
525
|
+
DrawerContentProps,
|
|
526
|
+
DrawerTitleProps,
|
|
527
|
+
DrawerDescriptionProps,
|
|
528
|
+
DrawerCloseProps,
|
|
529
|
+
DrawerHandleProps,
|
|
530
|
+
DrawerSide,
|
|
531
|
+
DrawerState
|
|
532
|
+
} from './Drawer.js'
|