@cognitap/radiant 0.0.31 → 0.0.33
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 +17 -8
- package/dist/library/Button.d.ts +17 -2
- package/dist/library/Button.d.ts.map +1 -1
- package/dist/library/Button.js +15 -3
- package/dist/library/Button.js.map +1 -1
- package/dist/library/Combobox.d.ts +2 -1
- package/dist/library/Combobox.d.ts.map +1 -1
- package/dist/library/Combobox.js.map +1 -1
- package/dist/library/Menu.d.ts +3 -2
- package/dist/library/Menu.d.ts.map +1 -1
- package/dist/library/Menu.js.map +1 -1
- package/dist/library/Pagination.d.ts +2 -1
- package/dist/library/Pagination.d.ts.map +1 -1
- package/dist/library/Pagination.js.map +1 -1
- package/dist/library/ScrollArea.d.ts +27 -0
- package/dist/library/ScrollArea.d.ts.map +1 -0
- package/dist/library/ScrollArea.js +278 -0
- package/dist/library/ScrollArea.js.map +1 -0
- package/dist/library/Select.d.ts +2 -1
- package/dist/library/Select.d.ts.map +1 -1
- package/dist/library/Select.js.map +1 -1
- package/dist/library/Tabs.d.ts +1 -1
- package/dist/library/Tabs.d.ts.map +1 -1
- package/dist/library/Tabs.js +1 -1
- package/dist/library/Tabs.js.map +1 -1
- package/dist/library/ToggleGroup.d.ts +67 -0
- package/dist/library/ToggleGroup.d.ts.map +1 -0
- package/dist/library/ToggleGroup.js +165 -0
- package/dist/library/ToggleGroup.js.map +1 -0
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +8 -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/types.d.ts +3 -0
- package/dist/library/internal/types.d.ts.map +1 -0
- package/dist/library/internal/types.js +2 -0
- package/dist/library/internal/types.js.map +1 -0
- package/dist/library/motion/host.d.ts +2 -1
- package/dist/library/motion/host.d.ts.map +1 -1
- package/dist/library/motion/host.js.map +1 -1
- package/dist/library/motion/indicator.d.ts +5 -0
- package/dist/library/motion/indicator.d.ts.map +1 -0
- package/dist/library/motion/indicator.js +73 -0
- package/dist/library/motion/indicator.js.map +1 -0
- package/dist/library/motion/react.d.ts.map +1 -1
- package/dist/library/motion/react.js +3 -1
- package/dist/library/motion/react.js.map +1 -1
- package/dist/library/react/useRovingFocus.d.ts +20 -0
- package/dist/library/react/useRovingFocus.d.ts.map +1 -0
- package/dist/library/react/useRovingFocus.js +109 -0
- package/dist/library/react/useRovingFocus.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +15 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +10 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +24 -18
- package/package.json +1 -1
- package/src/Button.tsx +53 -21
- package/src/Combobox.tsx +2 -1
- package/src/Menu.tsx +3 -2
- package/src/Pagination.tsx +2 -1
- package/src/ScrollArea.tsx +500 -0
- package/src/Select.tsx +2 -1
- package/src/Tabs.tsx +6 -0
- package/src/ToggleGroup.tsx +363 -0
- package/src/cn.ts +8 -0
- package/src/index.ts +13 -0
- package/src/internal/types.ts +4 -0
- package/src/motion/host.ts +2 -1
- package/src/motion/indicator.ts +77 -0
- package/src/motion/react.ts +3 -1
- package/src/react/useRovingFocus.ts +147 -0
- package/src/themes/components.ts +10 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/* oxlint-disable jsx-a11y/prefer-tag-over-role -- A scrolling ARIA group preserves menu/listbox child semantics; a fieldset would add unrelated form behavior. */
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useId,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
type ComponentProps,
|
|
13
|
+
type PointerEvent
|
|
14
|
+
} from 'react'
|
|
15
|
+
import { cn } from './cn.js'
|
|
16
|
+
import { joinIds } from './internal/ids.js'
|
|
17
|
+
import { useComposedRefs } from './react/useComposedRefs.js'
|
|
18
|
+
import type { PartStyle } from './presentation.js'
|
|
19
|
+
import type { ThemeStyle } from './themes/defineTheme.js'
|
|
20
|
+
|
|
21
|
+
export type ScrollAreaOrientation = 'vertical' | 'horizontal' | 'both'
|
|
22
|
+
export type ScrollAreaVisibility = 'hover' | 'scroll' | 'always'
|
|
23
|
+
type Name =
|
|
24
|
+
| { 'aria-label': string; 'aria-labelledby'?: string }
|
|
25
|
+
| { 'aria-label'?: string; 'aria-labelledby': string }
|
|
26
|
+
export type ScrollAreaProps = Omit<
|
|
27
|
+
ComponentProps<'div'>,
|
|
28
|
+
'style' | 'role' | 'contentEditable' | 'dangerouslySetInnerHTML'
|
|
29
|
+
> &
|
|
30
|
+
Name & {
|
|
31
|
+
orientation?: ScrollAreaOrientation
|
|
32
|
+
visibility?: ScrollAreaVisibility
|
|
33
|
+
style?: ThemeStyle
|
|
34
|
+
parts?: { content?: PartStyle; scrollbar?: PartStyle; thumb?: PartStyle }
|
|
35
|
+
'data-slot'?: string
|
|
36
|
+
}
|
|
37
|
+
type Axis = 'vertical' | 'horizontal'
|
|
38
|
+
type Metrics = {
|
|
39
|
+
width: number
|
|
40
|
+
height: number
|
|
41
|
+
scrollWidth: number
|
|
42
|
+
scrollHeight: number
|
|
43
|
+
innerWidth: number
|
|
44
|
+
innerHeight: number
|
|
45
|
+
rtl: boolean
|
|
46
|
+
orientation: ScrollAreaOrientation
|
|
47
|
+
}
|
|
48
|
+
type Gesture = {
|
|
49
|
+
pointerId: number
|
|
50
|
+
axis: Axis
|
|
51
|
+
start: number
|
|
52
|
+
offset: number
|
|
53
|
+
travel: number
|
|
54
|
+
max: number
|
|
55
|
+
}
|
|
56
|
+
const hitSize = 24
|
|
57
|
+
const clamp = (value: number) => Math.min(1, Math.max(0, value))
|
|
58
|
+
function tracks(metrics: Metrics) {
|
|
59
|
+
const vertical = metrics.orientation !== 'horizontal' && metrics.scrollHeight > metrics.height + 1
|
|
60
|
+
const horizontal = metrics.orientation !== 'vertical' && metrics.scrollWidth > metrics.width + 1
|
|
61
|
+
const height = Math.max(0, metrics.innerHeight - (horizontal ? hitSize : 0))
|
|
62
|
+
const width = Math.max(0, metrics.innerWidth - (vertical ? hitSize : 0))
|
|
63
|
+
return {
|
|
64
|
+
vertical,
|
|
65
|
+
horizontal,
|
|
66
|
+
height,
|
|
67
|
+
width,
|
|
68
|
+
thumbHeight:
|
|
69
|
+
metrics.scrollHeight > 0
|
|
70
|
+
? Math.min(height, Math.max(hitSize, (height * metrics.height) / metrics.scrollHeight))
|
|
71
|
+
: 0,
|
|
72
|
+
thumbWidth:
|
|
73
|
+
metrics.scrollWidth > 0
|
|
74
|
+
? Math.min(width, Math.max(hitSize, (width * metrics.width) / metrics.scrollWidth))
|
|
75
|
+
: 0
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function same(a: Metrics | null, b: Metrics) {
|
|
79
|
+
return a !== null && Object.entries(b).every(([key, value]) => a[key as keyof Metrics] === value)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The ref and native props reach the browser-owned scroll viewport. */
|
|
83
|
+
export function ScrollArea({
|
|
84
|
+
orientation = 'vertical',
|
|
85
|
+
visibility = 'hover',
|
|
86
|
+
parts,
|
|
87
|
+
children,
|
|
88
|
+
className,
|
|
89
|
+
style,
|
|
90
|
+
ref,
|
|
91
|
+
tabIndex = 0,
|
|
92
|
+
onScroll,
|
|
93
|
+
onPointerDown,
|
|
94
|
+
onPointerMove,
|
|
95
|
+
onPointerUp,
|
|
96
|
+
onPointerCancel,
|
|
97
|
+
onLostPointerCapture,
|
|
98
|
+
onPointerEnter,
|
|
99
|
+
onPointerLeave,
|
|
100
|
+
onFocus,
|
|
101
|
+
onBlur,
|
|
102
|
+
...props
|
|
103
|
+
}: ScrollAreaProps) {
|
|
104
|
+
if (!props['aria-label']?.trim() && !props['aria-labelledby']?.trim())
|
|
105
|
+
throw new TypeError('ScrollArea requires aria-label or aria-labelledby.')
|
|
106
|
+
const owner = useId(),
|
|
107
|
+
root = useRef<HTMLDivElement>(null),
|
|
108
|
+
content = useRef<HTMLDivElement>(null)
|
|
109
|
+
const hostRef = useComposedRefs(root, ref)
|
|
110
|
+
const [metrics, setMetrics] = useState<Metrics | null>(null)
|
|
111
|
+
const measured = useRef<Metrics | null>(null),
|
|
112
|
+
gesture = useRef<Gesture | null>(null)
|
|
113
|
+
const [dragging, setDragging] = useState<Axis | null>(null)
|
|
114
|
+
const [hovered, setHovered] = useState(false),
|
|
115
|
+
[focused, setFocused] = useState(false)
|
|
116
|
+
const [scrolling, setScrolling] = useState(false),
|
|
117
|
+
hideTimer = useRef<number | undefined>(undefined)
|
|
118
|
+
const finish = useCallback((node = root.current, notify = true) => {
|
|
119
|
+
const active = gesture.current
|
|
120
|
+
if (!active) return
|
|
121
|
+
gesture.current = null
|
|
122
|
+
if (node?.hasPointerCapture(active.pointerId)) node.releasePointerCapture(active.pointerId)
|
|
123
|
+
if (notify) setDragging(null)
|
|
124
|
+
}, [])
|
|
125
|
+
const position = useCallback((next = measured.current) => {
|
|
126
|
+
const node = root.current
|
|
127
|
+
if (!node || !next) return
|
|
128
|
+
const track = tracks(next)
|
|
129
|
+
const maxX = Math.max(0, next.scrollWidth - next.width),
|
|
130
|
+
maxY = Math.max(0, next.scrollHeight - next.height)
|
|
131
|
+
const x = maxX > 0 ? clamp((next.rtl ? maxX + node.scrollLeft : node.scrollLeft) / maxX) : 0
|
|
132
|
+
const y = maxY > 0 ? clamp(node.scrollTop / maxY) : 0
|
|
133
|
+
node.style.setProperty(
|
|
134
|
+
'--_rad-scroll-area-thumb-x',
|
|
135
|
+
`${x * (track.width - track.thumbWidth)}px`
|
|
136
|
+
)
|
|
137
|
+
node.style.setProperty(
|
|
138
|
+
'--_rad-scroll-area-thumb-y',
|
|
139
|
+
`${y * (track.height - track.thumbHeight)}px`
|
|
140
|
+
)
|
|
141
|
+
}, [])
|
|
142
|
+
const measure = useCallback(() => {
|
|
143
|
+
const node = root.current,
|
|
144
|
+
win = node?.ownerDocument.defaultView
|
|
145
|
+
if (!node || !win) return
|
|
146
|
+
const css = win.getComputedStyle(node)
|
|
147
|
+
const next: Metrics = {
|
|
148
|
+
width: node.clientWidth,
|
|
149
|
+
height: node.clientHeight,
|
|
150
|
+
scrollWidth: node.scrollWidth,
|
|
151
|
+
scrollHeight: node.scrollHeight,
|
|
152
|
+
innerWidth: Math.max(
|
|
153
|
+
0,
|
|
154
|
+
node.clientWidth - parseFloat(css.paddingLeft) - parseFloat(css.paddingRight)
|
|
155
|
+
),
|
|
156
|
+
innerHeight: Math.max(
|
|
157
|
+
0,
|
|
158
|
+
node.clientHeight - parseFloat(css.paddingTop) - parseFloat(css.paddingBottom)
|
|
159
|
+
),
|
|
160
|
+
rtl: css.direction === 'rtl',
|
|
161
|
+
orientation
|
|
162
|
+
}
|
|
163
|
+
if (!same(measured.current, next)) finish(node)
|
|
164
|
+
measured.current = next
|
|
165
|
+
position(next)
|
|
166
|
+
setMetrics(previous => (same(previous, next) ? previous : next))
|
|
167
|
+
}, [orientation, finish, position])
|
|
168
|
+
useLayoutEffect(() => {
|
|
169
|
+
// oxlint-disable-next-line react/set-state-in-effect -- Read external native viewport geometry, including edits before hydration.
|
|
170
|
+
measure()
|
|
171
|
+
})
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
const node = root.current,
|
|
174
|
+
body = content.current,
|
|
175
|
+
win = node?.ownerDocument.defaultView
|
|
176
|
+
if (!node || !body || !win) return
|
|
177
|
+
let frame: number | undefined
|
|
178
|
+
const schedule = () => {
|
|
179
|
+
if (frame !== undefined) return
|
|
180
|
+
frame = win.requestAnimationFrame(() => {
|
|
181
|
+
frame = undefined
|
|
182
|
+
measure()
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
const resize = new win.ResizeObserver(schedule),
|
|
186
|
+
mutation = new win.MutationObserver(schedule)
|
|
187
|
+
resize.observe(node)
|
|
188
|
+
resize.observe(body)
|
|
189
|
+
mutation.observe(body, {
|
|
190
|
+
childList: true,
|
|
191
|
+
subtree: true,
|
|
192
|
+
characterData: true,
|
|
193
|
+
attributes: true
|
|
194
|
+
})
|
|
195
|
+
body.addEventListener('load', schedule, true)
|
|
196
|
+
body.addEventListener('loadedmetadata', schedule, true)
|
|
197
|
+
node.ownerDocument.fonts?.addEventListener('loadingdone', schedule)
|
|
198
|
+
win.addEventListener('resize', schedule)
|
|
199
|
+
return () => {
|
|
200
|
+
resize.disconnect()
|
|
201
|
+
mutation.disconnect()
|
|
202
|
+
body.removeEventListener('load', schedule, true)
|
|
203
|
+
body.removeEventListener('loadedmetadata', schedule, true)
|
|
204
|
+
node.ownerDocument.fonts?.removeEventListener('loadingdone', schedule)
|
|
205
|
+
win.removeEventListener('resize', schedule)
|
|
206
|
+
if (frame !== undefined) win.cancelAnimationFrame(frame)
|
|
207
|
+
win.clearTimeout(hideTimer.current)
|
|
208
|
+
finish(node, false)
|
|
209
|
+
}
|
|
210
|
+
}, [measure, finish])
|
|
211
|
+
const moveTo = (axis: Axis, offset: number) => {
|
|
212
|
+
const node = root.current
|
|
213
|
+
if (!node) return
|
|
214
|
+
node.scrollTo(
|
|
215
|
+
axis === 'vertical'
|
|
216
|
+
? { top: offset, behavior: 'instant' }
|
|
217
|
+
: { left: offset, behavior: 'instant' }
|
|
218
|
+
)
|
|
219
|
+
position()
|
|
220
|
+
}
|
|
221
|
+
const start = (event: PointerEvent<HTMLDivElement>) => {
|
|
222
|
+
onPointerDown?.(event)
|
|
223
|
+
const node = root.current,
|
|
224
|
+
win = node?.ownerDocument.defaultView
|
|
225
|
+
if (
|
|
226
|
+
event.defaultPrevented ||
|
|
227
|
+
event.button !== 0 ||
|
|
228
|
+
!node ||
|
|
229
|
+
!win ||
|
|
230
|
+
!(event.target instanceof win.Element)
|
|
231
|
+
)
|
|
232
|
+
return
|
|
233
|
+
const bar = event.target.closest<HTMLElement>('[data-scroll-area-hit]')
|
|
234
|
+
if (!bar || bar.dataset.owner !== owner || !node.contains(bar)) return
|
|
235
|
+
const axis = bar.dataset.axis === 'horizontal' ? 'horizontal' : 'vertical'
|
|
236
|
+
const thumb = bar.querySelector<HTMLElement>('[data-scroll-area-thumb-hit]')
|
|
237
|
+
if (!thumb) return
|
|
238
|
+
measure()
|
|
239
|
+
const current = measured.current
|
|
240
|
+
if (!current) return
|
|
241
|
+
const box = bar.getBoundingClientRect(),
|
|
242
|
+
knob = thumb.getBoundingClientRect()
|
|
243
|
+
const travel = axis === 'vertical' ? box.height - knob.height : box.width - knob.width
|
|
244
|
+
const max =
|
|
245
|
+
axis === 'vertical'
|
|
246
|
+
? current.scrollHeight - current.height
|
|
247
|
+
: current.scrollWidth - current.width
|
|
248
|
+
if (travel <= 0 || max <= 0) return
|
|
249
|
+
event.preventDefault()
|
|
250
|
+
const coordinate = axis === 'vertical' ? event.clientY : event.clientX
|
|
251
|
+
if (!thumb.contains(event.target)) {
|
|
252
|
+
const progress = clamp(
|
|
253
|
+
(coordinate -
|
|
254
|
+
(axis === 'vertical' ? box.top + knob.height / 2 : box.left + knob.width / 2)) /
|
|
255
|
+
travel
|
|
256
|
+
)
|
|
257
|
+
moveTo(axis, axis === 'horizontal' && current.rtl ? (progress - 1) * max : progress * max)
|
|
258
|
+
}
|
|
259
|
+
gesture.current = {
|
|
260
|
+
pointerId: event.pointerId,
|
|
261
|
+
axis,
|
|
262
|
+
start: coordinate,
|
|
263
|
+
offset: axis === 'vertical' ? node.scrollTop : node.scrollLeft,
|
|
264
|
+
travel,
|
|
265
|
+
max
|
|
266
|
+
}
|
|
267
|
+
if (node.tabIndex >= 0) node.focus({ preventScroll: true })
|
|
268
|
+
node.setPointerCapture(event.pointerId)
|
|
269
|
+
setDragging(axis)
|
|
270
|
+
}
|
|
271
|
+
const active =
|
|
272
|
+
visibility === 'always' ||
|
|
273
|
+
focused ||
|
|
274
|
+
dragging !== null ||
|
|
275
|
+
(visibility === 'hover' ? hovered : scrolling)
|
|
276
|
+
const track = metrics ? tracks(metrics) : null
|
|
277
|
+
const nativeProps = {
|
|
278
|
+
...props,
|
|
279
|
+
role: undefined,
|
|
280
|
+
contentEditable: undefined,
|
|
281
|
+
dangerouslySetInnerHTML: undefined
|
|
282
|
+
}
|
|
283
|
+
return (
|
|
284
|
+
// oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- The native scroll viewport owns keyboard scrolling; pointer delegation operates its decorative scrollbars.
|
|
285
|
+
<div
|
|
286
|
+
{...nativeProps}
|
|
287
|
+
role="group"
|
|
288
|
+
ref={hostRef}
|
|
289
|
+
tabIndex={tabIndex}
|
|
290
|
+
style={style}
|
|
291
|
+
data-slot={joinIds('scroll-area', props['data-slot'])}
|
|
292
|
+
data-orientation={orientation}
|
|
293
|
+
data-visibility={visibility}
|
|
294
|
+
data-enhanced={metrics ? '' : undefined}
|
|
295
|
+
className={cn(
|
|
296
|
+
'relative box-border min-h-0 min-w-0 [scrollbar-width:thin] [scrollbar-color:var(--rad-scroll-area-thumb-color,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))_var(--rad-scroll-area-track-color,var(--rad-color-surface,oklch(1_0_0)))]',
|
|
297
|
+
'data-enhanced:[scrollbar-width:none] [&[data-enhanced]::-webkit-scrollbar]:hidden',
|
|
298
|
+
'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-color-focus,oklch(0.55_0.13_255))] focus-visible:[outline-width:var(--rad-focus-width,2px)] focus-visible:[outline-offset:var(--rad-focus-offset,2px)] forced-colors:focus-visible:outline-[Highlight]',
|
|
299
|
+
orientation === 'vertical'
|
|
300
|
+
? 'overflow-x-hidden overflow-y-auto'
|
|
301
|
+
: orientation === 'horizontal'
|
|
302
|
+
? 'overflow-x-auto overflow-y-hidden'
|
|
303
|
+
: 'overflow-auto',
|
|
304
|
+
className
|
|
305
|
+
)}
|
|
306
|
+
onPointerDown={start}
|
|
307
|
+
onPointerMove={event => {
|
|
308
|
+
onPointerMove?.(event)
|
|
309
|
+
const current = gesture.current
|
|
310
|
+
if (!current || current.pointerId !== event.pointerId) return
|
|
311
|
+
if (event.defaultPrevented) {
|
|
312
|
+
finish()
|
|
313
|
+
return
|
|
314
|
+
}
|
|
315
|
+
event.preventDefault()
|
|
316
|
+
const coordinate = current.axis === 'vertical' ? event.clientY : event.clientX
|
|
317
|
+
moveTo(
|
|
318
|
+
current.axis,
|
|
319
|
+
current.offset + ((coordinate - current.start) / current.travel) * current.max
|
|
320
|
+
)
|
|
321
|
+
}}
|
|
322
|
+
onPointerUp={event => {
|
|
323
|
+
onPointerUp?.(event)
|
|
324
|
+
if (gesture.current?.pointerId === event.pointerId) finish()
|
|
325
|
+
}}
|
|
326
|
+
onPointerCancel={event => {
|
|
327
|
+
onPointerCancel?.(event)
|
|
328
|
+
if (gesture.current?.pointerId === event.pointerId) finish()
|
|
329
|
+
}}
|
|
330
|
+
onLostPointerCapture={event => {
|
|
331
|
+
onLostPointerCapture?.(event)
|
|
332
|
+
if (gesture.current?.pointerId === event.pointerId) finish()
|
|
333
|
+
}}
|
|
334
|
+
onPointerEnter={event => {
|
|
335
|
+
onPointerEnter?.(event)
|
|
336
|
+
setHovered(true)
|
|
337
|
+
}}
|
|
338
|
+
onPointerLeave={event => {
|
|
339
|
+
onPointerLeave?.(event)
|
|
340
|
+
setHovered(false)
|
|
341
|
+
}}
|
|
342
|
+
onFocus={event => {
|
|
343
|
+
onFocus?.(event)
|
|
344
|
+
setFocused(true)
|
|
345
|
+
}}
|
|
346
|
+
onBlur={event => {
|
|
347
|
+
onBlur?.(event)
|
|
348
|
+
const win = event.currentTarget.ownerDocument.defaultView
|
|
349
|
+
if (
|
|
350
|
+
!win ||
|
|
351
|
+
!(event.relatedTarget instanceof win.Node) ||
|
|
352
|
+
!event.currentTarget.contains(event.relatedTarget)
|
|
353
|
+
)
|
|
354
|
+
setFocused(false)
|
|
355
|
+
}}
|
|
356
|
+
onScroll={event => {
|
|
357
|
+
onScroll?.(event)
|
|
358
|
+
if (event.target !== event.currentTarget) return
|
|
359
|
+
position()
|
|
360
|
+
if (visibility === 'scroll') {
|
|
361
|
+
setScrolling(true)
|
|
362
|
+
const win = event.currentTarget.ownerDocument.defaultView
|
|
363
|
+
if (win) {
|
|
364
|
+
win.clearTimeout(hideTimer.current)
|
|
365
|
+
hideTimer.current = win.setTimeout(() => setScrolling(false), 900)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}}
|
|
369
|
+
>
|
|
370
|
+
<div
|
|
371
|
+
aria-hidden="true"
|
|
372
|
+
className="pointer-events-none sticky start-0 top-0 z-10 h-0 w-full"
|
|
373
|
+
>
|
|
374
|
+
{track?.vertical && metrics ? (
|
|
375
|
+
<Bar
|
|
376
|
+
owner={owner}
|
|
377
|
+
axis="vertical"
|
|
378
|
+
length={track.height}
|
|
379
|
+
thumb={track.thumbHeight}
|
|
380
|
+
active={active}
|
|
381
|
+
dragging={dragging === 'vertical'}
|
|
382
|
+
offset={0}
|
|
383
|
+
parts={parts}
|
|
384
|
+
/>
|
|
385
|
+
) : null}
|
|
386
|
+
{track?.horizontal && metrics ? (
|
|
387
|
+
<Bar
|
|
388
|
+
owner={owner}
|
|
389
|
+
axis="horizontal"
|
|
390
|
+
length={track.width}
|
|
391
|
+
thumb={track.thumbWidth}
|
|
392
|
+
active={active}
|
|
393
|
+
dragging={dragging === 'horizontal'}
|
|
394
|
+
offset={metrics.rtl && track.vertical ? hitSize : 0}
|
|
395
|
+
top={metrics.innerHeight - hitSize}
|
|
396
|
+
parts={parts}
|
|
397
|
+
/>
|
|
398
|
+
) : null}
|
|
399
|
+
</div>
|
|
400
|
+
<div
|
|
401
|
+
ref={content}
|
|
402
|
+
className={cn(
|
|
403
|
+
'box-border min-h-full min-w-full',
|
|
404
|
+
orientation === 'vertical' ? 'w-full' : 'w-max'
|
|
405
|
+
)}
|
|
406
|
+
style={{
|
|
407
|
+
paddingInlineEnd: orientation !== 'horizontal' ? hitSize : undefined,
|
|
408
|
+
paddingBottom: orientation !== 'vertical' ? hitSize : undefined
|
|
409
|
+
}}
|
|
410
|
+
>
|
|
411
|
+
<div
|
|
412
|
+
data-slot="scroll-area-content"
|
|
413
|
+
className={cn('flow-root min-w-0', parts?.content?.className)}
|
|
414
|
+
style={parts?.content?.style}
|
|
415
|
+
>
|
|
416
|
+
{children}
|
|
417
|
+
</div>
|
|
418
|
+
</div>
|
|
419
|
+
</div>
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
function Bar({
|
|
423
|
+
owner,
|
|
424
|
+
axis,
|
|
425
|
+
length,
|
|
426
|
+
thumb,
|
|
427
|
+
active,
|
|
428
|
+
dragging,
|
|
429
|
+
offset,
|
|
430
|
+
top = 0,
|
|
431
|
+
parts
|
|
432
|
+
}: {
|
|
433
|
+
owner: string
|
|
434
|
+
axis: Axis
|
|
435
|
+
length: number
|
|
436
|
+
thumb: number
|
|
437
|
+
active: boolean
|
|
438
|
+
dragging: boolean
|
|
439
|
+
offset: number
|
|
440
|
+
top?: number
|
|
441
|
+
parts?: ScrollAreaProps['parts']
|
|
442
|
+
}) {
|
|
443
|
+
const vertical = axis === 'vertical'
|
|
444
|
+
const shape = vertical
|
|
445
|
+
? 'left-1/2 h-full max-w-full -translate-x-1/2 w-[var(--rad-scroll-area-size,6px)]'
|
|
446
|
+
: 'top-1/2 w-full max-h-full -translate-y-1/2 h-[var(--rad-scroll-area-size,6px)]'
|
|
447
|
+
return (
|
|
448
|
+
<div
|
|
449
|
+
data-scroll-area-hit=""
|
|
450
|
+
data-axis={axis}
|
|
451
|
+
data-owner={owner}
|
|
452
|
+
className="absolute touch-none select-none"
|
|
453
|
+
style={{
|
|
454
|
+
width: vertical ? hitSize : length,
|
|
455
|
+
height: vertical ? length : hitSize,
|
|
456
|
+
insetInlineEnd: vertical ? 0 : undefined,
|
|
457
|
+
left: vertical ? undefined : offset,
|
|
458
|
+
top,
|
|
459
|
+
opacity: active ? 1 : 0,
|
|
460
|
+
pointerEvents: active ? 'auto' : 'none'
|
|
461
|
+
}}
|
|
462
|
+
>
|
|
463
|
+
<span
|
|
464
|
+
data-slot="scroll-area-scrollbar"
|
|
465
|
+
data-axis={axis}
|
|
466
|
+
data-state={active ? 'visible' : 'hidden'}
|
|
467
|
+
className={cn(
|
|
468
|
+
'absolute rounded-[var(--rad-scroll-area-radius,var(--rad-control-radius,0.5rem))] bg-[var(--rad-scroll-area-track-color,var(--rad-color-surface,oklch(1_0_0)))] forced-colors:bg-[Canvas]',
|
|
469
|
+
shape,
|
|
470
|
+
parts?.scrollbar?.className
|
|
471
|
+
)}
|
|
472
|
+
style={parts?.scrollbar?.style}
|
|
473
|
+
/>
|
|
474
|
+
<div
|
|
475
|
+
data-scroll-area-thumb-hit=""
|
|
476
|
+
data-axis={axis}
|
|
477
|
+
className="absolute top-0 left-0 touch-none"
|
|
478
|
+
style={{
|
|
479
|
+
width: vertical ? hitSize : thumb,
|
|
480
|
+
height: vertical ? thumb : hitSize,
|
|
481
|
+
translate: vertical
|
|
482
|
+
? '0 var(--_rad-scroll-area-thumb-y,0px)'
|
|
483
|
+
: 'var(--_rad-scroll-area-thumb-x,0px) 0'
|
|
484
|
+
}}
|
|
485
|
+
>
|
|
486
|
+
<span
|
|
487
|
+
data-slot="scroll-area-thumb"
|
|
488
|
+
data-axis={axis}
|
|
489
|
+
data-dragging={dragging ? '' : undefined}
|
|
490
|
+
className={cn(
|
|
491
|
+
'absolute rounded-[var(--rad-scroll-area-radius,var(--rad-control-radius,0.5rem))] bg-[var(--rad-scroll-area-thumb-color,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))] forced-colors:bg-[CanvasText]',
|
|
492
|
+
shape,
|
|
493
|
+
parts?.thumb?.className
|
|
494
|
+
)}
|
|
495
|
+
style={parts?.thumb?.style}
|
|
496
|
+
/>
|
|
497
|
+
</div>
|
|
498
|
+
</div>
|
|
499
|
+
)
|
|
500
|
+
}
|
package/src/Select.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import type { ComponentProps, ReactNode, RefObject } from 'react'
|
|
|
15
15
|
import { createPortal } from 'react-dom'
|
|
16
16
|
import { Button, type ButtonProps } from './Button.js'
|
|
17
17
|
import { useField, useFieldControl } from './Field.js'
|
|
18
|
+
import type { DistributiveOmit } from './internal/types.js'
|
|
18
19
|
import { cn } from './cn.js'
|
|
19
20
|
import { controlMetrics } from './controlStyles.js'
|
|
20
21
|
import { matchSelectText, moveSelectFocus, positionSelect } from './internal/select.js'
|
|
@@ -296,7 +297,7 @@ export function Select({
|
|
|
296
297
|
)
|
|
297
298
|
}
|
|
298
299
|
|
|
299
|
-
export type SelectTriggerProps =
|
|
300
|
+
export type SelectTriggerProps = DistributiveOmit<
|
|
300
301
|
ButtonProps,
|
|
301
302
|
'variant' | 'tone' | 'type' | 'pending' | 'controlSize' | 'disabled'
|
|
302
303
|
>
|
package/src/Tabs.tsx
CHANGED
|
@@ -92,6 +92,9 @@ export type TabsTriggerProps = Omit<
|
|
|
92
92
|
| 'fullWidth'
|
|
93
93
|
| 'pending'
|
|
94
94
|
| 'motion'
|
|
95
|
+
| 'pressed'
|
|
96
|
+
| 'defaultPressed'
|
|
97
|
+
| 'onPressedChange'
|
|
95
98
|
> & { value: string }
|
|
96
99
|
export type TabsContentProps = Omit<
|
|
97
100
|
ComponentProps<'div'>,
|
|
@@ -347,6 +350,9 @@ export function TabsTrigger({
|
|
|
347
350
|
data-orientation={tabs.orientation}
|
|
348
351
|
motion="off"
|
|
349
352
|
pending={false}
|
|
353
|
+
pressed={undefined}
|
|
354
|
+
defaultPressed={undefined}
|
|
355
|
+
onPressedChange={undefined}
|
|
350
356
|
variant="ghost"
|
|
351
357
|
tone="neutral"
|
|
352
358
|
controlSize={controlSize ?? tabs.controlSize}
|