@cognitap/radiant 0.0.65 → 0.0.67

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 (75) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/library/AppShell.d.ts +71 -0
  3. package/dist/library/AppShell.d.ts.map +1 -0
  4. package/dist/library/AppShell.js +189 -0
  5. package/dist/library/AppShell.js.map +1 -0
  6. package/dist/library/Button.d.ts +2 -7
  7. package/dist/library/Button.d.ts.map +1 -1
  8. package/dist/library/Button.js.map +1 -1
  9. package/dist/library/ButtonGroup.d.ts +4 -1
  10. package/dist/library/ButtonGroup.d.ts.map +1 -1
  11. package/dist/library/ButtonGroup.js +2 -1
  12. package/dist/library/ButtonGroup.js.map +1 -1
  13. package/dist/library/CheckboxGroup.d.ts +6 -4
  14. package/dist/library/CheckboxGroup.d.ts.map +1 -1
  15. package/dist/library/CheckboxGroup.js +17 -21
  16. package/dist/library/CheckboxGroup.js.map +1 -1
  17. package/dist/library/Command.d.ts +1 -2
  18. package/dist/library/Command.d.ts.map +1 -1
  19. package/dist/library/Command.js +1 -1
  20. package/dist/library/Command.js.map +1 -1
  21. package/dist/library/Drawer.d.ts +8 -17
  22. package/dist/library/Drawer.d.ts.map +1 -1
  23. package/dist/library/Drawer.js +2 -2
  24. package/dist/library/Drawer.js.map +1 -1
  25. package/dist/library/Field.d.ts.map +1 -1
  26. package/dist/library/Field.js +1 -1
  27. package/dist/library/Field.js.map +1 -1
  28. package/dist/library/PasswordInput.d.ts.map +1 -1
  29. package/dist/library/PasswordInput.js +1 -1
  30. package/dist/library/PasswordInput.js.map +1 -1
  31. package/dist/library/ScrollArea.d.ts +2 -2
  32. package/dist/library/ScrollArea.d.ts.map +1 -1
  33. package/dist/library/cn.d.ts.map +1 -1
  34. package/dist/library/cn.js +10 -0
  35. package/dist/library/cn.js.map +1 -1
  36. package/dist/library/index.d.ts +2 -0
  37. package/dist/library/index.d.ts.map +1 -1
  38. package/dist/library/index.js +1 -0
  39. package/dist/library/index.js.map +1 -1
  40. package/dist/library/motion/host.d.ts +2 -1
  41. package/dist/library/motion/host.d.ts.map +1 -1
  42. package/dist/library/motion/host.js.map +1 -1
  43. package/dist/library/motion/layoutHost.d.ts +5 -0
  44. package/dist/library/motion/layoutHost.d.ts.map +1 -0
  45. package/dist/library/motion/layoutHost.js +24 -0
  46. package/dist/library/motion/layoutHost.js.map +1 -0
  47. package/dist/library/motion/press.d.ts.map +1 -1
  48. package/dist/library/motion/press.js +6 -5
  49. package/dist/library/motion/press.js.map +1 -1
  50. package/dist/library/motion/react.d.ts.map +1 -1
  51. package/dist/library/motion/react.js +3 -1
  52. package/dist/library/motion/react.js.map +1 -1
  53. package/dist/library/styles.css +1 -1
  54. package/dist/library/themes/components.d.ts +22 -0
  55. package/dist/library/themes/components.d.ts.map +1 -1
  56. package/dist/library/themes/components.js +22 -0
  57. package/dist/library/themes/components.js.map +1 -1
  58. package/docs/architecture.md +10 -7
  59. package/package.json +1 -1
  60. package/src/AppShell.tsx +517 -0
  61. package/src/Button.tsx +2 -4
  62. package/src/ButtonGroup.tsx +6 -2
  63. package/src/CheckboxGroup.tsx +33 -25
  64. package/src/Command.tsx +2 -13
  65. package/src/Drawer.tsx +10 -14
  66. package/src/Field.tsx +5 -1
  67. package/src/PasswordInput.tsx +1 -2
  68. package/src/ScrollArea.tsx +3 -3
  69. package/src/cn.ts +10 -0
  70. package/src/index.ts +26 -0
  71. package/src/motion/host.ts +2 -1
  72. package/src/motion/layoutHost.ts +25 -0
  73. package/src/motion/press.ts +6 -5
  74. package/src/motion/react.ts +3 -1
  75. package/src/themes/components.ts +22 -0
@@ -0,0 +1,517 @@
1
+ 'use client'
2
+
3
+ import {
4
+ createContext,
5
+ useContext,
6
+ useEffect,
7
+ useId,
8
+ useLayoutEffect,
9
+ useRef,
10
+ useState,
11
+ type ComponentProps,
12
+ type ReactNode,
13
+ type RefObject
14
+ } from 'react'
15
+ import { createPortal } from 'react-dom'
16
+ import { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'
17
+ import {
18
+ ComposedLink,
19
+ type ComposedLinkProps,
20
+ type ComposedLinkRenderProps
21
+ } from './composedLink.js'
22
+ import { Drawer, DrawerContent, DrawerTitle, DrawerClose, useDrawer } from './Drawer.js'
23
+ import { cn } from './cn.js'
24
+ import { joinIds } from './internal/ids.js'
25
+ import { composeAction } from './internal/events.js'
26
+ import type { WithoutToggle, DistributiveOmit } from './internal/types.js'
27
+ import { useControllableState } from './react/useControllableState.js'
28
+ import { useComposedRefs } from './react/useComposedRefs.js'
29
+ import type { StateOwner } from './react/useNativeOwner.js'
30
+ import { useTransitionHost } from './motion/host.js'
31
+ import type { PartStyle } from './presentation.js'
32
+ import type { ThemeStyle } from './themes/defineTheme.js'
33
+
34
+ export type AppShellProps = Omit<ComponentProps<'div'>, 'style'> &
35
+ StateOwner<'collapsed', boolean> &
36
+ StateOwner<'open', boolean> & {
37
+ style?: ThemeStyle
38
+ 'data-slot'?: string
39
+ onCollapsedChange?: (collapsed: boolean) => void
40
+ onOpenChange?: (open: boolean) => void
41
+ mainId?: string
42
+ sidebarId?: string
43
+ motion?: 'inherit' | 'off'
44
+ }
45
+ export type AppShellState = {
46
+ collapsed: boolean
47
+ open: boolean
48
+ mobile: boolean
49
+ collapsedControlled: boolean
50
+ openControlled: boolean
51
+ mainId: string
52
+ sidebarId: string
53
+ setCollapsed: (collapsed: boolean) => void
54
+ setOpen: (open: boolean) => void
55
+ }
56
+ type Binding = AppShellState & {
57
+ root: RefObject<HTMLDivElement | null>
58
+ drawerId: string
59
+ labelId: string
60
+ motion: 'inherit' | 'off'
61
+ }
62
+ const Context = createContext<Binding | null>(null)
63
+ export function useAppShell(): AppShellState | null {
64
+ return useContext(Context)
65
+ }
66
+ export function useSidebar(): AppShellState | null {
67
+ return useContext(Context)
68
+ }
69
+ function useBinding() {
70
+ const value = useContext(Context)
71
+ if (!value) throw new Error('AppShell and Sidebar parts must render inside AppShell.')
72
+ return value
73
+ }
74
+ function Provider({
75
+ binding,
76
+ children
77
+ }: {
78
+ binding: Omit<Binding, 'drawerId'>
79
+ children: ReactNode
80
+ }) {
81
+ const drawer = useDrawer()
82
+ if (!drawer) throw new Error('AppShell requires its Drawer.')
83
+ return (
84
+ <Context.Provider value={{ ...binding, drawerId: drawer.contentId }}>
85
+ {children}
86
+ </Context.Provider>
87
+ )
88
+ }
89
+ function toggleFocus(root: HTMLElement | null) {
90
+ ;(
91
+ root?.querySelector<HTMLElement>('[data-slot~="sidebar-trigger"]:not(:disabled)') ??
92
+ root?.querySelector<HTMLElement>('[data-slot~="app-shell-main"]')
93
+ )?.focus({ preventScroll: true })
94
+ }
95
+ export function AppShell({
96
+ collapsed,
97
+ defaultCollapsed,
98
+ onCollapsedChange,
99
+ open,
100
+ defaultOpen,
101
+ onOpenChange,
102
+ mainId,
103
+ sidebarId,
104
+ motion = 'inherit',
105
+ ref,
106
+ className,
107
+ onFocusCapture,
108
+ ...props
109
+ }: AppShellProps) {
110
+ const collapse = useControllableState({
111
+ name: 'AppShell collapsed',
112
+ value: collapsed,
113
+ defaultValue: defaultCollapsed,
114
+ initialValue: false,
115
+ onChange: onCollapsedChange
116
+ }),
117
+ drawer = useControllableState({
118
+ name: 'AppShell open',
119
+ value: open,
120
+ defaultValue: defaultOpen,
121
+ initialValue: false,
122
+ onChange: onOpenChange
123
+ })
124
+ if (typeof collapse.value !== 'boolean' || typeof drawer.value !== 'boolean')
125
+ throw new TypeError('AppShell states must be boolean.')
126
+ for (const id of [mainId, sidebarId])
127
+ if (id !== undefined && (!id || /\s/.test(id)))
128
+ throw new TypeError('AppShell relationship IDs must be nonempty and contain no whitespace.')
129
+ const root = useRef<HTMLDivElement>(null),
130
+ host = useComposedRefs(root, ref),
131
+ { ref: layoutRef } = useTransitionHost('layout', host, motion === 'off'),
132
+ [mobile, setMobile] = useState(false),
133
+ id = useId(),
134
+ latestOpen = useRef(drawer.request),
135
+ focused = useRef<HTMLElement | null>(null),
136
+ previous = useRef(collapse.value)
137
+ useLayoutEffect(() => {
138
+ latestOpen.current = drawer.request
139
+ })
140
+ useEffect(() => {
141
+ const node = root.current
142
+ if (!node) return
143
+ const query = node.ownerDocument.defaultView!.matchMedia('(width < 40rem)')
144
+ setMobile(query.matches)
145
+ const change = () => {
146
+ setMobile(query.matches)
147
+ if (!query.matches) latestOpen.current(false)
148
+ }
149
+ query.addEventListener('change', change)
150
+ return () => query.removeEventListener('change', change)
151
+ }, [])
152
+ useLayoutEffect(() => {
153
+ const node = root.current,
154
+ active = focused.current
155
+ if (
156
+ node &&
157
+ !mobile &&
158
+ collapse.value &&
159
+ !previous.current &&
160
+ active?.closest('[data-slot~="sidebar-content"][data-expanded-only]') &&
161
+ (node.ownerDocument.activeElement === node.ownerDocument.body ||
162
+ node.ownerDocument.activeElement === active)
163
+ )
164
+ toggleFocus(node)
165
+ previous.current = collapse.value
166
+ })
167
+ const setCollapsed = (next: boolean) => {
168
+ if (typeof next !== 'boolean')
169
+ throw new TypeError('AppShell collapsed requests must be boolean.')
170
+ collapse.request(next)
171
+ }
172
+ const setOpen = (next: boolean) => {
173
+ if (typeof next !== 'boolean') throw new TypeError('AppShell open requests must be boolean.')
174
+ drawer.request(next)
175
+ }
176
+ return (
177
+ <Drawer
178
+ open={mobile && drawer.value}
179
+ onOpenChange={setOpen}
180
+ snapPoints={[1]}
181
+ >
182
+ <Provider
183
+ binding={{
184
+ collapsed: collapse.value,
185
+ open: drawer.value,
186
+ mobile,
187
+ collapsedControlled: collapse.controlled,
188
+ openControlled: drawer.controlled,
189
+ setCollapsed,
190
+ setOpen,
191
+ mainId: mainId ?? `${id}-main`,
192
+ sidebarId: sidebarId ?? `${id}-sidebar`,
193
+ labelId: `${id}-sidebar-label`,
194
+ root,
195
+ motion
196
+ }}
197
+ >
198
+ <div
199
+ {...props}
200
+ ref={layoutRef}
201
+ data-slot={joinIds('app-shell', props['data-slot'])}
202
+ data-collapsed={collapse.value || undefined}
203
+ data-mobile={mobile || undefined}
204
+ data-state={
205
+ mobile ? (drawer.value ? 'open' : 'closed') : collapse.value ? 'closed' : 'open'
206
+ }
207
+ data-motion={motion}
208
+ className={cn(
209
+ 'relative grid h-dvh min-h-0 min-w-0 grid-cols-[var(--_rad-shell-sidebar)_minmax(0,1fr)] grid-rows-[auto_minmax(0,1fr)] [--_rad-shell-sidebar:var(--rad-sidebar-width,16rem)] data-collapsed:[--_rad-shell-sidebar:var(--rad-sidebar-collapsed-width,5rem)] max-[40rem]:grid-cols-[0_minmax(0,1fr)] bg-[var(--rad-app-shell-background,var(--rad-color-surface,white))] text-[var(--rad-app-shell-color,var(--rad-color-foreground,black))]',
210
+ className
211
+ )}
212
+ onFocusCapture={event => {
213
+ onFocusCapture?.(event)
214
+ focused.current = event.target
215
+ }}
216
+ >
217
+ {props.children}
218
+ </div>
219
+ </Provider>
220
+ </Drawer>
221
+ )
222
+ }
223
+ export type AppShellHeaderProps = Omit<ComponentProps<'header'>, 'style' | 'role'> & {
224
+ style?: ThemeStyle
225
+ 'data-slot'?: string
226
+ }
227
+ export function AppShellHeader({ className, ...props }: AppShellHeaderProps) {
228
+ useBinding()
229
+ return (
230
+ <div
231
+ data-rad-layout-slot=""
232
+ className="col-span-2 row-start-1 min-w-0"
233
+ >
234
+ <div
235
+ data-rad-layout-part=""
236
+ className="flow-root size-full"
237
+ >
238
+ <header
239
+ {...props}
240
+ role="banner"
241
+ data-slot={joinIds('app-shell-header', props['data-slot'])}
242
+ className={cn(
243
+ 'box-border flex min-w-0 items-center justify-between gap-4 min-h-[var(--rad-app-shell-header-min-height,3.5rem)] p-[var(--rad-app-shell-header-padding,1rem)] border-b-[length:var(--rad-app-shell-header-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-surface-border-style,solid)] border-[var(--rad-app-shell-header-border-color,var(--rad-color-border))] bg-[var(--rad-app-shell-header-background,var(--rad-color-surface))] text-[var(--rad-app-shell-header-color,var(--rad-color-foreground))]',
244
+ className
245
+ )}
246
+ />
247
+ </div>
248
+ </div>
249
+ )
250
+ }
251
+ export type AppShellMainProps = Omit<
252
+ ComponentProps<'main'>,
253
+ 'style' | 'role' | 'id' | 'tabIndex'
254
+ > & { style?: ThemeStyle; 'data-slot'?: string }
255
+ export function AppShellMain({ className, ...props }: AppShellMainProps) {
256
+ const shell = useBinding()
257
+ return (
258
+ <div
259
+ data-rad-layout-slot=""
260
+ className="col-start-2 row-start-2 min-h-0 min-w-0"
261
+ >
262
+ <div
263
+ data-rad-layout-part=""
264
+ className="flow-root size-full"
265
+ >
266
+ <main
267
+ {...props}
268
+ id={shell.mainId}
269
+ role="main"
270
+ tabIndex={-1}
271
+ data-slot={joinIds('app-shell-main', props['data-slot'])}
272
+ className={cn(
273
+ 'box-border size-full min-h-0 min-w-0 overflow-auto p-[var(--rad-app-shell-main-padding,var(--rad-surface-padding,1.5rem))] focus-visible:[outline-style:var(--rad-focus-style,solid)] focus-visible:outline-[color:var(--rad-color-focus)] focus-visible:outline-[length:var(--rad-focus-width,2px)] focus-visible:outline-offset-[-2px]',
274
+ className
275
+ )}
276
+ />
277
+ </div>
278
+ </div>
279
+ )
280
+ }
281
+ export type AppShellRenderProps = ComposedLinkRenderProps
282
+ export type AppShellSkipLinkProps = Omit<ComposedLinkProps, 'href'>
283
+ export function AppShellSkipLink({ className, ...props }: AppShellSkipLinkProps) {
284
+ const shell = useBinding()
285
+ return (
286
+ <ComposedLink
287
+ {...props}
288
+ identity="app-shell-skip-link"
289
+ href={`#${shell.mainId}`}
290
+ className={cn(
291
+ 'sr-only focus:not-sr-only focus:absolute focus:start-2 focus:top-2 focus:z-50 focus:rounded focus:bg-[var(--rad-color-surface)] focus:p-3',
292
+ className
293
+ )}
294
+ />
295
+ )
296
+ }
297
+ export type SidebarProps = Omit<
298
+ ComponentProps<'nav'>,
299
+ 'style' | 'role' | 'id' | 'aria-label' | 'aria-labelledby' | 'tabIndex'
300
+ > & {
301
+ style?: ThemeStyle
302
+ 'data-slot'?: string
303
+ label: ReactNode
304
+ closeLabel?: string
305
+ parts?: { label?: PartStyle; drawer?: PartStyle; viewport?: PartStyle; close?: PartStyle }
306
+ }
307
+ /* oxlint-disable jsx-a11y/no-noninteractive-tabindex -- The named native navigation viewport accepts focus for keyboard scrolling. */
308
+ export function Sidebar({
309
+ label,
310
+ closeLabel = 'Close navigation',
311
+ parts,
312
+ ref,
313
+ className,
314
+ children,
315
+ ...props
316
+ }: SidebarProps) {
317
+ const shell = useBinding(),
318
+ desktop = useRef<HTMLDivElement>(null),
319
+ dock = useRef<HTMLDivElement>(null),
320
+ [container, setContainer] = useState<HTMLDivElement | null>(null),
321
+ collapsed = shell.collapsed && !shell.mobile
322
+ if (
323
+ label === null ||
324
+ label === undefined ||
325
+ typeof label === 'boolean' ||
326
+ (typeof label === 'string' && !label.trim()) ||
327
+ !closeLabel.trim()
328
+ )
329
+ throw new TypeError('Sidebar requires meaningful navigation and close labels.')
330
+ useLayoutEffect(() => {
331
+ const slot = desktop.current
332
+ if (!slot) return
333
+ const node = slot.ownerDocument.createElement('div')
334
+ node.setAttribute('data-rad-layout-part', '')
335
+ node.className = 'flow-root size-full min-w-0'
336
+ setContainer(node)
337
+ return () => node.remove()
338
+ }, [])
339
+ useLayoutEffect(() => {
340
+ if (!container) return
341
+ const target = shell.mobile ? dock.current : desktop.current
342
+ if (!target) return
343
+ const doc = target.ownerDocument,
344
+ view = doc.defaultView!,
345
+ active = doc.activeElement,
346
+ held =
347
+ active instanceof doc.defaultView!.HTMLElement && container.contains(active) ? active : null
348
+ if (container.parentElement === target) return
349
+ target.append(container)
350
+ if (held && shell.mobile && !shell.open)
351
+ toggleFocus(desktop.current?.closest('[data-slot~="app-shell"]') ?? null)
352
+ let frame = 0
353
+ if (held && (!shell.mobile || shell.open))
354
+ frame = view.requestAnimationFrame(() => {
355
+ if (
356
+ doc.activeElement === doc.body ||
357
+ (doc.activeElement?.closest('[data-slot~="sidebar-trigger"]') &&
358
+ desktop.current?.closest('[data-slot~="app-shell"]')?.contains(doc.activeElement)) ||
359
+ dock.current?.closest('dialog')?.contains(doc.activeElement)
360
+ )
361
+ held.focus({ preventScroll: true })
362
+ })
363
+ return () => view.cancelAnimationFrame(frame)
364
+ }, [container, shell.mobile, shell.open])
365
+ const navigation = (
366
+ <nav
367
+ {...props}
368
+ ref={ref}
369
+ role="navigation"
370
+ id={shell.sidebarId}
371
+ aria-labelledby={shell.labelId}
372
+ tabIndex={0}
373
+ data-slot={joinIds('sidebar', props['data-slot'])}
374
+ data-collapsed={collapsed || undefined}
375
+ data-state={shell.mobile ? (shell.open ? 'open' : 'closed') : collapsed ? 'closed' : 'open'}
376
+ className={cn(
377
+ 'box-border flex size-full min-h-0 min-w-0 flex-col overflow-auto gap-[var(--rad-sidebar-gap,1rem)] p-[var(--rad-sidebar-padding,0.5rem)] border-e-[length:var(--rad-sidebar-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-surface-border-style,solid)] border-[var(--rad-sidebar-border-color,var(--rad-color-border))] bg-[var(--rad-sidebar-background,var(--rad-color-surface))] text-[var(--rad-sidebar-color,var(--rad-color-foreground))]',
378
+ className
379
+ )}
380
+ >
381
+ <h2
382
+ id={shell.labelId}
383
+ data-slot="sidebar-label"
384
+ className={cn(
385
+ 'm-0 text-[length:var(--rad-sidebar-label-size,1rem)] font-semibold',
386
+ collapsed || shell.mobile ? 'sr-only' : undefined,
387
+ parts?.label?.className
388
+ )}
389
+ style={parts?.label?.style}
390
+ >
391
+ {label}
392
+ </h2>
393
+ {children}
394
+ </nav>
395
+ )
396
+ return (
397
+ <>
398
+ <div
399
+ ref={desktop}
400
+ data-slot="sidebar-slot"
401
+ data-rad-layout-slot={shell.mobile ? undefined : ''}
402
+ className="col-start-1 row-start-2 min-h-0 min-w-0 max-[40rem]:hidden"
403
+ >
404
+ {!container && (
405
+ <div
406
+ data-rad-layout-part=""
407
+ className="flow-root size-full"
408
+ >
409
+ {navigation}
410
+ </div>
411
+ )}
412
+ </div>
413
+ <DrawerContent
414
+ side="start"
415
+ motion={shell.motion}
416
+ className={cn(
417
+ 'open:w-[min(var(--rad-sidebar-width,16rem),90dvw)]',
418
+ parts?.drawer?.className
419
+ )}
420
+ style={parts?.drawer?.style}
421
+ parts={{
422
+ viewport: {
423
+ className: cn('flex flex-col gap-0 p-0', parts?.viewport?.className),
424
+ style: parts?.viewport?.style
425
+ }
426
+ }}
427
+ >
428
+ <div className="flex items-center justify-between gap-3 p-3">
429
+ <DrawerTitle className="m-0 text-base">{label}</DrawerTitle>
430
+ <DrawerClose
431
+ variant="ghost"
432
+ tone="neutral"
433
+ controlSize="small"
434
+ className={parts?.close?.className}
435
+ style={parts?.close?.style}
436
+ >
437
+ {closeLabel}
438
+ </DrawerClose>
439
+ </div>
440
+ <div
441
+ ref={dock}
442
+ className="min-h-0 flex-1"
443
+ />
444
+ </DrawerContent>
445
+ {container && createPortal(navigation, container)}
446
+ </>
447
+ )
448
+ }
449
+ /* oxlint-enable jsx-a11y/no-noninteractive-tabindex */
450
+ export type SidebarRenderProps = ButtonRenderProps
451
+ export type SidebarTriggerProps = WithoutToggle<
452
+ DistributiveOmit<
453
+ ButtonProps,
454
+ 'aria-expanded' | 'aria-controls' | 'aria-haspopup' | 'popoverTarget' | 'popoverTargetAction'
455
+ >
456
+ >
457
+ export function SidebarTrigger({
458
+ onClick,
459
+ variant = 'ghost',
460
+ tone = 'neutral',
461
+ ...props
462
+ }: SidebarTriggerProps) {
463
+ const shell = useBinding()
464
+ return (
465
+ <Button
466
+ {...props}
467
+ variant={variant}
468
+ tone={tone}
469
+ pressed={undefined}
470
+ defaultPressed={undefined}
471
+ onPressedChange={undefined}
472
+ aria-pressed={undefined}
473
+ popoverTarget={undefined}
474
+ popoverTargetAction={undefined}
475
+ aria-expanded={shell.mobile ? shell.open : !shell.collapsed}
476
+ aria-controls={shell.mobile ? shell.drawerId : shell.sidebarId}
477
+ aria-haspopup={shell.mobile ? 'dialog' : undefined}
478
+ data-slot={joinIds('sidebar-trigger', props['data-slot'])}
479
+ onClick={composeAction(onClick, () =>
480
+ shell.mobile ? shell.setOpen(!shell.open) : shell.setCollapsed(!shell.collapsed)
481
+ )}
482
+ />
483
+ )
484
+ }
485
+ export type SidebarLabelProps = Omit<ComponentProps<'span'>, 'style'> & {
486
+ style?: ThemeStyle
487
+ 'data-slot'?: string
488
+ }
489
+ export function SidebarLabel({ className, ...props }: SidebarLabelProps) {
490
+ const shell = useBinding()
491
+ return (
492
+ <span
493
+ {...props}
494
+ data-slot={joinIds('sidebar-item-label', props['data-slot'])}
495
+ className={cn(shell.collapsed && !shell.mobile ? 'sr-only' : undefined, className)}
496
+ />
497
+ )
498
+ }
499
+ export type SidebarContentProps = Omit<ComponentProps<'div'>, 'style' | 'hidden' | 'inert'> & {
500
+ style?: ThemeStyle
501
+ 'data-slot'?: string
502
+ expandedOnly?: boolean
503
+ }
504
+ export function SidebarContent({ expandedOnly = false, className, ...props }: SidebarContentProps) {
505
+ const shell = useBinding(),
506
+ hidden = expandedOnly && shell.collapsed && !shell.mobile
507
+ return (
508
+ <div
509
+ {...props}
510
+ hidden={hidden}
511
+ inert={hidden}
512
+ data-slot={joinIds('sidebar-content', props['data-slot'])}
513
+ data-expanded-only={expandedOnly || undefined}
514
+ className={cn('min-w-0 [hidden]:hidden', className)}
515
+ />
516
+ )
517
+ }
package/src/Button.tsx CHANGED
@@ -11,6 +11,7 @@ import { cn } from './cn.js'
11
11
  import { joinIds } from './internal/ids.js'
12
12
  import { composeAction } from './internal/events.js'
13
13
  import { useControllableState } from './react/useControllableState.js'
14
+ import type { StateOwner } from './react/useNativeOwner.js'
14
15
  import type { ThemeStyle } from './themes/defineTheme.js'
15
16
 
16
17
  export type { ButtonVariant } from './presentation.js'
@@ -24,10 +25,7 @@ export type ButtonRenderProps = Omit<ComponentProps<'button'>, 'style'> & {
24
25
  }
25
26
 
26
27
  type PressedOwner =
27
- | ((
28
- | { pressed: boolean; defaultPressed?: never }
29
- | { pressed?: undefined; defaultPressed?: boolean }
30
- ) & {
28
+ | (StateOwner<'pressed', boolean> & {
31
29
  onPressedChange?: (pressed: boolean) => void
32
30
  'aria-pressed'?: never
33
31
  })
@@ -1,14 +1,18 @@
1
1
  /* oxlint-disable jsx-a11y/prefer-tag-over-role -- A passive action group uses a div; fieldset would introduce form grouping. */
2
2
  import type { ComponentProps } from 'react'
3
3
  import { cn } from './cn.js'
4
+ import { joinIds } from './internal/ids.js'
5
+ import type { Orientation } from './presentation.js'
4
6
  import type { ThemeStyle } from './themes/defineTheme.js'
5
7
 
6
8
  export type ButtonGroupProps = Omit<
7
9
  ComponentProps<'div'>,
8
10
  'style' | 'role' | 'aria-orientation'
9
11
  > & {
10
- orientation?: 'horizontal' | 'vertical'
12
+ orientation?: Orientation
11
13
  style?: ThemeStyle
14
+ /** Additional composed identities; the button-group token is always retained. */
15
+ 'data-slot'?: string
12
16
  }
13
17
 
14
18
  /** Joined presentation only: each real Button keeps its native focus and activation. */
@@ -20,7 +24,7 @@ export function ButtonGroup({ orientation = 'horizontal', className, ...props }:
20
24
  {...props}
21
25
  role="group"
22
26
  aria-orientation={undefined}
23
- data-slot="button-group"
27
+ data-slot={joinIds('button-group', props['data-slot'])}
24
28
  data-orientation={orientation}
25
29
  className={cn(
26
30
  'isolate inline-flex max-w-full items-stretch align-middle [&>button]:relative [&>button]:rounded-none [&>button:focus-visible]:z-10',
@@ -11,7 +11,7 @@ import {
11
11
  type ReactNode
12
12
  } from 'react'
13
13
  import { Checkbox, type CheckboxProps } from './Checkbox.js'
14
- import { Fieldset, type FieldsetProps } from './Fieldset.js'
14
+ import { Field, type FieldProps } from './Field.js'
15
15
  import { useNativeOwner, type ValueOwner, type CheckedOwner } from './react/useNativeOwner.js'
16
16
  import { useComposedRefs } from './react/useComposedRefs.js'
17
17
  import { cn } from './cn.js'
@@ -36,16 +36,16 @@ type OptionPresentation = Omit<
36
36
  export type CheckboxGroupItem = OptionPresentation & { value: string }
37
37
  export type CheckboxGroupSelectAll = OptionPresentation
38
38
  export type CheckboxGroupProps = Omit<
39
- FieldsetProps,
40
- 'children' | 'defaultValue' | 'value' | 'parts' | 'onChange'
39
+ Extract<FieldProps, { layout: 'group' }>,
40
+ 'layout' | 'children' | 'defaultValue' | 'parts' | 'onChange' | 'role'
41
41
  > &
42
- ValueOwner<readonly string[]> & {
42
+ ValueOwner<string[]> & {
43
43
  items: readonly CheckboxGroupItem[]
44
44
  onValueChange?: (value: string[]) => void
45
45
  controlSize?: ControlSize
46
46
  /** Toggles available options; disabled selections remain unchanged. Never submitted. */
47
47
  selectAll?: CheckboxGroupSelectAll
48
- parts?: NonNullable<FieldsetProps['parts']> & { options?: PartStyle }
48
+ parts?: NonNullable<FieldProps['parts']> & { options?: PartStyle }
49
49
  }
50
50
  // Configuration objects may carry extra native props through structural typing.
51
51
  const nativeOption = {
@@ -83,9 +83,11 @@ export function CheckboxGroup({
83
83
  selectAll,
84
84
  controlSize = 'medium',
85
85
  parts,
86
+ className,
86
87
  ref,
87
88
  name,
88
89
  form,
90
+ required,
89
91
  ...props
90
92
  }: CheckboxGroupProps) {
91
93
  const controlled = useNativeOwner('CheckboxGroup', value, defaultValue)
@@ -134,7 +136,7 @@ export function CheckboxGroup({
134
136
  return () => node?.removeEventListener('change', nativeChange)
135
137
  }, [])
136
138
  const aggregate = summary(current, items)
137
- useLayoutEffect(() => {
139
+ const sync = () => {
138
140
  // Native uncontrolled checkboxes own reset and edits made before hydration.
139
141
  const next = controlled ? current : read()
140
142
  if (controlled) {
@@ -151,21 +153,18 @@ export function CheckboxGroup({
151
153
  all.current.checked = state.all
152
154
  all.current.indeterminate = state.mixed
153
155
  }
154
- })
155
- const afterReset = useEffectEvent(() => {
156
- const next = controlled ? current : read()
157
- if (!controlled) adopt(next)
158
- else
159
- for (const item of items) {
160
- const node = nodes.current.get(item.value)
161
- if (node) node.checked = current.includes(item.value)
162
- }
163
- const state = summary(next, items)
164
- if (all.current) {
165
- all.current.checked = state.all
166
- all.current.indeterminate = state.mixed
167
- }
168
- })
156
+ // Native checkboxes have no group requirement, so the first enabled option carries it.
157
+ const enabled = items
158
+ .map(item => nodes.current.get(item.value))
159
+ .filter((node): node is HTMLInputElement => !!node && !node.matches(':disabled'))
160
+ const missing = required && !enabled.some(node => node.checked)
161
+ for (const node of nodes.current.values())
162
+ node.setCustomValidity(
163
+ missing && node === enabled[0] ? 'Please select at least one option.' : ''
164
+ )
165
+ }
166
+ useLayoutEffect(sync)
167
+ const afterReset = useEffectEvent(sync)
169
168
  useEffect(() => {
170
169
  const node = root.current,
171
170
  owner = node?.form,
@@ -210,12 +209,21 @@ export function CheckboxGroup({
210
209
  }
211
210
  }
212
211
  return (
213
- <Fieldset
214
- {...props}
212
+ <Field
213
+ {...{ ...props, role: undefined }}
214
+ layout="group"
215
+ required={required}
215
216
  form={form}
216
217
  ref={hostRef}
217
218
  data-slot={joinIds('checkbox-group', props['data-slot'])}
218
- parts={fieldParts}
219
+ className={cn(
220
+ 'max-w-full [gap:var(--rad-fieldset-gap,var(--rad-spacing-group-gap,0.75rem))]',
221
+ className
222
+ )}
223
+ parts={{
224
+ ...fieldParts,
225
+ label: { ...fieldParts.label, className: cn('max-w-full', fieldParts.label?.className) }
226
+ }}
219
227
  data-control-size={controlSize}
220
228
  >
221
229
  {selectAll ? (
@@ -272,7 +280,7 @@ export function CheckboxGroup({
272
280
  />
273
281
  ))}
274
282
  </div>
275
- </Fieldset>
283
+ </Field>
276
284
  )
277
285
  }
278
286
  function Option({