@cognitap/radiant 0.0.61 → 0.0.63

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 (90) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/library/Autocomplete.d.ts +3 -2
  3. package/dist/library/Autocomplete.d.ts.map +1 -1
  4. package/dist/library/Autocomplete.js +1 -1
  5. package/dist/library/Autocomplete.js.map +1 -1
  6. package/dist/library/CodeBlock.d.ts +2 -7
  7. package/dist/library/CodeBlock.d.ts.map +1 -1
  8. package/dist/library/CodeBlock.js.map +1 -1
  9. package/dist/library/Combobox.d.ts +14 -24
  10. package/dist/library/Combobox.d.ts.map +1 -1
  11. package/dist/library/Combobox.js +15 -14
  12. package/dist/library/Combobox.js.map +1 -1
  13. package/dist/library/Command.d.ts.map +1 -1
  14. package/dist/library/Command.js +2 -2
  15. package/dist/library/Command.js.map +1 -1
  16. package/dist/library/Dialog.d.ts +2 -9
  17. package/dist/library/Dialog.d.ts.map +1 -1
  18. package/dist/library/Dialog.js.map +1 -1
  19. package/dist/library/Menu.d.ts +2 -2
  20. package/dist/library/Menu.d.ts.map +1 -1
  21. package/dist/library/Menu.js.map +1 -1
  22. package/dist/library/MultiSelect.d.ts +4 -5
  23. package/dist/library/MultiSelect.d.ts.map +1 -1
  24. package/dist/library/MultiSelect.js +2 -2
  25. package/dist/library/MultiSelect.js.map +1 -1
  26. package/dist/library/Popover.d.ts +2 -2
  27. package/dist/library/Popover.d.ts.map +1 -1
  28. package/dist/library/Popover.js.map +1 -1
  29. package/dist/library/Resizable.d.ts +56 -0
  30. package/dist/library/Resizable.d.ts.map +1 -0
  31. package/dist/library/Resizable.js +345 -0
  32. package/dist/library/Resizable.js.map +1 -0
  33. package/dist/library/Separator.d.ts +6 -1
  34. package/dist/library/Separator.d.ts.map +1 -1
  35. package/dist/library/Separator.js +11 -3
  36. package/dist/library/Separator.js.map +1 -1
  37. package/dist/library/TagsInput.d.ts +2 -2
  38. package/dist/library/TagsInput.d.ts.map +1 -1
  39. package/dist/library/TagsInput.js +1 -1
  40. package/dist/library/TagsInput.js.map +1 -1
  41. package/dist/library/Toast.d.ts +2 -2
  42. package/dist/library/Toast.d.ts.map +1 -1
  43. package/dist/library/Toast.js.map +1 -1
  44. package/dist/library/cn.d.ts.map +1 -1
  45. package/dist/library/cn.js +4 -0
  46. package/dist/library/cn.js.map +1 -1
  47. package/dist/library/index.d.ts +3 -2
  48. package/dist/library/index.d.ts.map +1 -1
  49. package/dist/library/index.js +1 -0
  50. package/dist/library/index.js.map +1 -1
  51. package/dist/library/internal/decimal.d.ts +3 -0
  52. package/dist/library/internal/decimal.d.ts.map +1 -0
  53. package/dist/library/internal/decimal.js +15 -0
  54. package/dist/library/internal/decimal.js.map +1 -0
  55. package/dist/library/internal/numberField.d.ts +1 -1
  56. package/dist/library/internal/numberField.d.ts.map +1 -1
  57. package/dist/library/internal/numberField.js +3 -13
  58. package/dist/library/internal/numberField.js.map +1 -1
  59. package/dist/library/internal/resizable.d.ts +15 -0
  60. package/dist/library/internal/resizable.d.ts.map +1 -0
  61. package/dist/library/internal/resizable.js +86 -0
  62. package/dist/library/internal/resizable.js.map +1 -0
  63. package/dist/library/internal/types.d.ts +9 -0
  64. package/dist/library/internal/types.d.ts.map +1 -1
  65. package/dist/library/styles.css +1 -1
  66. package/dist/library/themes/components.d.ts +10 -0
  67. package/dist/library/themes/components.d.ts.map +1 -1
  68. package/dist/library/themes/components.js +10 -0
  69. package/dist/library/themes/components.js.map +1 -1
  70. package/docs/architecture.md +5 -6
  71. package/package.json +1 -1
  72. package/src/Autocomplete.tsx +4 -2
  73. package/src/CodeBlock.tsx +2 -7
  74. package/src/Combobox.tsx +55 -41
  75. package/src/Command.tsx +0 -2
  76. package/src/Dialog.tsx +2 -10
  77. package/src/Menu.tsx +2 -5
  78. package/src/MultiSelect.tsx +7 -7
  79. package/src/Popover.tsx +2 -5
  80. package/src/Resizable.tsx +581 -0
  81. package/src/Separator.tsx +22 -5
  82. package/src/TagsInput.tsx +5 -5
  83. package/src/Toast.tsx +2 -5
  84. package/src/cn.ts +4 -0
  85. package/src/index.ts +17 -2
  86. package/src/internal/decimal.ts +17 -0
  87. package/src/internal/numberField.ts +4 -16
  88. package/src/internal/resizable.ts +115 -0
  89. package/src/internal/types.ts +10 -0
  90. package/src/themes/components.ts +10 -0
@@ -0,0 +1,581 @@
1
+ 'use client'
2
+
3
+ import {
4
+ createContext,
5
+ useContext,
6
+ useId,
7
+ useRef,
8
+ useState,
9
+ useLayoutEffect,
10
+ useEffect,
11
+ useCallback,
12
+ type ComponentProps
13
+ } from 'react'
14
+ import { SeparatorRoot, type SeparatorProps } from './Separator.js'
15
+ import { cn } from './cn.js'
16
+ import { joinIds } from './internal/ids.js'
17
+ import { requireAccessibleName, type AccessibleName } from './internal/accessibleName.js'
18
+ import {
19
+ checkResizableItems,
20
+ checkResizableValue,
21
+ resizableIndex,
22
+ resizableNeighbor,
23
+ resizableRanges,
24
+ resizePanel,
25
+ sameResizableValue,
26
+ type ResizableItem
27
+ } from './internal/resizable.js'
28
+ import { addDecimal } from './internal/decimal.js'
29
+ import { useControllableState } from './react/useControllableState.js'
30
+ import { useComposedRefs } from './react/useComposedRefs.js'
31
+ import type { ValueOwner } from './react/useNativeOwner.js'
32
+ import type { Orientation } from './presentation.js'
33
+ import type { ThemeStyle } from './themes/defineTheme.js'
34
+ export type { ResizableItem } from './internal/resizable.js'
35
+
36
+ type LayoutOwner = ValueOwner<number[]> & ({ value: number[] } | { defaultValue: number[] })
37
+ export type ResizableProps = Omit<
38
+ ComponentProps<'div'>,
39
+ 'value' | 'defaultValue' | 'onChange' | 'style'
40
+ > &
41
+ LayoutOwner & {
42
+ items: readonly ResizableItem[]
43
+ onValueChange?: (value: number[]) => void
44
+ orientation?: Orientation
45
+ disabled?: boolean
46
+ style?: ThemeStyle
47
+ 'data-slot'?: string
48
+ }
49
+ export type ResizablePanelState = {
50
+ id: string
51
+ size: number
52
+ min: number
53
+ max: number
54
+ collapsed: boolean
55
+ canCollapse: boolean
56
+ canExpand: boolean
57
+ }
58
+ export type ResizableState = {
59
+ value: number[]
60
+ controlled: boolean
61
+ orientation: Orientation
62
+ disabled: boolean
63
+ setValue: (value: number[]) => void
64
+ resize: (panel: string, size: number) => void
65
+ resizeBy: (panel: string, amount: number) => void
66
+ toggle: (panel: string) => void
67
+ getPanel: (panel: string) => ResizablePanelState
68
+ }
69
+ type Binding = {
70
+ state: ResizableState
71
+ items: readonly ResizableItem[]
72
+ id: string
73
+ dragging: string | null
74
+ registerPanel: (value: string, node: HTMLDivElement | null) => void
75
+ registerHandle: (value: string, node: HTMLHRElement | null) => void
76
+ focusHandle: (value: string) => void
77
+ begin: (value: string) => symbol | null
78
+ finish: (token: symbol) => void
79
+ room: () => number
80
+ direction: () => string
81
+ pointerResize: (value: string, size: number, sum: number) => void
82
+ }
83
+ const Context = createContext<Binding | null>(null)
84
+ export function useResizable(): ResizableState | null {
85
+ return useContext(Context)?.state ?? null
86
+ }
87
+ function useBinding() {
88
+ const binding = useContext(Context)
89
+ if (!binding) throw new Error('Resizable parts must render inside Resizable.')
90
+ return binding
91
+ }
92
+ export function Resizable({
93
+ items,
94
+ value,
95
+ defaultValue,
96
+ onValueChange,
97
+ orientation = 'horizontal',
98
+ disabled = false,
99
+ className,
100
+ style,
101
+ ref,
102
+ ...props
103
+ }: ResizableProps) {
104
+ checkResizableItems(items)
105
+ if (value === undefined && defaultValue === undefined)
106
+ throw new TypeError('Resizable requires value or defaultValue.')
107
+ const selection = useControllableState({
108
+ name: 'Resizable',
109
+ value,
110
+ defaultValue,
111
+ initialValue: [],
112
+ onChange: (value: number[]) => onValueChange?.([...value]),
113
+ equal: sameResizableValue
114
+ })
115
+ checkResizableValue(items, selection.value)
116
+ const id = useId(),
117
+ root = useRef<HTMLDivElement>(null),
118
+ panels = useRef(new Map<string, HTMLDivElement>()),
119
+ handles = useRef(new Map<string, HTMLHRElement>()),
120
+ history = useRef(new Map<string, number>()),
121
+ gesture = useRef<symbol | null>(null)
122
+ const [dragging, setDragging] = useState<string | null>(null)
123
+ const composed = useComposedRefs(root, ref)
124
+ const registerPanel = useCallback((value: string, node: HTMLDivElement | null) => {
125
+ if (node) panels.current.set(value, node)
126
+ else panels.current.delete(value)
127
+ }, [])
128
+ const registerHandle = useCallback((value: string, node: HTMLHRElement | null) => {
129
+ if (node) handles.current.set(value, node)
130
+ else handles.current.delete(value)
131
+ }, [])
132
+ useLayoutEffect(() => {
133
+ items.forEach((item, index) => {
134
+ if (selection.value[index]! > 0) history.current.set(item.value, selection.value[index]!)
135
+ })
136
+ const node = root.current
137
+ if (!node) return
138
+ const sequence = Array.from(node.children).filter(child =>
139
+ child.matches('[data-slot~="resizable-panel"],[data-slot~="resizable-handle"]')
140
+ )
141
+ if (!sequence.length) return
142
+ if (
143
+ sequence.length !== items.length * 2 - 1 ||
144
+ sequence.some(
145
+ (child, index) =>
146
+ child.getAttribute('data-panel') !== items[Math.floor(index / 2)]?.value ||
147
+ !child.matches(
148
+ index % 2 ? '[data-slot~="resizable-handle"]' : '[data-slot~="resizable-panel"]'
149
+ )
150
+ )
151
+ )
152
+ throw new Error('Render Resizable panels and handles directly in items order.')
153
+ })
154
+ const request = (update: (value: number[]) => number[]) => {
155
+ if (disabled) return
156
+ selection.request(previous => {
157
+ const next = update(previous)
158
+ checkResizableValue(items, next)
159
+ return next
160
+ })
161
+ }
162
+ const resize = (panel: string, size: number) =>
163
+ request(previous => resizePanel(items, previous, resizableIndex(items, panel), size))
164
+ const resizeBy = (panel: string, amount: number) => {
165
+ if (!Number.isFinite(amount)) throw new TypeError('Resizable increments must be finite.')
166
+ request(previous => {
167
+ const index = resizableIndex(items, panel)
168
+ return resizePanel(items, previous, index, addDecimal(previous[index]!, amount))
169
+ })
170
+ }
171
+ const toggle = (panel: string) =>
172
+ request(previous => {
173
+ const index = resizableIndex(items, panel)
174
+ if (!items[index]!.collapsible) return previous
175
+ const size = previous[index]!
176
+ if (size > 0) {
177
+ if (!resizableRanges(items, previous, index).some(range => range[0] === 0)) return previous
178
+ history.current.set(panel, size)
179
+ return resizePanel(items, previous, index, 0)
180
+ }
181
+ const neighbor = resizableNeighbor(items, index)
182
+ return resizePanel(
183
+ items,
184
+ previous,
185
+ index,
186
+ history.current.get(panel) ?? addDecimal(previous[index]!, previous[neighbor]!) / 2
187
+ )
188
+ })
189
+ const getPanel = (panel: string): ResizablePanelState => {
190
+ const index = resizableIndex(items, panel),
191
+ ranges = resizableRanges(items, selection.value, index),
192
+ size = selection.value[index]!,
193
+ min = ranges[0]?.[0] ?? size,
194
+ max = ranges.at(-1)?.[1] ?? size
195
+ return {
196
+ id: id + '-panel-' + encodeURIComponent(panel),
197
+ size,
198
+ min,
199
+ max,
200
+ collapsed: size === 0,
201
+ canCollapse: !!items[index]!.collapsible && min === 0 && size > 0,
202
+ canExpand: !!items[index]!.collapsible && max > 0 && size === 0
203
+ }
204
+ }
205
+ const state: ResizableState = {
206
+ value: selection.value,
207
+ controlled: selection.controlled,
208
+ orientation,
209
+ disabled,
210
+ setValue: value => request(() => [...value]),
211
+ resize,
212
+ resizeBy,
213
+ toggle,
214
+ getPanel
215
+ }
216
+ const beginGesture = useCallback(
217
+ (panel: string) => {
218
+ if (disabled || gesture.current) return null
219
+ const token = Symbol()
220
+ gesture.current = token
221
+ setDragging(panel)
222
+ return token
223
+ },
224
+ [disabled]
225
+ )
226
+ const finishGesture = useCallback((token: symbol) => {
227
+ if (gesture.current !== token) return
228
+ gesture.current = null
229
+ setDragging(null)
230
+ }, [])
231
+ const binding: Binding = {
232
+ state,
233
+ items,
234
+ id,
235
+ dragging,
236
+ registerPanel,
237
+ registerHandle,
238
+ focusHandle(panel) {
239
+ const index = resizableIndex(items, panel)
240
+ handles.current
241
+ .get(items[Math.min(index, items.length - 2)]!.value)
242
+ ?.focus({ preventScroll: true })
243
+ },
244
+ begin: beginGesture,
245
+ finish: finishGesture,
246
+ direction() {
247
+ const node = root.current
248
+ return node?.ownerDocument.defaultView?.getComputedStyle(node).direction ?? 'ltr'
249
+ },
250
+ room() {
251
+ let room = 0
252
+ for (const panel of panels.current.values()) {
253
+ const rect = panel.getBoundingClientRect(),
254
+ view = panel.ownerDocument.defaultView
255
+ if (!view) continue
256
+ const css = view.getComputedStyle(panel),
257
+ horizontal = orientation === 'horizontal',
258
+ length = horizontal ? rect.width : rect.height,
259
+ outer = horizontal ? panel.offsetWidth : panel.offsetHeight
260
+ const scale = outer ? length / outer : 1
261
+ const edges =
262
+ (horizontal
263
+ ? [css.paddingLeft, css.paddingRight, css.borderLeftWidth, css.borderRightWidth]
264
+ : [css.paddingTop, css.paddingBottom, css.borderTopWidth, css.borderBottomWidth]
265
+ ).reduce((sum, edge) => sum + (parseFloat(edge) || 0), 0) * scale
266
+ room += Math.max(0, length - edges)
267
+ }
268
+ return room
269
+ },
270
+ pointerResize(panel, size, sum) {
271
+ request(previous => {
272
+ const index = resizableIndex(items, panel),
273
+ neighbor = resizableNeighbor(items, index)
274
+ return Math.abs(addDecimal(previous[index]!, previous[neighbor]!) - sum) > 1e-7
275
+ ? previous
276
+ : resizePanel(items, previous, index, size, false)
277
+ })
278
+ }
279
+ }
280
+ return (
281
+ <Context.Provider value={binding}>
282
+ <div
283
+ {...props}
284
+ ref={composed}
285
+ data-slot={joinIds('resizable', props['data-slot'])}
286
+ data-orientation={orientation}
287
+ data-disabled={disabled ? '' : undefined}
288
+ data-dragging={dragging ? '' : undefined}
289
+ className={cn(
290
+ 'flex min-h-0 min-w-0 data-[orientation=horizontal]:flex-row data-[orientation=vertical]:flex-col data-dragging:select-none',
291
+ className
292
+ )}
293
+ style={style}
294
+ />
295
+ </Context.Provider>
296
+ )
297
+ }
298
+ export type ResizablePanelProps = Omit<
299
+ ComponentProps<'div'>,
300
+ 'id' | 'hidden' | 'inert' | 'style'
301
+ > & { value: string; style?: ThemeStyle; 'data-slot'?: string }
302
+ export function ResizablePanel({
303
+ value,
304
+ ref,
305
+ className,
306
+ style,
307
+ onFocusCapture,
308
+ onBlurCapture,
309
+ ...props
310
+ }: ResizablePanelProps) {
311
+ const context = useBinding(),
312
+ index = resizableIndex(context.items, value),
313
+ size = context.state.value[index]!,
314
+ collapsed = size === 0
315
+ const node = useRef<HTMLDivElement>(null),
316
+ hadFocus = useRef(false)
317
+ const registerPanel = context.registerPanel
318
+ const register = useCallback(
319
+ (element: HTMLDivElement | null) => {
320
+ node.current = element
321
+ registerPanel(value, element)
322
+ },
323
+ [registerPanel, value]
324
+ )
325
+ const composed = useComposedRefs(register, ref)
326
+ useLayoutEffect(() => {
327
+ const panel = node.current
328
+ if (!collapsed || !panel) return
329
+ const active = panel.ownerDocument.activeElement
330
+ if (hadFocus.current && (panel.contains(active) || active === panel.ownerDocument.body))
331
+ context.focusHandle(value)
332
+ hadFocus.current = false
333
+ })
334
+ const panelStyle: ThemeStyle = { '--_rad-resizable-size': size, ...style }
335
+ return (
336
+ <div
337
+ {...props}
338
+ ref={composed}
339
+ id={context.id + '-panel-' + encodeURIComponent(value)}
340
+ hidden={collapsed}
341
+ inert={collapsed || undefined}
342
+ data-slot={joinIds('resizable-panel', props['data-slot'])}
343
+ data-panel={value}
344
+ data-size={size}
345
+ data-collapsed={collapsed ? '' : undefined}
346
+ className={cn(
347
+ 'box-border min-h-0 min-w-0 basis-0 shrink grow-(--_rad-resizable-size) overflow-hidden',
348
+ className
349
+ )}
350
+ style={panelStyle}
351
+ onFocusCapture={event => {
352
+ onFocusCapture?.(event)
353
+ hadFocus.current = true
354
+ }}
355
+ onBlurCapture={event => {
356
+ onBlurCapture?.(event)
357
+ if (
358
+ !event.currentTarget.contains(event.relatedTarget) &&
359
+ (!collapsed || event.relatedTarget !== null)
360
+ )
361
+ hadFocus.current = false
362
+ }}
363
+ />
364
+ )
365
+ }
366
+ export type ResizableHandleProps = Omit<
367
+ SeparatorProps,
368
+ | 'orientation'
369
+ | 'decorative'
370
+ | 'aria-controls'
371
+ | 'aria-disabled'
372
+ | 'aria-valuenow'
373
+ | 'aria-valuemin'
374
+ | 'aria-valuemax'
375
+ | 'aria-valuetext'
376
+ > &
377
+ AccessibleName & {
378
+ value: string
379
+ step?: number
380
+ largeStep?: number
381
+ }
382
+ type Drag = {
383
+ node: HTMLHRElement
384
+ pointer: number
385
+ token: symbol
386
+ start: number
387
+ size: number
388
+ room: number
389
+ sum: number
390
+ orientation: Orientation
391
+ direction: string
392
+ cleanup: () => void
393
+ }
394
+ export function ResizableHandle({
395
+ value,
396
+ step = 1,
397
+ largeStep = step * 10,
398
+ className,
399
+ ref,
400
+ onKeyDown,
401
+ onPointerDown,
402
+ onPointerMove,
403
+ onPointerUp,
404
+ onPointerCancel,
405
+ onLostPointerCapture,
406
+ onBlur,
407
+ ...props
408
+ }: ResizableHandleProps) {
409
+ const context = useBinding(),
410
+ index = resizableIndex(context.items, value)
411
+ if (index === context.items.length - 1)
412
+ throw new TypeError('Resizable handles follow every panel except the last.')
413
+ requireAccessibleName('ResizableHandle', props)
414
+ if (!Number.isFinite(step) || step <= 0 || !Number.isFinite(largeStep) || largeStep <= 0)
415
+ throw new TypeError('Resizable handle steps must be finite and positive.')
416
+ const ranges = resizableRanges(context.items, context.state.value, index),
417
+ min = ranges[0]?.[0] ?? context.state.value[index]!,
418
+ max = ranges.at(-1)?.[1] ?? min
419
+ const disabled = context.state.disabled || min === max,
420
+ drag = useRef<Drag | null>(null)
421
+ const registerHandle = context.registerHandle,
422
+ finishGesture = context.finish
423
+ const register = useCallback(
424
+ (node: HTMLHRElement | null) => registerHandle(value, node),
425
+ [registerHandle, value]
426
+ )
427
+ const composed = useComposedRefs(register, ref)
428
+ const finish = useCallback(() => {
429
+ const current = drag.current
430
+ if (!current) return
431
+ drag.current = null
432
+ current.cleanup()
433
+ try {
434
+ if (current.node.hasPointerCapture(current.pointer))
435
+ current.node.releasePointerCapture(current.pointer)
436
+ } catch {}
437
+ finishGesture(current.token)
438
+ }, [finishGesture])
439
+ useEffect(() => () => finish(), [finish])
440
+ useLayoutEffect(() => {
441
+ if (disabled || (drag.current && drag.current.orientation !== context.state.orientation))
442
+ finish()
443
+ })
444
+ return (
445
+ <SeparatorRoot
446
+ {...props}
447
+ interactive
448
+ tabIndex={disabled ? -1 : 0}
449
+ decorative={false}
450
+ ref={composed}
451
+ orientation={context.state.orientation === 'horizontal' ? 'vertical' : 'horizontal'}
452
+ aria-controls={context.id + '-panel-' + encodeURIComponent(value)}
453
+ aria-disabled={disabled || undefined}
454
+ aria-valuenow={context.state.value[index]}
455
+ aria-valuemin={min}
456
+ aria-valuemax={max}
457
+ aria-valuetext={Number(context.state.value[index]!.toFixed(4)) + '%'}
458
+ data-slot={joinIds('resizable-handle', props['data-slot'])}
459
+ data-panel={value}
460
+ data-dragging={context.dragging === value ? '' : undefined}
461
+ className={cn(
462
+ 'touch-none select-none m-0 bg-[var(--rad-resizable-handle-background,transparent)] [border-color:var(--rad-resizable-handle-color,var(--rad-color-border,oklch(0.885_0.005_286)))]',
463
+ 'hover:bg-[var(--rad-resizable-handle-hover-background,var(--rad-color-neutral,oklch(0.955_0.004_286)))] data-dragging:bg-[var(--rad-resizable-handle-active-background,var(--rad-color-neutral,oklch(0.955_0.004_286)))]',
464
+ 'focus-visible:outline-solid focus-visible:outline-[color:var(--rad-resizable-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))] focus-visible:outline-[length:var(--rad-resizable-focus-width,var(--rad-focus-width,2px))] focus-visible:outline-offset-[var(--rad-resizable-focus-offset,-2px)]',
465
+ 'aria-disabled:cursor-not-allowed aria-disabled:bg-[var(--rad-resizable-handle-background,transparent)] forced-colors:border-[CanvasText] forced-colors:focus-visible:outline-[Highlight]',
466
+ context.state.orientation === 'horizontal'
467
+ ? 'h-auto w-[length:var(--rad-resizable-handle-size,0.5rem)] cursor-col-resize'
468
+ : 'w-auto h-[length:var(--rad-resizable-handle-size,0.5rem)] cursor-row-resize',
469
+ className
470
+ )}
471
+ onKeyDown={event => {
472
+ onKeyDown?.(event)
473
+ if (event.defaultPrevented || disabled || event.altKey || event.ctrlKey || event.metaKey)
474
+ return
475
+ if (event.key === 'Enter') {
476
+ event.preventDefault()
477
+ context.state.toggle(value)
478
+ return
479
+ }
480
+ if (event.key === 'Home' || event.key === 'End') {
481
+ event.preventDefault()
482
+ context.state.resize(value, event.key === 'Home' ? min : max)
483
+ return
484
+ }
485
+ const horizontal = context.state.orientation === 'horizontal',
486
+ direction = context.direction(),
487
+ amount = event.shiftKey ? largeStep : step
488
+ const sign = horizontal
489
+ ? event.key === 'ArrowRight'
490
+ ? 1
491
+ : event.key === 'ArrowLeft'
492
+ ? -1
493
+ : 0
494
+ : event.key === 'ArrowDown'
495
+ ? 1
496
+ : event.key === 'ArrowUp'
497
+ ? -1
498
+ : 0
499
+ if (!sign) return
500
+ event.preventDefault()
501
+ context.state.resizeBy(value, sign * amount * (horizontal && direction === 'rtl' ? -1 : 1))
502
+ }}
503
+ onPointerDown={event => {
504
+ onPointerDown?.(event)
505
+ if (event.defaultPrevented || disabled || event.button !== 0 || !event.isPrimary) return
506
+ const room = context.room(),
507
+ token = room > 0 ? context.begin(value) : null
508
+ if (!token) return
509
+ event.preventDefault()
510
+ event.currentTarget.focus({ preventScroll: true })
511
+ try {
512
+ event.currentTarget.setPointerCapture(event.pointerId)
513
+ } catch {
514
+ context.finish(token)
515
+ return
516
+ }
517
+ const view = event.currentTarget.ownerDocument.defaultView
518
+ view?.addEventListener('blur', finish)
519
+ drag.current = {
520
+ node: event.currentTarget,
521
+ pointer: event.pointerId,
522
+ token,
523
+ start: context.state.orientation === 'horizontal' ? event.clientX : event.clientY,
524
+ size: context.state.value[index]!,
525
+ room,
526
+ sum: addDecimal(context.state.value[index]!, context.state.value[index + 1]!),
527
+ orientation: context.state.orientation,
528
+ direction: context.direction(),
529
+ cleanup: () => view?.removeEventListener('blur', finish)
530
+ }
531
+ }}
532
+ onPointerMove={event => {
533
+ onPointerMove?.(event)
534
+ const current = drag.current
535
+ if (!current || current.pointer !== event.pointerId) return
536
+ const room = context.room(),
537
+ coordinate = current.orientation === 'horizontal' ? event.clientX : event.clientY
538
+ if (
539
+ disabled ||
540
+ !event.currentTarget.isConnected ||
541
+ context.direction() !== current.direction ||
542
+ Math.abs(
543
+ addDecimal(context.state.value[index]!, context.state.value[index + 1]!) - current.sum
544
+ ) > 1e-7
545
+ ) {
546
+ finish()
547
+ return
548
+ }
549
+ if (event.defaultPrevented) return
550
+ if (Math.abs(room - current.room) > 0.5) {
551
+ current.start = coordinate
552
+ current.size = context.state.value[index]!
553
+ current.room = room
554
+ return
555
+ }
556
+ if (room <= 0) return
557
+ const delta =
558
+ ((coordinate - current.start) / room) *
559
+ 100 *
560
+ (current.orientation === 'horizontal' && current.direction === 'rtl' ? -1 : 1)
561
+ context.pointerResize(value, addDecimal(current.size, delta), current.sum)
562
+ }}
563
+ onPointerUp={event => {
564
+ onPointerUp?.(event)
565
+ if (drag.current?.pointer === event.pointerId) finish()
566
+ }}
567
+ onPointerCancel={event => {
568
+ onPointerCancel?.(event)
569
+ if (drag.current?.pointer === event.pointerId) finish()
570
+ }}
571
+ onLostPointerCapture={event => {
572
+ onLostPointerCapture?.(event)
573
+ if (drag.current?.pointer === event.pointerId) finish()
574
+ }}
575
+ onBlur={event => {
576
+ onBlur?.(event)
577
+ finish()
578
+ }}
579
+ />
580
+ )
581
+ }
package/src/Separator.tsx CHANGED
@@ -21,23 +21,40 @@ export type SeparatorProps = Omit<
21
21
  'data-slot'?: string
22
22
  }
23
23
 
24
- export function Separator({
24
+ export function Separator(props: SeparatorProps) {
25
+ return (
26
+ <SeparatorRoot
27
+ {...props}
28
+ interactive={undefined}
29
+ tabIndex={undefined}
30
+ />
31
+ )
32
+ }
33
+
34
+ /** Private native seam for an interactive separator; the public rule stays passive. */
35
+ export function SeparatorRoot({
36
+ interactive,
37
+ tabIndex,
25
38
  decorative = false,
26
39
  orientation = 'horizontal',
27
40
  className,
28
41
  ...props
29
- }: SeparatorProps) {
42
+ }: SeparatorProps & { interactive?: boolean; tabIndex?: number }) {
30
43
  const {
31
44
  children: _children,
32
45
  dangerouslySetInnerHTML: _html,
33
46
  ...attributes
34
47
  }: ComponentProps<'hr'> = props
35
- const nativeProps = { ...attributes, role: undefined, tabIndex: undefined }
48
+ const nativeProps = {
49
+ ...attributes,
50
+ role: interactive ? 'separator' : undefined,
51
+ tabIndex: interactive ? (tabIndex ?? 0) : undefined
52
+ }
36
53
  return (
37
54
  <hr
38
55
  {...nativeProps}
39
- aria-hidden={decorative ? true : undefined}
40
- aria-orientation={decorative ? undefined : orientation}
56
+ aria-hidden={!interactive && decorative ? true : undefined}
57
+ aria-orientation={!interactive && decorative ? undefined : orientation}
41
58
  data-slot={joinIds('separator', props['data-slot'])}
42
59
  data-orientation={orientation}
43
60
  data-decorative={decorative ? '' : undefined}
package/src/TagsInput.tsx CHANGED
@@ -20,13 +20,13 @@ export type TagsInputProps = DistributiveOmit<
20
20
  'value' | 'defaultValue' | 'type' | 'children'
21
21
  > &
22
22
  ValueOwner<string[]> & {
23
- onValueChange?: (values: string[]) => void
23
+ onValueChange?: (value: string[]) => void
24
24
  /** Single-character separators; line breaks in pasted text also separate tags. */
25
25
  separators?: readonly string[]
26
26
  /** True accepts; false or an error message rejects. Values are trimmed before validation. */
27
27
  validate?: (value: string) => boolean | string
28
28
  maxCount?: number
29
- parts?: { wrapper?: PartStyle; tag?: PartStyle; remove?: PartStyle; message?: PartStyle }
29
+ parts?: { wrapper?: PartStyle; tag?: PartStyle; remove?: PartStyle; error?: PartStyle }
30
30
  }
31
31
  const defaultSeparators = [','] as const
32
32
 
@@ -257,14 +257,14 @@ export function TagsInput({
257
257
  />
258
258
  <span
259
259
  id={message}
260
- data-slot="tags-input-message"
260
+ data-slot="tags-input-error"
261
261
  aria-live="polite"
262
262
  aria-atomic="true"
263
263
  className={cn(
264
264
  'w-full empty:hidden text-[length:var(--rad-typography-roles-ui-supporting-size,0.8125rem)] [color:var(--rad-color-invalid,oklch(0.56_0.19_25))]',
265
- parts?.message?.className
265
+ parts?.error?.className
266
266
  )}
267
- style={parts?.message?.style}
267
+ style={parts?.error?.style}
268
268
  >
269
269
  {feedback}
270
270
  </span>
package/src/Toast.tsx CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  import { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'
24
24
  import { cn } from './cn.js'
25
25
  import { joinIds } from './internal/ids.js'
26
- import type { DistributiveOmit } from './internal/types.js'
26
+ import type { WithoutToggle } from './internal/types.js'
27
27
  import { composeAction } from './internal/events.js'
28
28
  import { validateToastDuration } from './internal/toast.js'
29
29
  import { useControllableState } from './react/useControllableState.js'
@@ -49,10 +49,7 @@ export type ToastProps = Omit<
49
49
  export type ToastState = { open: boolean; visible: boolean; setOpen: (open: boolean) => void }
50
50
  export type ToastTitleProps = AlertTitleProps
51
51
  export type ToastDescriptionProps = AlertDescriptionProps
52
- type ToastButtonProps = DistributiveOmit<
53
- ButtonProps,
54
- 'pressed' | 'defaultPressed' | 'onPressedChange' | 'aria-pressed'
55
- >
52
+ type ToastButtonProps = WithoutToggle<ButtonProps>
56
53
  export type ToastActionProps = ToastButtonProps & { altText: string }
57
54
  export type ToastCloseProps = ToastButtonProps
58
55
  const notToggle = {