@justanarthur/modo-ui 2.1.0 → 2.2.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.
- package/blocks/desktop-shell/index.tsx +2 -1
- package/components/inputs/checkbox/index.tsx +5 -0
- package/components/inputs/combobox/index.tsx +9 -4
- package/components/inputs/radio/index.tsx +5 -0
- package/components/inputs/select/index.tsx +23 -3
- package/components/inputs/slider/comfortable.tsx +10 -4
- package/components/inputs/slider/compact.tsx +153 -71
- package/components/inputs/slider/examples.mdx +24 -0
- package/components/inputs/slider/geometry.ts +18 -6
- package/components/inputs/slider/index.tsx +30 -8
- package/components/inputs/slider/value-display.tsx +16 -9
- package/components/inputs/switch/index.tsx +5 -0
- package/components/inputs/textarea/examples.mdx +19 -0
- package/components/inputs/textarea/index.tsx +42 -5
- package/components/navigation/sidebar/sidebar-group.tsx +2 -1
- package/components/navigation/sidebar/sidebar-menu-sub.tsx +2 -1
- package/components/navigation/sidebar/sidebar-shell.tsx +2 -1
- package/components/navigation/tree/index.tsx +2 -1
- package/components/overlays/dropdown/index.tsx +50 -8
- package/components/overlays/dropdown/submenu.tsx +41 -10
- package/components/overlays/tooltip/examples.mdx +13 -0
- package/components/overlays/tooltip/index.tsx +58 -16
- package/dist/blocks/desktop-shell/index.js +28 -27
- package/dist/blocks/sidebar-app/index.js +38 -37
- package/dist/components/actions/button/index.js +4 -4
- package/dist/components/actions/copy/index.js +12 -12
- package/dist/components/containers/accordion/index.d.ts +1 -1
- package/dist/components/containers/accordion/index.js +16 -16
- package/dist/components/containers/card/index.js +14 -14
- package/dist/components/data-display/avatar/index.js +3 -3
- package/dist/components/data-display/badge/index.js +2 -2
- package/dist/components/data-display/diff/index.js +4 -4
- package/dist/components/data-display/list/index.js +3 -3
- package/dist/components/data-display/log-view/index.js +8 -8
- package/dist/components/data-display/markdown/index.js +15 -15
- package/dist/components/data-display/table/index.js +9 -9
- package/dist/components/feedback/empty-state/index.js +3 -3
- package/dist/components/feedback/meter/index.js +2 -2
- package/dist/components/feedback/progress/index.js +2 -2
- package/dist/components/inputs/checkbox/index.d.ts +2 -0
- package/dist/components/inputs/checkbox/index.js +13 -13
- package/dist/components/inputs/choice-list/index.js +10 -10
- package/dist/components/inputs/color-picker/index.js +22 -22
- package/dist/components/inputs/combobox/index.d.ts +1 -1
- package/dist/components/inputs/combobox/index.js +21 -21
- package/dist/components/inputs/date-time/calendar/index.js +9 -9
- package/dist/components/inputs/date-time/date-picker/index.js +28 -28
- package/dist/components/inputs/date-time/date-range-picker/index.js +28 -28
- package/dist/components/inputs/date-time/duration-picker/index.js +27 -27
- package/dist/components/inputs/date-time/month-picker/index.js +26 -26
- package/dist/components/inputs/date-time/time-picker/index.js +27 -27
- package/dist/components/inputs/editable-text/index.js +2 -2
- package/dist/components/inputs/field/index.js +5 -5
- package/dist/components/inputs/file-dropzone/index.js +8 -8
- package/dist/components/inputs/input/index.js +6 -6
- package/dist/components/inputs/key-value/index.js +12 -12
- package/dist/components/inputs/number-input/index.js +7 -7
- package/dist/components/inputs/radio/index.d.ts +2 -0
- package/dist/components/inputs/radio/index.js +12 -12
- package/dist/components/inputs/search/index.js +23 -23
- package/dist/components/inputs/select/index.d.ts +22 -4
- package/dist/components/inputs/select/index.js +22 -22
- package/dist/components/inputs/slider/index.d.ts +12 -3
- package/dist/components/inputs/slider/index.js +4 -4
- package/dist/components/inputs/switch/index.d.ts +2 -0
- package/dist/components/inputs/switch/index.js +9 -9
- package/dist/components/inputs/textarea/index.d.ts +8 -1
- package/dist/components/inputs/textarea/index.js +4 -4
- package/dist/components/navigation/breadcrumb/index.js +25 -25
- package/dist/components/navigation/navigation-menu/index.js +17 -17
- package/dist/components/navigation/pagination/index.js +16 -16
- package/dist/components/navigation/sidebar/index.js +26 -25
- package/dist/components/navigation/tabs/index.js +13 -13
- package/dist/components/navigation/tree/index.js +10 -9
- package/dist/components/overlays/alert-dialog/index.d.ts +3 -3
- package/dist/components/overlays/alert-dialog/index.js +15 -15
- package/dist/components/overlays/command/index.d.ts +1 -1
- package/dist/components/overlays/command/index.js +21 -21
- package/dist/components/overlays/context-menu/index.d.ts +20 -1
- package/dist/components/overlays/context-menu/index.js +25 -25
- package/dist/components/overlays/dialog/index.d.ts +3 -3
- package/dist/components/overlays/dialog/index.js +14 -14
- package/dist/components/overlays/dropdown/index.d.ts +30 -8
- package/dist/components/overlays/dropdown/index.js +24 -24
- package/dist/components/overlays/lightbox/index.js +12 -12
- package/dist/components/overlays/popover/index.d.ts +6 -6
- package/dist/components/overlays/popover/index.js +11 -11
- package/dist/components/overlays/preview-card/index.js +10 -10
- package/dist/components/overlays/sheet/index.d.ts +3 -3
- package/dist/components/overlays/sheet/index.js +15 -15
- package/dist/components/overlays/toast/index.d.ts +1 -1
- package/dist/components/overlays/toast/index.js +11 -11
- package/dist/components/overlays/tooltip/index.d.ts +35 -10
- package/dist/components/overlays/tooltip/index.js +8 -8
- package/dist/docs/index.js +18 -17
- package/dist/index.d.ts +88 -36
- package/dist/index.js +78 -77
- package/dist/lib/fluid-hover-highlight.js +4 -4
- package/dist/lib/focus-ring.js +2 -2
- package/dist/lib/goo-indicator.js +3 -3
- package/dist/lib/inert.d.ts +7 -0
- package/dist/lib/inert.js +6 -0
- package/dist/lib/morph-layers.js +4 -4
- package/dist/lib/morph-part.js +2 -2
- package/dist/lib/overlay.d.ts +20 -13
- package/dist/lib/overlay.js +5 -4
- package/dist/lib/popup-rows.js +2 -2
- package/dist/lib/popup-surface.js +7 -7
- package/dist/lib/scroll-column.js +6 -6
- package/dist/lib/slot.d.ts +5 -2
- package/dist/lib/slot.js +1 -1
- package/dist/lib/use-merge-split.js +4 -4
- package/dist/lib/use-morph.js +2 -2
- package/dist/primitives/content/code/index.js +3 -3
- package/dist/primitives/layout/resizable/index.js +2 -2
- package/dist/primitives/layout/sortable/index.js +5 -5
- package/dist/primitives/systems/craft/index.js +3 -3
- package/dist/primitives/systems/fluid-hover/index.js +6 -6
- package/dist/primitives/systems/morph/index.js +14 -14
- package/dist/primitives/systems/motion/index.js +7 -7
- package/dist/primitives/systems/sizes/index.js +2 -2
- package/dist/shared/{components-280grw6q.js → components-09n5hgmx.js} +2 -2
- package/dist/shared/{components-1f3a7gmg.js → components-151vndgm.js} +3 -3
- package/dist/shared/{components-14wzcym0.js → components-16wx5av1.js} +6 -6
- package/dist/shared/{components-yf2gtq68.js → components-19e2wpxc.js} +9 -6
- package/dist/shared/{components-rzy6h7s4.js → components-1nqp7wqr.js} +1 -1
- package/dist/shared/components-2myjk2zf.js +8 -0
- package/dist/shared/{components-9rebr89j.js → components-2q0m4mxf.js} +2 -2
- package/dist/shared/{components-1asw2ph0.js → components-2zr49v82.js} +3 -3
- package/dist/shared/{components-wq9hrera.js → components-313rmbxy.js} +2 -2
- package/dist/shared/{components-0h2mng6m.js → components-31pkxwfz.js} +1 -1
- package/dist/shared/{components-w2at9ntm.js → components-3cvwrzc1.js} +3 -3
- package/dist/shared/{components-n0gbyp5a.js → components-4xd21p2p.js} +6 -6
- package/dist/shared/{components-t0c1rw40.js → components-7v6869ga.js} +1 -1
- package/dist/shared/{components-kwxye0an.js → components-7wjkag2j.js} +4 -2
- package/dist/shared/{components-fqsgd07c.js → components-85dz3xx3.js} +4 -4
- package/dist/shared/{components-3rvrdsa9.js → components-8qkd3659.js} +1 -1
- package/dist/shared/{components-me742146.js → components-8qwbwtv9.js} +5 -5
- package/dist/shared/{components-nxqrw789.js → components-90sfqz5t.js} +1 -1
- package/dist/shared/{components-b9bj65j3.js → components-90y8qwxv.js} +9 -9
- package/dist/shared/{components-g35n8tzm.js → components-95kp19zn.js} +1 -1
- package/dist/shared/{components-nhmgr5xc.js → components-9e5fpy3v.js} +14 -11
- package/dist/shared/{components-a1ms36qq.js → components-9hysh6d3.js} +1 -1
- package/dist/shared/{components-hcftn5r8.js → components-9s9vb2w0.js} +7 -4
- package/dist/shared/{components-vfreweq3.js → components-a3edrqpb.js} +3 -3
- package/dist/shared/{components-ee09xmkh.js → components-afj2ajea.js} +8 -5
- package/dist/shared/{components-ev0ytbqb.js → components-ajgwbabq.js} +4 -4
- package/dist/shared/{components-62510420.js → components-dr5c27yd.js} +6 -6
- package/dist/shared/{components-s90v3jpr.js → components-fqdh9ysk.js} +68 -19
- package/dist/shared/{components-2m2hg11x.js → components-gfw4zk8b.js} +8 -8
- package/dist/shared/{components-z0kz9rxj.js → components-gvwxswpr.js} +1 -1
- package/dist/shared/{components-p32aqk3q.js → components-h9se5cz5.js} +110 -73
- package/dist/shared/{components-77gxngmc.js → components-jd21f3mb.js} +8 -8
- package/dist/shared/{components-xnkc892z.js → components-mamtvenk.js} +2 -2
- package/dist/shared/{components-1hga6pkn.js → components-mcnyaaep.js} +3 -3
- package/dist/shared/{components-h0x2pj2y.js → components-mpx3yq5c.js} +24 -10
- package/dist/shared/{components-j79a6jqa.js → components-nc8wggew.js} +3 -3
- package/dist/shared/{components-r5q9gdh4.js → components-nd3f803g.js} +7 -7
- package/dist/shared/{components-9ca0c92a.js → components-nehs80xd.js} +1 -1
- package/dist/shared/{components-4t2cjav8.js → components-pgs3p035.js} +1 -1
- package/dist/shared/{components-91mmbrw3.js → components-ppc2dmxs.js} +2 -2
- package/dist/shared/{components-b2kjsn1s.js → components-qc1fae2s.js} +6 -6
- package/dist/shared/{components-fmyvz4r2.js → components-qd27dvgj.js} +6 -6
- package/dist/shared/{components-9z7bq8gn.js → components-qe8yp3vf.js} +3 -3
- package/dist/shared/{components-wx1dcp2n.js → components-qhk2m7fj.js} +2 -2
- package/dist/shared/{components-a1mwqxsv.js → components-qkt4h7x4.js} +8 -8
- package/dist/shared/{components-6rtawx8y.js → components-qs0cwe8p.js} +10 -10
- package/dist/shared/{components-y8m64zdw.js → components-r6ejdtpr.js} +3 -3
- package/dist/shared/{components-1bnf96sr.js → components-rj4nnqkz.js} +39 -11
- package/dist/shared/{components-gd8gmr6w.js → components-rmhdr4g1.js} +1 -1
- package/dist/shared/{components-e7zxwja1.js → components-rts2mggt.js} +1 -1
- package/dist/shared/{components-ta4e10mx.js → components-s25rehbv.js} +1 -1
- package/dist/shared/{components-chda6b23.js → components-sxstx1x7.js} +33 -4
- package/dist/shared/{components-b7p1pjcm.js → components-t4eb37vd.js} +2 -2
- package/dist/shared/{components-7xc2dne4.js → components-v3c3madd.js} +2 -2
- package/dist/shared/{components-22h8dvt1.js → components-v81eejq6.js} +3 -3
- package/dist/shared/{components-w1ysefg1.js → components-veaxns17.js} +2 -2
- package/dist/shared/{components-czvraaw9.js → components-vkrp4nb9.js} +4 -4
- package/dist/shared/{components-gsstwhtv.js → components-vv420geb.js} +6 -3
- package/dist/shared/{components-5xs8pkkj.js → components-w5p7mfb4.js} +1 -1
- package/dist/shared/{components-rgng034x.js → components-xvf8jcza.js} +25 -4
- package/dist/shared/{components-q7zk70tx.js → components-y07de1qv.js} +1 -1
- package/dist/shared/{components-0cpte6s1.js → components-yn8bw8tv.js} +11 -10
- package/dist/shared/{components-xa9fvd5b.js → components-z9gc2weg.js} +3 -3
- package/dist/shared/{components-twyj2y8c.js → components-zk1tj5za.js} +3 -3
- package/dist/shared/{components-hz6armxa.js → components-zktkxnzq.js} +7 -4
- package/dist/styles.css +5 -1
- package/lib/inert.ts +15 -0
- package/lib/overlay.tsx +49 -5
- package/lib/slot.tsx +9 -3
- package/package.json +6 -1
- /package/dist/shared/{components-jw45ck66.js → components-02683eqd.js} +0 -0
- /package/dist/shared/{components-q0hs5rqn.js → components-6c52v58g.js} +0 -0
- /package/dist/shared/{components-y4gsk1jt.js → components-fa61vwag.js} +0 -0
- /package/dist/shared/{components-nz14rwtd.js → components-ffng9rpa.js} +0 -0
- /package/dist/shared/{components-knryyjme.js → components-hbqyf35a.js} +0 -0
- /package/dist/shared/{components-7mj5wsv3.js → components-k9qbcmaa.js} +0 -0
- /package/dist/shared/{components-8pnvkrbw.js → components-mp7en54n.js} +0 -0
- /package/dist/shared/{components-h8v9nh5r.js → components-pbx77hzb.js} +0 -0
- /package/dist/shared/{components-c515d6xr.js → components-v1m0xjbw.js} +0 -0
- /package/dist/shared/{components-pa43g2r2.js → components-wddr0r6a.js} +0 -0
- /package/dist/shared/{components-ymq8tbq9.js → components-wqac4434.js} +0 -0
- /package/dist/shared/{components-m3vxpz2z.js → components-yy0a9b02.js} +0 -0
- /package/dist/shared/{components-92mvpt9h.js → components-zwgxvktt.js} +0 -0
|
@@ -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
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
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 =
|
|
288
|
+
const x = layoutPos(e, trackEl, vertical)
|
|
276
289
|
if (x === null) return
|
|
277
|
-
const layoutWidth = trackEl
|
|
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 =
|
|
326
|
+
const x = layoutPos(e, trackEl, vertical)
|
|
314
327
|
if (x === null) return
|
|
315
|
-
const layoutWidth = trackEl
|
|
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
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
|
471
|
-
|
|
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=
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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 =
|
|
539
|
+
const x = layoutPos(e, trackEl, vertical)
|
|
498
540
|
if (x === null) return
|
|
499
|
-
|
|
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
|
|
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
|
|
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=
|
|
559
|
-
style={
|
|
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=
|
|
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=
|
|
579
|
-
initial={{ opacity: 0, y: 4 }}
|
|
580
|
-
animate={{ opacity: 1, y: 0 }}
|
|
581
|
-
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
|
-
|
|
585
|
-
|
|
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
|
-
|
|
601
|
-
|
|
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(
|
|
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=
|
|
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
|
-
|
|
632
|
-
|
|
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
|
-
?
|
|
636
|
-
|
|
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=
|
|
723
|
+
className={cn('absolute pointer-events-none', vertical ? 'top-0 bottom-0' : 'left-0 right-0')}
|
|
644
724
|
style={{
|
|
645
|
-
|
|
646
|
-
|
|
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
|
-
|
|
657
|
-
|
|
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
|
|
67
|
-
*
|
|
68
|
-
*
|
|
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
|
|
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
|
-
|
|
73
|
-
|
|
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)
|
|
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
|
-
|
|
101
|
-
|
|
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={
|
|
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=
|
|
172
|
-
style={
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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>
|