@galaxy-io/dls 2.11.0 → 2.11.2
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.
|
@@ -29,7 +29,11 @@ export type SliderInputRange = [low: number, high: number];
|
|
|
29
29
|
export interface SliderInputMark {
|
|
30
30
|
/** Position on the rail, in value units. */
|
|
31
31
|
value: number;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Text under the tick. Never drawn outside the slider: the label of a mark at `min` is
|
|
34
|
+
* start-aligned, at `max` end-aligned, and any other is centered on its tick and shifted inward
|
|
35
|
+
* when it would cross an edge. Omit for an unlabeled tick.
|
|
36
|
+
*/
|
|
33
37
|
label?: string;
|
|
34
38
|
}
|
|
35
39
|
/** Every prop except the value quartet; exported as a helper type. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect.js";
|
|
1
2
|
import { Placement } from "../theme/enums.js";
|
|
2
3
|
import Text, { TextSize, TextVariant } from "../text/Text.js";
|
|
3
4
|
import { useControlledState } from "../hooks/useControlledState.js";
|
|
@@ -7,6 +8,7 @@ import { isFilled } from "./internal/predicates.js";
|
|
|
7
8
|
import { useFieldWiring } from "./internal/fieldWiring.js";
|
|
8
9
|
import Field, { FieldSize } from "./Field.js";
|
|
9
10
|
import { useOwnField } from "./internal/ownField.js";
|
|
11
|
+
import { SliderMarkAlign, inRangeMarksOf, markAlignOf, markFractionOf, markLabelShiftOf } from "./internal/sliderMarks.js";
|
|
10
12
|
/* empty css */
|
|
11
13
|
import { styled } from "@linaria/react";
|
|
12
14
|
import { forwardRef, useRef, useState } from "react";
|
|
@@ -61,7 +63,14 @@ function decimalsOf(number) {
|
|
|
61
63
|
const fraction = mantissa.split(".")[1]?.length ?? 0;
|
|
62
64
|
return Math.max(0, fraction - (exponent === void 0 ? 0 : Number(exponent)));
|
|
63
65
|
}
|
|
64
|
-
/**
|
|
66
|
+
/** Whether an element lays out right to left (`dir="rtl"` on it or an ancestor). */
|
|
67
|
+
function isRtl(element) {
|
|
68
|
+
return element.ownerDocument.defaultView?.getComputedStyle(element).direction === "rtl";
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A position along the track for a fraction custom property: half a thumb in at each end. Every
|
|
72
|
+
* position is an `inset-inline-start`, so the slider mirrors under `dir="rtl"`.
|
|
73
|
+
*/
|
|
65
74
|
/** The root: the track, then the mark labels. */
|
|
66
75
|
var Slider = /*#__PURE__*/ styled("div")({
|
|
67
76
|
name: "Slider",
|
|
@@ -86,57 +95,74 @@ var Fill = /*#__PURE__*/ styled("span")({
|
|
|
86
95
|
class: "gx-SliderInput-Fill-falrebx",
|
|
87
96
|
propsAsIs: false
|
|
88
97
|
});
|
|
89
|
-
/** A 2px dot on the rail. */
|
|
98
|
+
/** A 2px dot on the rail, centered on its position. */
|
|
90
99
|
var Tick = /*#__PURE__*/ styled("span")({
|
|
91
100
|
name: "Tick",
|
|
92
101
|
class: "gx-SliderInput-Tick-t1trli0w",
|
|
93
102
|
propsAsIs: false
|
|
94
103
|
});
|
|
95
|
-
/** A thumb: the focusable `role="slider"` element. */
|
|
104
|
+
/** A thumb: the focusable `role="slider"` element, centered on its position. */
|
|
96
105
|
var Thumb = /*#__PURE__*/ styled("span")({
|
|
97
106
|
name: "Thumb",
|
|
98
107
|
class: "gx-SliderInput-Thumb-t1vqwgc8",
|
|
99
108
|
propsAsIs: false
|
|
100
109
|
});
|
|
101
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* The labels row under the track, as wide as the track. It does not clip: every label is placed
|
|
112
|
+
* inside it (`SLIDER_MARK_ALIGN_TO_CSS_MAP`).
|
|
113
|
+
*/
|
|
102
114
|
var MarkLabels = /*#__PURE__*/ styled("div")({
|
|
103
115
|
name: "MarkLabels",
|
|
104
116
|
class: "gx-SliderInput-MarkLabels-m1i23o1h",
|
|
105
117
|
propsAsIs: false
|
|
106
118
|
});
|
|
107
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* One mark label, aligned by `SLIDER_MARK_ALIGN_TO_CSS_MAP`. A flex box, so its height is the
|
|
121
|
+
* text's line height and not a taller mixed-font line box.
|
|
122
|
+
*/
|
|
108
123
|
var MarkLabel = /*#__PURE__*/ styled("span")({
|
|
109
124
|
name: "MarkLabel",
|
|
110
125
|
class: "gx-SliderInput-MarkLabel-m14axfe1",
|
|
111
126
|
propsAsIs: false
|
|
112
127
|
});
|
|
128
|
+
/**
|
|
129
|
+
* A mark label never renders outside the slider's inline bounds. The mark at `min` sits on the
|
|
130
|
+
* track's start edge, the mark at `max` on its end edge. Any other is centered on its tick and
|
|
131
|
+
* moved inward by `--gx-slider-mark-shift`, which the layout effect measures and sets only on a
|
|
132
|
+
* label that would cross an edge. Logical insets, so `dir="rtl"` mirrors all three.
|
|
133
|
+
*/
|
|
134
|
+
var SLIDER_MARK_ALIGN_TO_CSS_MAP = {
|
|
135
|
+
[SliderMarkAlign.START]: "gx-SliderInput-SliderMarkAlign_START-sudygu0",
|
|
136
|
+
[SliderMarkAlign.CENTER]: "gx-SliderInput-SliderMarkAlign_CENTER-sftu20f",
|
|
137
|
+
[SliderMarkAlign.END]: "gx-SliderInput-SliderMarkAlign_END-si8xoiz"
|
|
138
|
+
};
|
|
113
139
|
/** Range: the fill runs between the two thumbs. */
|
|
114
|
-
var FILL_RANGE_CSS = "gx-SliderInput-FILL_RANGE_CSS-
|
|
115
|
-
/** The low thumb's position
|
|
116
|
-
var THUMB_LOW_CSS = "gx-SliderInput-THUMB_LOW_CSS-
|
|
140
|
+
var FILL_RANGE_CSS = "gx-SliderInput-FILL_RANGE_CSS-f1a78r92";
|
|
141
|
+
/** The low thumb's position: its start edge, so the thumb's center is on `positionOf`. */
|
|
142
|
+
var THUMB_LOW_CSS = "gx-SliderInput-THUMB_LOW_CSS-t12egp3k";
|
|
117
143
|
/** The high (or only) thumb's position. */
|
|
118
|
-
var THUMB_HIGH_CSS = "gx-SliderInput-THUMB_HIGH_CSS-
|
|
144
|
+
var THUMB_HIGH_CSS = "gx-SliderInput-THUMB_HIGH_CSS-tbdzcws";
|
|
119
145
|
/** A tick on the filled span stays visible on the fill. */
|
|
120
|
-
var TICK_FILLED_CSS = "gx-SliderInput-TICK_FILLED_CSS-
|
|
146
|
+
var TICK_FILLED_CSS = "gx-SliderInput-TICK_FILLED_CSS-t8thtvu";
|
|
121
147
|
/** The thumb being dragged. */
|
|
122
|
-
var DRAGGING_CSS = "gx-SliderInput-DRAGGING_CSS-
|
|
148
|
+
var DRAGGING_CSS = "gx-SliderInput-DRAGGING_CSS-d1ub36fq";
|
|
123
149
|
/** Track, rail and thumb sizes per rung; every value is even, so both center on whole pixels. */
|
|
124
150
|
var SLIDER_INPUT_SIZE_TO_CSS_MAP = {
|
|
125
|
-
["X_SMALL"]: "gx-SliderInput-X_SMALL-
|
|
126
|
-
["SMALL"]: "gx-SliderInput-SMALL-
|
|
127
|
-
["MEDIUM"]: "gx-SliderInput-MEDIUM-
|
|
128
|
-
["LARGE"]: "gx-SliderInput-LARGE-
|
|
129
|
-
["X_LARGE"]: "gx-SliderInput-X_LARGE-
|
|
151
|
+
["X_SMALL"]: "gx-SliderInput-X_SMALL-x1ebia5y",
|
|
152
|
+
["SMALL"]: "gx-SliderInput-SMALL-stm9yr7",
|
|
153
|
+
["MEDIUM"]: "gx-SliderInput-MEDIUM-m1eim1rd",
|
|
154
|
+
["LARGE"]: "gx-SliderInput-LARGE-lmdyvcs",
|
|
155
|
+
["X_LARGE"]: "gx-SliderInput-X_LARGE-xfme75x"
|
|
130
156
|
};
|
|
131
157
|
/** The unfilled rail per variant: the Input rest fills, with the hairline kept on every variant. */
|
|
132
158
|
var SLIDER_INPUT_VARIANT_TO_CSS_MAP = {
|
|
133
|
-
["BASE"]: "gx-SliderInput-BASE-
|
|
134
|
-
["PRIMARY"]: "gx-SliderInput-PRIMARY-
|
|
135
|
-
["SECONDARY"]: "gx-SliderInput-SECONDARY-
|
|
136
|
-
["TERTIARY"]: "gx-SliderInput-TERTIARY-
|
|
159
|
+
["BASE"]: "gx-SliderInput-BASE-bwnayei",
|
|
160
|
+
["PRIMARY"]: "gx-SliderInput-PRIMARY-p1nk0y5e",
|
|
161
|
+
["SECONDARY"]: "gx-SliderInput-SECONDARY-s18dfoic",
|
|
162
|
+
["TERTIARY"]: "gx-SliderInput-TERTIARY-tpqawlc"
|
|
137
163
|
};
|
|
138
164
|
/** `isGhost`: no rail fill, the hairline kept. Declared after the variant map, which it replaces. */
|
|
139
|
-
var GHOST_CSS = "gx-SliderInput-GHOST_CSS-
|
|
165
|
+
var GHOST_CSS = "gx-SliderInput-GHOST_CSS-g15bc6fe";
|
|
140
166
|
/** Mark labels per rung. */
|
|
141
167
|
var SLIDER_INPUT_SIZE_TO_MARK_TEXT_SIZE_MAP = {
|
|
142
168
|
["X_SMALL"]: TextSize.CAPTION,
|
|
@@ -157,18 +183,18 @@ var SLIDER_INPUT_SIZE_TO_FIELD_SIZE_MAP = {
|
|
|
157
183
|
* Hover on an editable slider: the rail hairline turns `border.hovered` (stronger than
|
|
158
184
|
* `border.primary` in both themes, Constitution III.6), as an input frame does.
|
|
159
185
|
*/
|
|
160
|
-
var HOVER_CSS = "gx-SliderInput-HOVER_CSS-
|
|
186
|
+
var HOVER_CSS = "gx-SliderInput-HOVER_CSS-h24kxar";
|
|
161
187
|
/** Error hairline on the rail, at rest and on hover. */
|
|
162
|
-
var ERROR_CSS = "gx-SliderInput-ERROR_CSS-
|
|
188
|
+
var ERROR_CSS = "gx-SliderInput-ERROR_CSS-ez4wyc9";
|
|
163
189
|
/**
|
|
164
190
|
* Disabled: the rail keeps its resting hairline (`border.disabled` is not used on frames); fill and
|
|
165
191
|
* thumbs turn `text.disabled`; nothing reacts to the pointer.
|
|
166
192
|
*/
|
|
167
|
-
var DISABLED_CSS = "gx-SliderInput-DISABLED_CSS-
|
|
193
|
+
var DISABLED_CSS = "gx-SliderInput-DISABLED_CSS-d19jglnp";
|
|
168
194
|
/** Read-only: focusable and announced, but nothing looks draggable. */
|
|
169
|
-
var READ_ONLY_CSS = "gx-SliderInput-READ_ONLY_CSS-
|
|
195
|
+
var READ_ONLY_CSS = "gx-SliderInput-READ_ONLY_CSS-r1qsjokj";
|
|
170
196
|
/** Stretch to the parent's width (slider, and the `Field` wrapper when there is one). */
|
|
171
|
-
var FILL_WIDTH_CSS = "gx-SliderInput-FILL_WIDTH_CSS-
|
|
197
|
+
var FILL_WIDTH_CSS = "gx-SliderInput-FILL_WIDTH_CSS-f6qh7n8";
|
|
172
198
|
/** The track, thumbs and marks, wired to the nearest Field (the slider's own or the app's). */
|
|
173
199
|
function SliderBody({ sliderProps, forwardedRef, isRoot }) {
|
|
174
200
|
const { isRange = false, value, defaultValue, onChange, onChangeEnd, min: minProp = 0, max: maxProp = 100, step: stepProp = 1, marks, formatValue = String, hasValueTooltip = false, size = "MEDIUM", variant = "PRIMARY", isGhost = false, label: _label, labelTooltip: _labelTooltip, description: _description, error, isError = false, isDisabled = false, isReadOnly = false, isRequired = false, fillWidth = false, ariaLabel, id, "aria-describedby": ariaDescribedBy, "aria-labelledby": ariaLabelledBy, "aria-label": ariaLabelAttribute, className, style, ...rest } = sliderProps;
|
|
@@ -228,14 +254,18 @@ function SliderBody({ sliderProps, forwardedRef, isRoot }) {
|
|
|
228
254
|
const endGesture = () => {
|
|
229
255
|
onChangeEnd?.(toPublic(valuesRef.current));
|
|
230
256
|
};
|
|
231
|
-
/**
|
|
257
|
+
/**
|
|
258
|
+
* The value under a pointer x, from the track box (minus half the thumb at each end). Under
|
|
259
|
+
* `dir="rtl"` the track runs from the right.
|
|
260
|
+
*/
|
|
232
261
|
const valueAt = (clientX) => {
|
|
233
262
|
const track = trackRef.current;
|
|
234
263
|
if (track === null) return min;
|
|
235
264
|
const box = track.getBoundingClientRect();
|
|
236
265
|
const thumb = thumbRefs.current[0]?.offsetWidth ?? 0;
|
|
237
266
|
const span = box.width - thumb;
|
|
238
|
-
const
|
|
267
|
+
const offset = isRtl(track) ? box.right - clientX : clientX - box.left;
|
|
268
|
+
const fraction = span <= 0 ? 0 : (offset - thumb / 2) / span;
|
|
239
269
|
return min + Math.min(1, Math.max(0, fraction)) * (max - min);
|
|
240
270
|
};
|
|
241
271
|
const handlePointerDown = (event) => {
|
|
@@ -297,13 +327,16 @@ function SliderBody({ sliderProps, forwardedRef, isRoot }) {
|
|
|
297
327
|
const current = valuesRef.current[index] ?? min;
|
|
298
328
|
const [low, high] = boundsOf(index);
|
|
299
329
|
const page = Math.max(step, (max - min) / 10);
|
|
330
|
+
const forward = isRtl(event.currentTarget) ? "ArrowLeft" : "ArrowRight";
|
|
300
331
|
let next;
|
|
301
332
|
switch (event.key) {
|
|
302
333
|
case "ArrowRight":
|
|
334
|
+
case "ArrowLeft":
|
|
335
|
+
next = event.key === forward ? current + step : current - step;
|
|
336
|
+
break;
|
|
303
337
|
case "ArrowUp":
|
|
304
338
|
next = current + step;
|
|
305
339
|
break;
|
|
306
|
-
case "ArrowLeft":
|
|
307
340
|
case "ArrowDown":
|
|
308
341
|
next = current - step;
|
|
309
342
|
break;
|
|
@@ -334,13 +367,57 @@ function SliderBody({ sliderProps, forwardedRef, isRoot }) {
|
|
|
334
367
|
const labelledBy = isFilled(ariaLabelledBy) ? ariaLabelledBy : field?.labelId;
|
|
335
368
|
const name = isFilled(ariaLabelAttribute) ? ariaLabelAttribute : ariaLabel;
|
|
336
369
|
useDevWarning(!hasName, "[@galaxy-io/dls] SliderInput has no accessible name. Pass `label`, wrap it in a labelled `Field`, or set `ariaLabel`.");
|
|
337
|
-
const
|
|
338
|
-
const fractionOf = (number) => span === 0 ? 0 : (number - min) / span;
|
|
370
|
+
const fractionOf = (number) => markFractionOf(number, min, max);
|
|
339
371
|
const low = values[0] ?? min;
|
|
340
372
|
const high = values[values.length - 1] ?? max;
|
|
341
|
-
const inRangeMarks = (marks
|
|
373
|
+
const inRangeMarks = inRangeMarksOf(marks, min, max);
|
|
342
374
|
const hasMarkLabels = inRangeMarks.some((mark) => isFilled(mark.label));
|
|
343
375
|
const isOnFill = (mark) => isRange ? mark >= low && mark <= high : mark <= high;
|
|
376
|
+
const markLabelsRef = useRef(null);
|
|
377
|
+
const markLabelRefs = useRef(/* @__PURE__ */ new Map());
|
|
378
|
+
useIsomorphicLayoutEffect(() => {
|
|
379
|
+
const row = markLabelsRef.current;
|
|
380
|
+
if (row === null) return;
|
|
381
|
+
let isCancelled = false;
|
|
382
|
+
const centered = inRangeMarks.flatMap((mark) => {
|
|
383
|
+
const fraction = markFractionOf(mark.value, min, max);
|
|
384
|
+
const element = markLabelRefs.current.get(mark.value);
|
|
385
|
+
return markAlignOf(fraction) === SliderMarkAlign.CENTER && element !== void 0 ? [{
|
|
386
|
+
fraction,
|
|
387
|
+
element
|
|
388
|
+
}] : [];
|
|
389
|
+
});
|
|
390
|
+
const update = () => {
|
|
391
|
+
if (isCancelled) return;
|
|
392
|
+
const trackWidth = row.getBoundingClientRect().width;
|
|
393
|
+
const thumbWidth = thumbRefs.current[0]?.offsetWidth ?? 0;
|
|
394
|
+
for (const { fraction, element } of centered) {
|
|
395
|
+
const labelWidth = element.getBoundingClientRect().width;
|
|
396
|
+
const shift = markLabelShiftOf({
|
|
397
|
+
fraction,
|
|
398
|
+
trackWidth,
|
|
399
|
+
thumbWidth,
|
|
400
|
+
labelWidth
|
|
401
|
+
});
|
|
402
|
+
if (shift === 0) element.style.removeProperty("--gx-slider-mark-shift");
|
|
403
|
+
else element.style.setProperty("--gx-slider-mark-shift", `${shift}px`);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
update();
|
|
407
|
+
const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
|
|
408
|
+
observer?.observe(row);
|
|
409
|
+
for (const { element } of centered) observer?.observe(element);
|
|
410
|
+
document.fonts?.ready.then(update);
|
|
411
|
+
return () => {
|
|
412
|
+
isCancelled = true;
|
|
413
|
+
observer?.disconnect();
|
|
414
|
+
};
|
|
415
|
+
}, [
|
|
416
|
+
inRangeMarks.map((mark) => `${mark.value}:${mark.label ?? ""}`).join("|"),
|
|
417
|
+
min,
|
|
418
|
+
max,
|
|
419
|
+
size
|
|
420
|
+
]);
|
|
344
421
|
const renderThumb = (index) => {
|
|
345
422
|
const thumbValue = values[index] ?? min;
|
|
346
423
|
const [thumbMin, thumbMax] = boundsOf(index, values);
|
|
@@ -411,17 +488,28 @@ function SliderBody({ sliderProps, forwardedRef, isRoot }) {
|
|
|
411
488
|
values.map((_, index) => renderThumb(index))
|
|
412
489
|
]
|
|
413
490
|
}), hasMarkLabels && /* @__PURE__ */ jsx(MarkLabels, {
|
|
491
|
+
ref: markLabelsRef,
|
|
414
492
|
"aria-hidden": true,
|
|
415
|
-
children: inRangeMarks.map((mark) =>
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
493
|
+
children: inRangeMarks.map((mark) => {
|
|
494
|
+
if (!isFilled(mark.label)) return null;
|
|
495
|
+
const align = markAlignOf(fractionOf(mark.value));
|
|
496
|
+
return /* @__PURE__ */ jsx(MarkLabel, {
|
|
497
|
+
ref: (element) => {
|
|
498
|
+
if (element === null) markLabelRefs.current.delete(mark.value);
|
|
499
|
+
else markLabelRefs.current.set(mark.value, element);
|
|
500
|
+
},
|
|
501
|
+
"data-align": align.toLowerCase(),
|
|
502
|
+
className: SLIDER_MARK_ALIGN_TO_CSS_MAP[align],
|
|
503
|
+
style: { "--gx-slider-mark": fractionOf(mark.value) },
|
|
504
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
505
|
+
as: "span",
|
|
506
|
+
size: SLIDER_INPUT_SIZE_TO_MARK_TEXT_SIZE_MAP[size],
|
|
507
|
+
variant: isDisabled ? TextVariant.DISABLED : TextVariant.TERTIARY,
|
|
508
|
+
isTabular: true,
|
|
509
|
+
children: mark.label
|
|
510
|
+
})
|
|
511
|
+
}, mark.value);
|
|
512
|
+
})
|
|
425
513
|
})]
|
|
426
514
|
});
|
|
427
515
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mark-label geometry for `SliderInput`. A mark label never renders outside the slider's inline
|
|
3
|
+
* bounds: a mark at `min` is start-aligned, a mark at `max` is end-aligned, and every other mark is
|
|
4
|
+
* centered on its tick and shifted inward when centering would cross an edge.
|
|
5
|
+
*/
|
|
6
|
+
/** How a mark label sits against its tick; the label's `data-align` is the lowercase name. */
|
|
7
|
+
export declare enum SliderMarkAlign {
|
|
8
|
+
/** The label's start edge on the track's start edge: the mark at `min`. */
|
|
9
|
+
START = "START",
|
|
10
|
+
/** Centered on the tick, clamped inside the track. */
|
|
11
|
+
CENTER = "CENTER",
|
|
12
|
+
/** The label's end edge on the track's end edge: the mark at `max`. */
|
|
13
|
+
END = "END"
|
|
14
|
+
}
|
|
15
|
+
/** A mark's position on the track as a fraction of `[min, max]` (0 when `min === max`). */
|
|
16
|
+
export declare function markFractionOf(value: number, min: number, max: number): number;
|
|
17
|
+
/** Marks inside `[min, max]`; the rest are ignored. */
|
|
18
|
+
export declare function inRangeMarksOf<Mark extends {
|
|
19
|
+
value: number;
|
|
20
|
+
}>(marks: readonly Mark[] | undefined, min: number, max: number): Mark[];
|
|
21
|
+
/** The alignment of a mark label from its fraction: start at 0, end at 1, centered between. */
|
|
22
|
+
export declare function markAlignOf(fraction: number): SliderMarkAlign;
|
|
23
|
+
/** Inline sizes, in px, that place a centered mark label. */
|
|
24
|
+
export interface SliderMarkMeasure {
|
|
25
|
+
/** The mark's fraction of `[min, max]`. */
|
|
26
|
+
fraction: number;
|
|
27
|
+
/** Width of the labels row (the track's width). */
|
|
28
|
+
trackWidth: number;
|
|
29
|
+
/** Width of a thumb; tick centers run from half a thumb in at each end. */
|
|
30
|
+
thumbWidth: number;
|
|
31
|
+
/** Width of the label. */
|
|
32
|
+
labelWidth: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The inward shift, in px toward the inline end, that keeps a centered label inside the track:
|
|
36
|
+
* `0` when the centered label already fits. A label wider than the track is start-aligned.
|
|
37
|
+
*/
|
|
38
|
+
export declare function markLabelShiftOf({ fraction, trackWidth, thumbWidth, labelWidth, }: SliderMarkMeasure): number;
|
|
39
|
+
/** The label's inline `[start, end]` offsets within the track, in px, after alignment and shift. */
|
|
40
|
+
export declare function markLabelBoxOf(align: SliderMarkAlign, measure: SliderMarkMeasure): [start: number, end: number];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/inputs/internal/sliderMarks.ts
|
|
2
|
+
/**
|
|
3
|
+
* Mark-label geometry for `SliderInput`. A mark label never renders outside the slider's inline
|
|
4
|
+
* bounds: a mark at `min` is start-aligned, a mark at `max` is end-aligned, and every other mark is
|
|
5
|
+
* centered on its tick and shifted inward when centering would cross an edge.
|
|
6
|
+
*/
|
|
7
|
+
/** How a mark label sits against its tick; the label's `data-align` is the lowercase name. */
|
|
8
|
+
var SliderMarkAlign = /* @__PURE__ */ function(SliderMarkAlign) {
|
|
9
|
+
/** The label's start edge on the track's start edge: the mark at `min`. */
|
|
10
|
+
SliderMarkAlign["START"] = "START";
|
|
11
|
+
/** Centered on the tick, clamped inside the track. */
|
|
12
|
+
SliderMarkAlign["CENTER"] = "CENTER";
|
|
13
|
+
/** The label's end edge on the track's end edge: the mark at `max`. */
|
|
14
|
+
SliderMarkAlign["END"] = "END";
|
|
15
|
+
return SliderMarkAlign;
|
|
16
|
+
}({});
|
|
17
|
+
/** A mark's position on the track as a fraction of `[min, max]` (0 when `min === max`). */
|
|
18
|
+
function markFractionOf(value, min, max) {
|
|
19
|
+
const span = max - min;
|
|
20
|
+
return span === 0 ? 0 : (value - min) / span;
|
|
21
|
+
}
|
|
22
|
+
/** Marks inside `[min, max]`; the rest are ignored. */
|
|
23
|
+
function inRangeMarksOf(marks, min, max) {
|
|
24
|
+
return (marks ?? []).filter((mark) => mark.value >= min && mark.value <= max);
|
|
25
|
+
}
|
|
26
|
+
/** The alignment of a mark label from its fraction: start at 0, end at 1, centered between. */
|
|
27
|
+
function markAlignOf(fraction) {
|
|
28
|
+
if (fraction <= 0) return "START";
|
|
29
|
+
if (fraction >= 1) return "END";
|
|
30
|
+
return "CENTER";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The inward shift, in px toward the inline end, that keeps a centered label inside the track:
|
|
34
|
+
* `0` when the centered label already fits. A label wider than the track is start-aligned.
|
|
35
|
+
*/
|
|
36
|
+
function markLabelShiftOf({ fraction, trackWidth, thumbWidth, labelWidth }) {
|
|
37
|
+
const start = thumbWidth / 2 + fraction * (trackWidth - thumbWidth) - labelWidth / 2;
|
|
38
|
+
return Math.min(Math.max(start, 0), Math.max(0, trackWidth - labelWidth)) - start;
|
|
39
|
+
}
|
|
40
|
+
/** The label's inline `[start, end]` offsets within the track, in px, after alignment and shift. */
|
|
41
|
+
function markLabelBoxOf(align, measure) {
|
|
42
|
+
const { fraction, trackWidth, thumbWidth, labelWidth } = measure;
|
|
43
|
+
if (align === "START") return [0, labelWidth];
|
|
44
|
+
if (align === "END") return [trackWidth - labelWidth, trackWidth];
|
|
45
|
+
const start = thumbWidth / 2 + fraction * (trackWidth - thumbWidth) - labelWidth / 2 + markLabelShiftOf(measure);
|
|
46
|
+
return [start, start + labelWidth];
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { SliderMarkAlign, inRangeMarksOf, markAlignOf, markFractionOf, markLabelBoxOf, markLabelShiftOf };
|
|
@@ -49,10 +49,19 @@ var SCROLL_AREA_ORIENTATION_TO_SCROLLBAR_CSS_MAP = {
|
|
|
49
49
|
[Orientation.VERTICAL]: "gx-ScrollArea-Orientation_VERTICAL-o174c7co",
|
|
50
50
|
[Orientation.HORIZONTAL]: "gx-ScrollArea-Orientation_HORIZONTAL-okpbxfy"
|
|
51
51
|
};
|
|
52
|
-
/** The 4px thumb, a quiet neutral on every surface
|
|
52
|
+
/** The 4px thumb, a quiet neutral on every surface. */
|
|
53
53
|
var THUMB_CSS = "gx-ScrollArea-THUMB_CSS-tzpebzb";
|
|
54
|
+
/**
|
|
55
|
+
* The thumb's 24px pointer target (`::before`), anchored to the track's outer edge (the root's
|
|
56
|
+
* edge) and growing inward over the content, so it never leaves the root and never adds overflow to
|
|
57
|
+
* a scrolling parent. Along the track it matches the thumb.
|
|
58
|
+
*/
|
|
59
|
+
var SCROLL_AREA_ORIENTATION_TO_THUMB_CSS_MAP = {
|
|
60
|
+
[Orientation.VERTICAL]: "gx-ScrollArea-Orientation_VERTICAL-o1otan2y",
|
|
61
|
+
[Orientation.HORIZONTAL]: "gx-ScrollArea-Orientation_HORIZONTAL-o1rdgqrq"
|
|
62
|
+
};
|
|
54
63
|
/** Where the two scrollbars meet. */
|
|
55
|
-
var CORNER_CSS = "gx-ScrollArea-CORNER_CSS-
|
|
64
|
+
var CORNER_CSS = "gx-ScrollArea-CORNER_CSS-c1pufd3e";
|
|
56
65
|
/** Reads the viewport's scroll geometry into edge flags. */
|
|
57
66
|
function measureEdges(viewport, canScrollHorizontally) {
|
|
58
67
|
const { scrollTop, scrollHeight, clientHeight, scrollWidth, clientWidth } = viewport;
|
|
@@ -122,12 +131,12 @@ var ScrollArea = forwardRef(function ScrollArea({ children, canScrollHorizontall
|
|
|
122
131
|
/* @__PURE__ */ jsx(ScrollAreaPrimitive.Scrollbar, {
|
|
123
132
|
orientation: "vertical",
|
|
124
133
|
className: SCROLL_AREA_ORIENTATION_TO_SCROLLBAR_CSS_MAP[Orientation.VERTICAL],
|
|
125
|
-
children: /* @__PURE__ */ jsx(ScrollAreaPrimitive.Thumb, { className: THUMB_CSS })
|
|
134
|
+
children: /* @__PURE__ */ jsx(ScrollAreaPrimitive.Thumb, { className: cx(THUMB_CSS, SCROLL_AREA_ORIENTATION_TO_THUMB_CSS_MAP[Orientation.VERTICAL]) })
|
|
126
135
|
}),
|
|
127
136
|
canScrollHorizontally && /* @__PURE__ */ jsx(ScrollAreaPrimitive.Scrollbar, {
|
|
128
137
|
orientation: "horizontal",
|
|
129
138
|
className: SCROLL_AREA_ORIENTATION_TO_SCROLLBAR_CSS_MAP[Orientation.HORIZONTAL],
|
|
130
|
-
children: /* @__PURE__ */ jsx(ScrollAreaPrimitive.Thumb, { className: THUMB_CSS })
|
|
139
|
+
children: /* @__PURE__ */ jsx(ScrollAreaPrimitive.Thumb, { className: cx(THUMB_CSS, SCROLL_AREA_ORIENTATION_TO_THUMB_CSS_MAP[Orientation.HORIZONTAL]) })
|
|
131
140
|
}),
|
|
132
141
|
canScrollHorizontally && /* @__PURE__ */ jsx(ScrollAreaPrimitive.Corner, { className: CORNER_CSS })
|
|
133
142
|
]
|