@justanarthur/modo-ui 2.1.0 → 2.3.0

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 (145) hide show
  1. package/blocks/desktop-shell/index.tsx +2 -1
  2. package/components/inputs/checkbox/index.tsx +5 -0
  3. package/components/inputs/combobox/index.tsx +9 -4
  4. package/components/inputs/radio/index.tsx +5 -0
  5. package/components/inputs/select/index.tsx +23 -3
  6. package/components/inputs/slider/comfortable.tsx +10 -4
  7. package/components/inputs/slider/compact.tsx +153 -71
  8. package/components/inputs/slider/examples.mdx +24 -0
  9. package/components/inputs/slider/geometry.ts +18 -6
  10. package/components/inputs/slider/index.tsx +30 -8
  11. package/components/inputs/slider/value-display.tsx +16 -9
  12. package/components/inputs/switch/index.tsx +5 -0
  13. package/components/inputs/textarea/examples.mdx +19 -0
  14. package/components/inputs/textarea/index.tsx +42 -5
  15. package/components/navigation/sidebar/sidebar-group.tsx +2 -1
  16. package/components/navigation/sidebar/sidebar-menu-sub.tsx +2 -1
  17. package/components/navigation/sidebar/sidebar-shell.tsx +2 -1
  18. package/components/navigation/tree/index.tsx +2 -1
  19. package/components/overlays/dropdown/index.tsx +50 -8
  20. package/components/overlays/dropdown/submenu.tsx +41 -10
  21. package/components/overlays/tooltip/examples.mdx +13 -0
  22. package/components/overlays/tooltip/index.tsx +58 -16
  23. package/dist/blocks/desktop-shell/index.js +10 -9
  24. package/dist/blocks/sidebar-app/index.js +11 -10
  25. package/dist/components/actions/button/index.js +2 -2
  26. package/dist/components/actions/copy/index.js +4 -4
  27. package/dist/components/containers/accordion/index.d.ts +1 -1
  28. package/dist/components/containers/accordion/index.js +2 -2
  29. package/dist/components/containers/card/index.js +3 -3
  30. package/dist/components/data-display/log-view/index.js +3 -3
  31. package/dist/components/inputs/checkbox/index.d.ts +2 -0
  32. package/dist/components/inputs/checkbox/index.js +1 -1
  33. package/dist/components/inputs/color-picker/index.js +5 -5
  34. package/dist/components/inputs/combobox/index.d.ts +1 -1
  35. package/dist/components/inputs/combobox/index.js +2 -2
  36. package/dist/components/inputs/date-time/date-picker/index.js +7 -7
  37. package/dist/components/inputs/date-time/date-range-picker/index.js +7 -7
  38. package/dist/components/inputs/date-time/duration-picker/index.js +7 -7
  39. package/dist/components/inputs/date-time/month-picker/index.js +7 -7
  40. package/dist/components/inputs/date-time/time-picker/index.js +7 -7
  41. package/dist/components/inputs/field/index.js +2 -2
  42. package/dist/components/inputs/file-dropzone/index.js +3 -3
  43. package/dist/components/inputs/key-value/index.js +3 -3
  44. package/dist/components/inputs/radio/index.d.ts +2 -0
  45. package/dist/components/inputs/radio/index.js +1 -1
  46. package/dist/components/inputs/search/index.js +6 -6
  47. package/dist/components/inputs/select/index.d.ts +22 -4
  48. package/dist/components/inputs/select/index.js +3 -3
  49. package/dist/components/inputs/slider/index.d.ts +12 -3
  50. package/dist/components/inputs/slider/index.js +1 -1
  51. package/dist/components/inputs/switch/index.d.ts +2 -0
  52. package/dist/components/inputs/switch/index.js +1 -1
  53. package/dist/components/inputs/textarea/index.d.ts +8 -1
  54. package/dist/components/inputs/textarea/index.js +1 -1
  55. package/dist/components/navigation/breadcrumb/index.js +4 -4
  56. package/dist/components/navigation/navigation-menu/index.js +2 -2
  57. package/dist/components/navigation/pagination/index.js +3 -3
  58. package/dist/components/navigation/sidebar/index.js +8 -7
  59. package/dist/components/navigation/tree/index.js +2 -1
  60. package/dist/components/overlays/alert-dialog/index.d.ts +3 -3
  61. package/dist/components/overlays/alert-dialog/index.js +5 -5
  62. package/dist/components/overlays/command/index.d.ts +1 -1
  63. package/dist/components/overlays/command/index.js +5 -5
  64. package/dist/components/overlays/context-menu/index.d.ts +20 -1
  65. package/dist/components/overlays/context-menu/index.js +4 -4
  66. package/dist/components/overlays/dialog/index.d.ts +3 -3
  67. package/dist/components/overlays/dialog/index.js +4 -4
  68. package/dist/components/overlays/dropdown/index.d.ts +30 -8
  69. package/dist/components/overlays/dropdown/index.js +3 -3
  70. package/dist/components/overlays/lightbox/index.js +3 -3
  71. package/dist/components/overlays/popover/index.d.ts +6 -6
  72. package/dist/components/overlays/popover/index.js +3 -3
  73. package/dist/components/overlays/preview-card/index.js +2 -2
  74. package/dist/components/overlays/sheet/index.d.ts +3 -3
  75. package/dist/components/overlays/sheet/index.js +5 -5
  76. package/dist/components/overlays/toast/index.d.ts +1 -1
  77. package/dist/components/overlays/toast/index.js +3 -3
  78. package/dist/components/overlays/tooltip/index.d.ts +35 -10
  79. package/dist/components/overlays/tooltip/index.js +3 -3
  80. package/dist/docs/index.js +9 -8
  81. package/dist/index.d.ts +92 -38
  82. package/dist/index.js +47 -46
  83. package/dist/lib/inert.d.ts +7 -0
  84. package/dist/lib/inert.js +6 -0
  85. package/dist/lib/overlay.d.ts +20 -13
  86. package/dist/lib/overlay.js +2 -1
  87. package/dist/lib/slot.d.ts +5 -2
  88. package/dist/lib/slot.js +1 -1
  89. package/dist/primitives/layout/resizable/index.d.ts +4 -2
  90. package/dist/primitives/layout/resizable/index.js +1 -1
  91. package/dist/primitives/systems/morph/index.js +3 -3
  92. package/dist/primitives/systems/motion/index.js +3 -3
  93. package/dist/shared/{components-s90v3jpr.js → components-01e24999.js} +60 -11
  94. package/dist/shared/{components-a1ms36qq.js → components-1f5624hb.js} +1 -1
  95. package/dist/shared/{components-9z7bq8gn.js → components-1sbnbq6a.js} +1 -1
  96. package/dist/shared/{components-w2at9ntm.js → components-27fatggq.js} +1 -1
  97. package/dist/shared/{components-fmyvz4r2.js → components-2bq4ng4d.js} +4 -4
  98. package/dist/shared/components-2myjk2zf.js +8 -0
  99. package/dist/shared/{components-hz6armxa.js → components-2tw25pk6.js} +3 -0
  100. package/dist/shared/{components-nhmgr5xc.js → components-2v4mmw1s.js} +10 -7
  101. package/dist/shared/{components-twyj2y8c.js → components-3rt5c1qt.js} +1 -1
  102. package/dist/shared/{components-91mmbrw3.js → components-3sb31vw5.js} +1 -1
  103. package/dist/shared/{components-1f3a7gmg.js → components-4fswe4kh.js} +1 -1
  104. package/dist/shared/{components-gsstwhtv.js → components-5vezp3e5.js} +3 -0
  105. package/dist/shared/{components-ee09xmkh.js → components-6g8a5nrs.js} +4 -1
  106. package/dist/shared/{components-h0x2pj2y.js → components-6xtntksc.js} +17 -3
  107. package/dist/shared/{components-1asw2ph0.js → components-7g2q2ccp.js} +1 -1
  108. package/dist/shared/{components-kwxye0an.js → components-7wjkag2j.js} +4 -2
  109. package/dist/shared/{components-vfreweq3.js → components-83jn0raj.js} +1 -1
  110. package/dist/shared/{components-1bnf96sr.js → components-8e0fjgm9.js} +37 -9
  111. package/dist/shared/{components-j79a6jqa.js → components-8ybvpebx.js} +1 -1
  112. package/dist/shared/{components-me742146.js → components-a3brpprb.js} +1 -1
  113. package/dist/shared/{components-ev0ytbqb.js → components-abqfs5fh.js} +1 -1
  114. package/dist/shared/{components-r5q9gdh4.js → components-agjpst9b.js} +5 -5
  115. package/dist/shared/{components-6rtawx8y.js → components-e52xgvd9.js} +4 -4
  116. package/dist/shared/{components-0cpte6s1.js → components-eebf7f9c.js} +4 -3
  117. package/dist/shared/{components-xa9fvd5b.js → components-etgpz4zk.js} +1 -1
  118. package/dist/shared/{components-b9bj65j3.js → components-ex2xtqv7.js} +6 -6
  119. package/dist/shared/{components-n0gbyp5a.js → components-fjg4j430.js} +5 -5
  120. package/dist/shared/{components-280grw6q.js → components-fxw1122w.js} +1 -1
  121. package/dist/shared/{components-y8m64zdw.js → components-gnsvnejm.js} +1 -1
  122. package/dist/shared/{components-7mj5wsv3.js → components-gr82tz50.js} +21 -3
  123. package/dist/shared/{components-22h8dvt1.js → components-k25zw9g8.js} +3 -3
  124. package/dist/shared/{components-a1mwqxsv.js → components-k2gg1agj.js} +3 -3
  125. package/dist/shared/{components-wx1dcp2n.js → components-kz6ak6kj.js} +1 -1
  126. package/dist/shared/{components-yf2gtq68.js → components-m7d7r3r8.js} +8 -5
  127. package/dist/shared/{components-62510420.js → components-mvwf8ckh.js} +4 -4
  128. package/dist/shared/{components-2m2hg11x.js → components-nh05qz8b.js} +3 -3
  129. package/dist/shared/{components-77gxngmc.js → components-nred2e6g.js} +5 -5
  130. package/dist/shared/{components-3rvrdsa9.js → components-s2pnh8h9.js} +1 -1
  131. package/dist/shared/{components-xnkc892z.js → components-t4j0r23n.js} +1 -1
  132. package/dist/shared/{components-rgng034x.js → components-tcm3k3wj.js} +24 -3
  133. package/dist/shared/{components-p32aqk3q.js → components-vx286kq7.js} +110 -73
  134. package/dist/shared/{components-b2kjsn1s.js → components-vykcfb5r.js} +1 -1
  135. package/dist/shared/{components-hcftn5r8.js → components-x5v7e0fz.js} +3 -0
  136. package/dist/shared/{components-0h2mng6m.js → components-ycwhrqe1.js} +1 -1
  137. package/dist/shared/{components-chda6b23.js → components-ypxst3cn.js} +33 -4
  138. package/dist/shared/{components-14wzcym0.js → components-z87sanbc.js} +5 -5
  139. package/dist/shared/{components-fqsgd07c.js → components-zv63s4fh.js} +2 -2
  140. package/dist/styles.css +5 -1
  141. package/lib/inert.ts +15 -0
  142. package/lib/overlay.tsx +49 -5
  143. package/lib/slot.tsx +9 -3
  144. package/package.json +6 -1
  145. package/primitives/layout/resizable/index.tsx +35 -7
@@ -22,8 +22,9 @@ import {
22
22
  import { spring } from '../../../lib/springs'
23
23
  import { cn } from '../../../lib/utils'
24
24
  import {
25
+ axisLength,
25
26
  DOT_SIZE,
26
- layoutX,
27
+ layoutPos,
27
28
  nearestStepIndex,
28
29
  pixelToValue,
29
30
  type SliderValue,
@@ -68,6 +69,9 @@ interface SliderEngineProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChan
68
69
  hideFill?: boolean
69
70
  thumbColor?: string
70
71
  thumbBorderColor?: string
72
+ orientation?: 'horizontal' | 'vertical'
73
+ /** Called once an interaction ends (a pointer lifting, a keyboard step, a committed edit). */
74
+ onCommit?: () => void
71
75
  }
72
76
 
73
77
  const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
@@ -81,7 +85,7 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
81
85
  steps,
82
86
  showSteps = false,
83
87
  showValue = true,
84
- valuePosition = 'left',
88
+ valuePosition: valuePositionProp,
85
89
  formatValue = String,
86
90
  label,
87
91
  disabled = false,
@@ -93,11 +97,15 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
93
97
  hideFill = false,
94
98
  thumbColor,
95
99
  thumbBorderColor,
100
+ orientation = 'horizontal',
101
+ onCommit,
96
102
  className,
97
103
  ...props
98
104
  },
99
105
  ref,
100
106
  ) => {
107
+ const vertical = orientation === 'vertical'
108
+ const valuePosition = valuePositionProp ?? (vertical ? 'top' : 'left')
101
109
  const isRange = Array.isArray(value)
102
110
  const values = toRadixValue(value)
103
111
 
@@ -146,15 +154,20 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
146
154
  )
147
155
  const fillWidth = isRange ? fillWidthRange : fillWidthSingle
148
156
 
157
+ // Vertical: the axis position grows upward from the bottom edge.
158
+ const thumbY0 = useTransform(motionX0, x => -x)
159
+ const thumbY1 = useTransform(motionX1, x => -x)
160
+
149
161
  // Hides the dots on the filled side, like the comfortable design's pips.
162
+ const maskDir = vertical ? 'to top' : 'to right'
150
163
  const stepDotsMaskSingle = useTransform(motionX0, x => {
151
164
  const edge = x + THUMB_SIZE / 2
152
- return `linear-gradient(to right, transparent ${edge}px, black ${edge + 2}px)`
165
+ return `linear-gradient(${maskDir}, transparent ${edge}px, black ${edge + 2}px)`
153
166
  })
154
167
  const stepDotsMaskRange = useTransform([motionX0, motionX1] as MotionValue<number>[], ([x0, x1]) => {
155
168
  const left = (x0 as number) + THUMB_SIZE / 2
156
169
  const right = (x1 as number) + THUMB_SIZE / 2
157
- return `linear-gradient(to right, black ${left - 2}px, transparent ${left}px, transparent ${right}px, black ${right + 2}px)`
170
+ return `linear-gradient(${maskDir}, black ${left - 2}px, transparent ${left}px, transparent ${right}px, black ${right + 2}px)`
158
171
  })
159
172
  const stepDotsMask = isRange ? stepDotsMaskRange : stepDotsMaskSingle
160
173
 
@@ -187,7 +200,7 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
187
200
  useLayoutEffect(() => {
188
201
  const el = trackRef.current
189
202
  if (!el || initialSyncDone.current) return
190
- const w = el.offsetWidth
203
+ const w = axisLength(el, vertical)
191
204
  trackWidthRef.current = w
192
205
  const px0 = valueToPixel(values[0]!, min, max, w)
193
206
  motionX0.set(px0)
@@ -203,7 +216,7 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
203
216
  const el = trackRef.current
204
217
  if (!el) return
205
218
  const ro = new ResizeObserver(([entry]) => {
206
- const w = entry!.contentRect.width
219
+ const w = vertical ? entry!.contentRect.height : entry!.contentRect.width
207
220
  trackWidthRef.current = w
208
221
  if (!dragging.current && initialSyncDone.current) {
209
222
  const v = valuesRef.current
@@ -219,7 +232,7 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
219
232
  })
220
233
  ro.observe(el)
221
234
  return () => ro.disconnect()
222
- }, [isRange, motionX0, motionX1])
235
+ }, [isRange, vertical, motionX0, motionX1])
223
236
 
224
237
  // Depend on a primitive key rather than the `values` array — its identity
225
238
  // changes every render (toRadixValue allocates), which would restart the
@@ -272,9 +285,9 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
272
285
 
273
286
  const trackEl = trackRef.current
274
287
  if (!trackEl) return
275
- const x = layoutX(e.clientX, trackEl)
288
+ const x = layoutPos(e, trackEl, vertical)
276
289
  if (x === null) return
277
- const layoutWidth = trackEl.offsetWidth
290
+ const layoutWidth = axisLength(trackEl, vertical)
278
291
  const clamped = Math.max(0, Math.min(layoutWidth - THUMB_SIZE, x - THUMB_SIZE / 2))
279
292
 
280
293
  if (isRange) {
@@ -301,7 +314,7 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
301
314
 
302
315
  ;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
303
316
  },
304
- [disabled, isRange, min, max, step, stepValues, motionX0, motionX1, clampForRange, emitChange],
317
+ [disabled, vertical, isRange, min, max, step, stepValues, motionX0, motionX1, clampForRange, emitChange],
305
318
  )
306
319
 
307
320
  const handlePointerMove = useCallback(
@@ -310,9 +323,9 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
310
323
  e.stopPropagation()
311
324
  const trackEl = trackRef.current
312
325
  if (!trackEl) return
313
- const x = layoutX(e.clientX, trackEl)
326
+ const x = layoutPos(e, trackEl, vertical)
314
327
  if (x === null) return
315
- const layoutWidth = trackEl.offsetWidth
328
+ const layoutWidth = axisLength(trackEl, vertical)
316
329
  const clamped = Math.max(0, Math.min(layoutWidth - THUMB_SIZE, x - THUMB_SIZE / 2))
317
330
 
318
331
  const motionX = activeDragThumb.current === 0 ? motionX0 : motionX1
@@ -325,12 +338,13 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
325
338
  const finalValue = pixelToValue(finalPx, min, max, step, layoutWidth, stepValues)
326
339
  emitChange(activeDragThumb.current, finalValue)
327
340
  },
328
- [min, max, step, stepValues, motionX0, motionX1, clampForRange, emitChange],
341
+ [vertical, min, max, step, stepValues, motionX0, motionX1, clampForRange, emitChange],
329
342
  )
330
343
 
331
344
  const handlePointerUp = useCallback(() => {
332
345
  if (!dragging.current) return
333
346
  dragging.current = false
347
+ onCommit?.()
334
348
  setIsPressed(false)
335
349
  setHoverPreview(null)
336
350
 
@@ -340,7 +354,7 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
340
354
  const snapped = pixelToValue(currentPx, min, max, step, tw, stepValues)
341
355
  const snappedPx = valueToPixel(snapped, min, max, tw)
342
356
  animate(motionX, snappedPx, spring.moderate)
343
- }, [min, max, step, stepValues, motionX0, motionX1])
357
+ }, [min, max, step, stepValues, motionX0, motionX1, onCommit])
344
358
 
345
359
  // In steps mode the primitive runs on indices (0..len-1, step 1) so arrow
346
360
  // keys walk the list; map indices back to actual values on the way out.
@@ -364,9 +378,10 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
364
378
  const handleCommitEdit = useCallback(
365
379
  (index: number, v: number) => {
366
380
  emitChange(index, v)
381
+ onCommit?.()
367
382
  setEditingIndex(null)
368
383
  },
369
- [emitChange],
384
+ [emitChange, onCommit],
370
385
  )
371
386
 
372
387
  const handleCancelEdit = useCallback(() => {
@@ -424,16 +439,29 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
424
439
  <motion.span
425
440
  key={`visual-thumb-${index}`}
426
441
  className="flex items-center justify-center pointer-events-none"
427
- style={{
428
- width: THUMB_SIZE,
429
- height: THUMB_SIZE,
430
- marginTop: -THUMB_SIZE / 2,
431
- x: motionX,
432
- position: 'absolute',
433
- top: '50%',
434
- left: 0,
435
- zIndex: 10,
436
- }}
442
+ style={
443
+ vertical
444
+ ? {
445
+ width: THUMB_SIZE,
446
+ height: THUMB_SIZE,
447
+ marginLeft: -THUMB_SIZE / 2,
448
+ y: index === 0 ? thumbY0 : thumbY1,
449
+ position: 'absolute',
450
+ left: '50%',
451
+ bottom: 0,
452
+ zIndex: 10,
453
+ }
454
+ : {
455
+ width: THUMB_SIZE,
456
+ height: THUMB_SIZE,
457
+ marginTop: -THUMB_SIZE / 2,
458
+ x: motionX,
459
+ position: 'absolute',
460
+ top: '50%',
461
+ left: 0,
462
+ zIndex: 10,
463
+ }
464
+ }
437
465
  initial={false}
438
466
  >
439
467
  <motion.span
@@ -467,8 +495,14 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
467
495
  <div
468
496
  ref={ref}
469
497
  className={cn(
470
- 'flex flex-col gap-0 w-full select-none touch-none overflow-visible',
471
- valuePosition === 'left' || valuePosition === 'right' ? 'flex-row items-center gap-2 mb-2' : 'flex-col',
498
+ 'flex gap-0 select-none touch-none overflow-visible',
499
+ vertical ? 'h-40 w-fit items-center' : 'flex-col w-full',
500
+ valuePosition === 'left' || valuePosition === 'right'
501
+ ? vertical
502
+ ? 'flex-row gap-2'
503
+ : 'flex-row items-center gap-2 mb-2'
504
+ : 'flex-col',
505
+ vertical && (valuePosition === 'top' || valuePosition === 'bottom' || valuePosition === 'tooltip') && 'gap-2',
472
506
  disabled && 'opacity-50 pointer-events-none',
473
507
  className,
474
508
  )}
@@ -477,14 +511,22 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
477
511
  {(valuePosition === 'top' || valuePosition === 'left') && valueDisplay}
478
512
 
479
513
  <div
480
- className="relative flex-1 overflow-visible"
481
- style={{
482
- height:
483
- valuePosition === 'left' || valuePosition === 'right'
484
- ? THUMB_SIZE + 16
485
- : THUMB_SIZE + (valuePosition === 'tooltip' ? 16 : 0),
486
- paddingTop: valuePosition === 'tooltip' ? 16 : 0,
487
- }}
514
+ className={cn(
515
+ 'relative overflow-visible',
516
+ vertical ? 'min-h-0 min-w-0' : 'flex-1',
517
+ vertical && (valuePosition === 'left' || valuePosition === 'right' ? 'h-full' : 'flex-1'),
518
+ )}
519
+ style={
520
+ vertical
521
+ ? { width: THUMB_SIZE + 16 }
522
+ : {
523
+ height:
524
+ valuePosition === 'left' || valuePosition === 'right'
525
+ ? THUMB_SIZE + 16
526
+ : THUMB_SIZE + (valuePosition === 'tooltip' ? 16 : 0),
527
+ paddingTop: valuePosition === 'tooltip' ? 16 : 0,
528
+ }
529
+ }
488
530
  onPointerEnter={() => setIsHovered(true)}
489
531
  onPointerLeave={() => {
490
532
  setIsHovered(false)
@@ -494,18 +536,31 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
494
536
  if (dragging.current) return
495
537
  const trackEl = trackRef.current
496
538
  if (!trackEl) return
497
- const x = layoutX(e.clientX, trackEl)
539
+ const x = layoutPos(e, trackEl, vertical)
498
540
  if (x === null) return
499
- computeHoverPreview(Math.max(0, Math.min(trackEl.offsetWidth, x)), trackEl.offsetWidth)
541
+ const length = axisLength(trackEl, vertical)
542
+ computeHoverPreview(Math.max(0, Math.min(length, x)), length)
500
543
  }}
501
544
  >
502
545
  {showValue && valuePosition === 'tooltip' && (
503
546
  <AnimatePresence>
504
547
  {isInteracting && (
505
- <TooltipValue key="tooltip-0" value={values[0]!} formatValue={formatValue} motionX={motionX0} />
548
+ <TooltipValue
549
+ key="tooltip-0"
550
+ value={values[0]!}
551
+ formatValue={formatValue}
552
+ motionX={motionX0}
553
+ vertical={vertical}
554
+ />
506
555
  )}
507
556
  {isInteracting && isRange && values[1] !== undefined && (
508
- <TooltipValue key="tooltip-1" value={values[1]} formatValue={formatValue} motionX={motionX1} />
557
+ <TooltipValue
558
+ key="tooltip-1"
559
+ value={values[1]}
560
+ formatValue={formatValue}
561
+ motionX={motionX1}
562
+ vertical={vertical}
563
+ />
509
564
  )}
510
565
  </AnimatePresence>
511
566
  )}
@@ -514,13 +569,15 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
514
569
  <SliderPrimitive.Root
515
570
  value={stepValues ? values.map(v => nearestStepIndex(v, stepValues)) : values}
516
571
  onValueChange={v => handleRadixChange(v as number[])}
572
+ onValueCommitted={() => onCommit?.()}
517
573
  name={name}
518
574
  min={stepValues ? 0 : min}
519
575
  max={stepValues ? stepValues.length - 1 : max}
520
576
  step={stepValues ? 1 : step}
577
+ orientation={orientation}
521
578
  disabled={disabled}
522
579
  className="absolute inset-0 opacity-0 pointer-events-none"
523
- style={{ height: THUMB_SIZE }}
580
+ style={vertical ? { width: THUMB_SIZE } : { height: THUMB_SIZE }}
524
581
  >
525
582
  <SliderPrimitive.Control className="w-full h-full">
526
583
  <SliderPrimitive.Track className="w-full h-full">
@@ -555,8 +612,12 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
555
612
 
556
613
  <div
557
614
  ref={trackRef}
558
- className="relative w-full cursor-ew-resize py-2"
559
- style={{ height: THUMB_SIZE + 16, opacity: ready ? 1 : 0 }}
615
+ className={cn('relative', vertical ? 'h-full cursor-ns-resize px-2' : 'w-full cursor-ew-resize py-2')}
616
+ style={
617
+ vertical
618
+ ? { width: THUMB_SIZE + 16, opacity: ready ? 1 : 0 }
619
+ : { height: THUMB_SIZE + 16, opacity: ready ? 1 : 0 }
620
+ }
560
621
  onPointerDown={handlePointerDown}
561
622
  onPointerMove={handlePointerMove}
562
623
  onPointerUp={handlePointerUp}
@@ -564,8 +625,8 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
564
625
  >
565
626
  {/* The hit area reaches 8px past each end. */}
566
627
  <div
567
- className="absolute cursor-ew-resize"
568
- style={{ left: -8, right: -8, top: 0, bottom: 0 }}
628
+ className={cn('absolute', vertical ? 'cursor-ns-resize' : 'cursor-ew-resize')}
629
+ style={vertical ? { left: 0, right: 0, top: -8, bottom: -8 } : { left: -8, right: -8, top: 0, bottom: 0 }}
569
630
  onPointerDown={handlePointerDown}
570
631
  onPointerMove={handlePointerMove}
571
632
  onPointerUp={handlePointerUp}
@@ -575,15 +636,20 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
575
636
  {hoverPreview && showHoverTooltip && !isPressed && valuePosition !== 'tooltip' && (
576
637
  <motion.div
577
638
  key="hover-tooltip"
578
- className="absolute -translate-x-1/2 pointer-events-none z-20"
579
- initial={{ opacity: 0, y: 4 }}
580
- animate={{ opacity: 1, y: 0 }}
581
- exit={{ opacity: 0, y: 4, transition: spring.fast.exit }}
639
+ className={cn('absolute pointer-events-none z-20', vertical ? 'translate-y-1/2' : '-translate-x-1/2')}
640
+ initial={vertical ? { opacity: 0, x: -4 } : { opacity: 0, y: 4 }}
641
+ animate={vertical ? { opacity: 1, x: 0 } : { opacity: 1, y: 0 }}
642
+ exit={
643
+ vertical
644
+ ? { opacity: 0, x: -4, transition: spring.fast.exit }
645
+ : { opacity: 0, y: 4, transition: spring.fast.exit }
646
+ }
582
647
  transition={spring.fast}
583
- style={{
584
- left: hoverPreview.cursorX,
585
- top: -20,
586
- }}
648
+ style={
649
+ vertical
650
+ ? { bottom: hoverPreview.cursorX, left: 'calc(100% + 4px)' }
651
+ : { left: hoverPreview.cursorX, top: -20 }
652
+ }
587
653
  >
588
654
  <ValueBubble>{formatValue(hoverPreview.snappedValue)}</ValueBubble>
589
655
  </motion.div>
@@ -596,30 +662,33 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
596
662
  trackClassName,
597
663
  )}
598
664
  initial={false}
599
- animate={{
600
- height: TRACK_BG_HEIGHT,
601
- top: 8 + (THUMB_SIZE - TRACK_BG_HEIGHT) / 2,
602
- }}
665
+ animate={
666
+ vertical
667
+ ? { width: TRACK_BG_HEIGHT, left: 8 + (THUMB_SIZE - TRACK_BG_HEIGHT) / 2 }
668
+ : { height: TRACK_BG_HEIGHT, top: 8 + (THUMB_SIZE - TRACK_BG_HEIGHT) / 2 }
669
+ }
603
670
  transition={spring.fast}
604
671
  style={{
605
- left: TRACK_INSET,
606
- right: TRACK_INSET,
672
+ ...(vertical ? { top: TRACK_INSET, bottom: TRACK_INSET } : { left: TRACK_INSET, right: TRACK_INSET }),
607
673
  ...trackStyle,
608
674
  }}
609
675
  >
610
676
  {!hideFill && (
611
677
  <motion.div
612
- className={cn('absolute h-full bg-selected/50 dark:bg-accent/40', fillClassName)}
678
+ className={cn(
679
+ 'absolute bg-selected/50 dark:bg-accent/40',
680
+ vertical ? 'w-full' : 'h-full',
681
+ fillClassName,
682
+ )}
613
683
  style={{
614
- left: fillLeft,
615
- width: fillWidth,
684
+ ...(vertical ? { bottom: fillLeft, height: fillWidth } : { left: fillLeft, width: fillWidth }),
616
685
  ...fillStyle,
617
686
  }}
618
687
  />
619
688
  )}
620
689
 
621
690
  <motion.div
622
- className="absolute h-full bg-accent/40 pointer-events-none z-[2]"
691
+ className={cn('absolute bg-accent/40 pointer-events-none z-[2]', vertical ? 'w-full' : 'h-full')}
623
692
  initial={false}
624
693
  animate={{
625
694
  opacity: hoverPreview && !isPressed ? 1 : 0,
@@ -628,22 +697,34 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
628
697
  opacity: { duration: 0.15 },
629
698
  }}
630
699
  style={{
631
- left: hoverPreview ? hoverPreview.left - TRACK_INSET : 0,
632
- width: hoverPreview ? hoverPreview.width : 0,
700
+ ...(vertical
701
+ ? {
702
+ bottom: hoverPreview ? hoverPreview.left - TRACK_INSET : 0,
703
+ height: hoverPreview ? hoverPreview.width : 0,
704
+ }
705
+ : {
706
+ left: hoverPreview ? hoverPreview.left - TRACK_INSET : 0,
707
+ width: hoverPreview ? hoverPreview.width : 0,
708
+ }),
633
709
  borderRadius:
634
710
  hoverPreview && hoverPreview.cursorX > hoverPreview.left
635
- ? '0 9999px 9999px 0'
636
- : '9999px 0 0 9999px',
711
+ ? vertical
712
+ ? '9999px 9999px 0 0'
713
+ : '0 9999px 9999px 0'
714
+ : vertical
715
+ ? '0 0 9999px 9999px'
716
+ : '9999px 0 0 9999px',
637
717
  }}
638
718
  />
639
719
  </motion.div>
640
720
 
641
721
  {stepDots.length > 0 && (
642
722
  <motion.div
643
- className="absolute left-0 right-0 pointer-events-none"
723
+ className={cn('absolute pointer-events-none', vertical ? 'top-0 bottom-0' : 'left-0 right-0')}
644
724
  style={{
645
- top: 8 + (THUMB_SIZE - TRACK_BG_HEIGHT) / 2,
646
- height: TRACK_BG_HEIGHT,
725
+ ...(vertical
726
+ ? { left: 8 + (THUMB_SIZE - TRACK_BG_HEIGHT) / 2, width: TRACK_BG_HEIGHT }
727
+ : { top: 8 + (THUMB_SIZE - TRACK_BG_HEIGHT) / 2, height: TRACK_BG_HEIGHT }),
647
728
  WebkitMaskImage: stepDotsMask,
648
729
  maskImage: stepDotsMask,
649
730
  }}
@@ -653,8 +734,9 @@ const CompactSlider = forwardRef<HTMLDivElement, SliderEngineProps>(
653
734
  key={v}
654
735
  className="absolute pointer-events-none flex items-center justify-center"
655
736
  style={{
656
- left: `calc(${THUMB_SIZE / 2}px + ${percent} * (100% - ${THUMB_SIZE}px))`,
657
- top: '50%',
737
+ ...(vertical
738
+ ? { bottom: `calc(${THUMB_SIZE / 2}px + ${percent} * (100% - ${THUMB_SIZE}px))`, left: '50%' }
739
+ : { left: `calc(${THUMB_SIZE / 2}px + ${percent} * (100% - ${THUMB_SIZE}px))`, top: '50%' }),
658
740
  width: 0,
659
741
  height: 0,
660
742
  }}
@@ -125,3 +125,27 @@ The same dimming and inert behaviour on the default step.
125
125
  <div className="w-72">
126
126
  <Slider size="default" label="Roundness" defaultValue={2} min={0} max={4} disabled />
127
127
  </div>
128
+
129
+ # Vertical
130
+
131
+ `orientation="vertical"` stands the track upright: min at the bottom, max at the top, ArrowUp or ArrowRight to raise and ArrowDown or ArrowLeft to lower. It always renders the dense design, takes its height from `className`, and puts the value on top unless `valuePosition` says otherwise.
132
+
133
+ <div className="flex items-center gap-10">
134
+ <Slider orientation="vertical" label="Volume" defaultValue={40} className="h-48" />
135
+ <Slider orientation="vertical" label="Range" defaultValue={[20, 70]} className="h-48" />
136
+ <Slider orientation="vertical" label="Level" defaultValue={50} step={25} showSteps valuePosition="bottom" className="h-48" />
137
+ <Slider orientation="vertical" label="Gain" defaultValue={60} valuePosition="tooltip" className="h-48" />
138
+ </div>
139
+
140
+ # Commit
141
+
142
+ `onValueCommit` fires once when an interaction ends: the pointer lifting after a drag or click, a keyboard step, or a committed edit of the value. `onValueChange` reports every value on the way, so preview from `onValueChange` and save from `onValueCommit`.
143
+
144
+ ```tsx
145
+ <Slider
146
+ label="Volume"
147
+ defaultValue={40}
148
+ onValueChange={value => preview(value)}
149
+ onValueCommit={value => save(value)}
150
+ />
151
+ ```
@@ -62,15 +62,27 @@ export function toRadixValue(value: SliderValue): number[] {
62
62
  return Array.isArray(value) ? value : [value]
63
63
  }
64
64
 
65
+ /** The element's length along the slider's axis, in layout pixels. */
66
+ export function axisLength(el: HTMLElement, vertical = false): number {
67
+ return vertical ? el.offsetHeight : el.offsetWidth
68
+ }
69
+
65
70
  /**
66
- * The pointer's x inside `el` in layout pixels (offsetWidth space), so the
67
- * geometry holds under an ancestor's CSS scale (the canvas). `null` while
68
- * `el` has no width.
71
+ * The pointer's distance from the min end of `el` (its left edge, or its
72
+ * bottom edge when `vertical`) in layout pixels (offsetWidth / offsetHeight
73
+ * space), so the geometry holds under an ancestor's CSS scale (the canvas).
74
+ * `null` while `el` has no length.
69
75
  */
70
- export function layoutX(clientX: number, el: HTMLElement): number | null {
76
+ export function layoutPos(
77
+ { clientX, clientY }: { clientX: number; clientY: number },
78
+ el: HTMLElement,
79
+ vertical = false,
80
+ ): number | null {
71
81
  const rect = el.getBoundingClientRect()
72
- if (el.offsetWidth <= 0 || rect.width <= 0) return null
73
- return (clientX - rect.left) * (el.offsetWidth / rect.width)
82
+ const length = axisLength(el, vertical)
83
+ const visual = vertical ? rect.height : rect.width
84
+ if (length <= 0 || visual <= 0) return null
85
+ return (vertical ? rect.bottom - clientY : clientX - rect.left) * (length / visual)
74
86
  }
75
87
 
76
88
  /** `flag`, turning on only after it has held for `delay` ms (off at once). */
@@ -8,7 +8,7 @@
8
8
 
9
9
  'use client'
10
10
 
11
- import { forwardRef } from 'react'
11
+ import { forwardRef, useRef } from 'react'
12
12
  import { type SizeVariant, useSizeVariant } from '../../../lib/size-context'
13
13
  import { useControllableState } from '../../../lib/use-controllable-state'
14
14
  import { ComfortableSlider } from './comfortable'
@@ -30,7 +30,7 @@ const COMPACT_ONLY = [
30
30
  'thumbBorderColor',
31
31
  ] as const satisfies readonly (keyof SliderEngineProps)[]
32
32
 
33
- interface SliderProps extends Omit<SliderEngineProps, 'value' | 'onValueChange'> {
33
+ interface SliderProps extends Omit<SliderEngineProps, 'value' | 'onValueChange' | 'onCommit'> {
34
34
  /** Step on the size ladder (see Sizes). Default renders the pip/scrubber design; compact renders the dense design. Defaults to the surrounding SizeProvider, else `"default"`. */
35
35
  size?: SizeVariant
36
36
  /** Default-step layout. "pips" shows discrete dot indicators; "scrubber" drags anywhere in the row for a continuous value. Ignored when the compact design renders. Defaults to `"pips"`. */
@@ -41,6 +41,10 @@ interface SliderProps extends Omit<SliderEngineProps, 'value' | 'onValueChange'>
41
41
  defaultValue?: SliderValue
42
42
  /** Called when the value changes via drag, click, or keyboard. */
43
43
  onValueChange?: (value: SliderValue) => void
44
+ /** Called once when an interaction ends, with the value it settled on: the pointer lifting after a drag or click, a keyboard step, or a committed edit of the value label. `onValueChange` reports every value on the way, so save from here and preview from there. */
45
+ onValueCommit?: (value: SliderValue) => void
46
+ /** Layout axis. `"vertical"` stands the track upright (min at the bottom; ArrowUp / ArrowRight raise it, ArrowDown / ArrowLeft lower it) and always renders the compact design, which is the only one with a vertical layout. Give it a height with `className` (`h-48`); `valuePosition` then defaults to `"top"`. Defaults to `"horizontal"`. */
47
+ orientation?: 'horizontal' | 'vertical'
44
48
  /** Minimum value. Defaults to `0`. */
45
49
  min?: number
46
50
  /** Maximum value. Defaults to `100`. */
@@ -53,7 +57,7 @@ interface SliderProps extends Omit<SliderEngineProps, 'value' | 'onValueChange'>
53
57
  showSteps?: boolean
54
58
  /** Whether to display the current value label. Defaults to `true`. */
55
59
  showValue?: boolean
56
- /** Position of the value label. "tooltip" shows above the thumb during interaction. Defaults to `"left"`. */
60
+ /** Position of the value label. "tooltip" shows above the thumb during interaction (beside it when vertical). Defaults to `"left"`, or `"top"` when vertical. */
57
61
  valuePosition?: ValuePosition
58
62
  /** Custom formatter for the value label. Defaults to `String`. */
59
63
  formatValue?: (v: number) => string
@@ -79,7 +83,9 @@ interface SliderProps extends Omit<SliderEngineProps, 'value' | 'onValueChange'>
79
83
  * value label is click-to-edit.
80
84
  *
81
85
  * Works controlled (`value` + `onValueChange`) or uncontrolled
82
- * (`defaultValue`, with `onValueChange` reporting each change). Track
86
+ * (`defaultValue`, with `onValueChange` reporting each change);
87
+ * `onValueCommit` reports the value once an interaction ends.
88
+ * `orientation="vertical"` stands the dense design upright. Track
83
89
  * styling props come from the compact engine: `trackClassName`,
84
90
  * `trackStyle`, `fillClassName`, `fillStyle`, `hideFill`, `thumbColor` and
85
91
  * `thumbBorderColor` — each one also forces the dense design.
@@ -89,7 +95,7 @@ interface SliderProps extends Omit<SliderEngineProps, 'value' | 'onValueChange'>
89
95
  * @license MIT © 2026 Micka Touillaud
90
96
  */
91
97
  const Slider = forwardRef<HTMLDivElement, SliderProps>(
92
- ({ size, variant = 'pips', value: valueProp, defaultValue, onValueChange, ...rest }, ref) => {
98
+ ({ size, variant = 'pips', value: valueProp, defaultValue, onValueChange, onValueCommit, ...rest }, ref) => {
93
99
  const [value, setValue] = useControllableState<SliderValue>(
94
100
  valueProp,
95
101
  defaultValue ?? (rest.steps && rest.steps.length > 0 ? Math.min(...rest.steps) : (rest.min ?? 0)),
@@ -97,8 +103,22 @@ const Slider = forwardRef<HTMLDivElement, SliderProps>(
97
103
  )
98
104
  const resolved = useSizeVariant(size)
99
105
 
100
- if (resolved === 'compact' || Array.isArray(value) || COMPACT_ONLY.some(key => rest[key] !== undefined)) {
101
- return <CompactSlider ref={ref} {...rest} value={value} onValueChange={setValue} />
106
+ // A pointer can lift before the render that carries its last value, so the commit reads what was last set.
107
+ const latest = useRef(value)
108
+ latest.current = value
109
+ const change = (next: SliderValue) => {
110
+ latest.current = next
111
+ setValue(next)
112
+ }
113
+ const onCommit = onValueCommit && (() => onValueCommit(latest.current))
114
+
115
+ if (
116
+ resolved === 'compact' ||
117
+ Array.isArray(value) ||
118
+ rest.orientation === 'vertical' ||
119
+ COMPACT_ONLY.some(key => rest[key] !== undefined)
120
+ ) {
121
+ return <CompactSlider ref={ref} {...rest} value={value} onValueChange={change} onCommit={onCommit} />
102
122
  }
103
123
 
104
124
  const {
@@ -113,6 +133,7 @@ const Slider = forwardRef<HTMLDivElement, SliderProps>(
113
133
  hideFill,
114
134
  thumbColor,
115
135
  thumbBorderColor,
136
+ orientation,
116
137
  ...comfortable
117
138
  } = rest
118
139
 
@@ -121,7 +142,8 @@ const Slider = forwardRef<HTMLDivElement, SliderProps>(
121
142
  ref={ref}
122
143
  {...comfortable}
123
144
  value={value as number}
124
- onValueChange={setValue}
145
+ onValueChange={change}
146
+ onCommit={onCommit}
125
147
  variant={variant}
126
148
  />
127
149
  )
@@ -162,20 +162,27 @@ interface TooltipValueProps {
162
162
  value: number
163
163
  formatValue: (v: number) => string
164
164
  motionX: MotionValue<number>
165
+ vertical?: boolean
165
166
  }
166
167
 
167
- export function TooltipValue({ value, formatValue, motionX }: TooltipValueProps) {
168
+ export function TooltipValue({ value, formatValue, motionX, vertical = false }: TooltipValueProps) {
168
169
  const tooltipX = useTransform(motionX, x => x + THUMB_SIZE / 2)
170
+ const tooltipY = useTransform(motionX, x => -x)
169
171
  return (
170
172
  <motion.div
171
- className="absolute -translate-x-1/2 pointer-events-none z-20"
172
- style={{
173
- x: tooltipX,
174
- top: -16,
175
- }}
176
- initial={{ opacity: 0, y: 4 }}
177
- animate={{ opacity: 1, y: 0 }}
178
- exit={{ opacity: 0, y: 4, transition: spring.fast.exit }}
173
+ className={cn('absolute pointer-events-none z-20', vertical ? 'translate-y-1/2' : '-translate-x-1/2')}
174
+ style={
175
+ vertical
176
+ ? { y: tooltipY, bottom: THUMB_SIZE / 2, left: `calc(50% + ${THUMB_SIZE}px)` }
177
+ : { x: tooltipX, top: -16 }
178
+ }
179
+ initial={vertical ? { opacity: 0, x: -4 } : { opacity: 0, y: 4 }}
180
+ animate={vertical ? { opacity: 1, x: 0 } : { opacity: 1, y: 0 }}
181
+ exit={
182
+ vertical
183
+ ? { opacity: 0, x: -4, transition: spring.fast.exit }
184
+ : { opacity: 0, y: 4, transition: spring.fast.exit }
185
+ }
179
186
  transition={spring.fast}
180
187
  >
181
188
  <ValueBubble>{formatValue(value)}</ValueBubble>