@galaxy-io/dls 2.11.1 → 2.12.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/dist/inputs/SliderInput.d.ts +5 -1
- package/dist/inputs/SliderInput.js +130 -42
- package/dist/inputs/internal/sliderMarks.d.ts +40 -0
- package/dist/inputs/internal/sliderMarks.js +49 -0
- package/dist/modal/ConfirmDialog.d.ts +4 -4
- package/dist/modal/Modal.d.ts +18 -9
- package/dist/modal/Modal.js +154 -43
- package/dist/navigation/SidebarNav.js +2 -2
- package/dist/styles.css +1 -1
- package/package.json +1 -1
|
@@ -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 };
|
|
@@ -45,13 +45,13 @@ export interface ConfirmDialogProps extends AriaAttributes {
|
|
|
45
45
|
defaultIsOpen?: boolean;
|
|
46
46
|
/** Called with `false` on Cancel, Escape, a backdrop click, the close button, and after `onConfirm` succeeds. */
|
|
47
47
|
onOpenChange?: (isOpen: boolean) => void;
|
|
48
|
-
/** DOM id on the dialog
|
|
48
|
+
/** DOM id on the dialog (`role="dialog"`). */
|
|
49
49
|
id?: string;
|
|
50
|
-
/** Any `data-*` attribute, forwarded to the dialog
|
|
50
|
+
/** Any `data-*` attribute, forwarded to the dialog. */
|
|
51
51
|
[dataAttribute: `data-${string}`]: string | number | boolean | undefined;
|
|
52
|
-
/** Extra class on the dialog
|
|
52
|
+
/** Extra class on the dialog. */
|
|
53
53
|
className?: string;
|
|
54
|
-
/** Inline style on the dialog
|
|
54
|
+
/** Inline style on the dialog; only for setting CSS custom properties. */
|
|
55
55
|
style?: CSSProperties;
|
|
56
56
|
}
|
|
57
57
|
/** A yes/no question before an action: title, description, optional type-to-confirm, Cancel + action. */
|
package/dist/modal/Modal.d.ts
CHANGED
|
@@ -8,17 +8,21 @@ export declare enum ModalSize {
|
|
|
8
8
|
MEDIUM = "MEDIUM",
|
|
9
9
|
/** 720px: a longer form or a preview. */
|
|
10
10
|
LARGE = "LARGE",
|
|
11
|
-
/**
|
|
11
|
+
/** 960px wide and a fixed 720px tall: settings, a chooser, a multi-step wizard. */
|
|
12
12
|
X_LARGE = "X_LARGE"
|
|
13
13
|
}
|
|
14
14
|
/** Every Modal prop except the name pair (`header` / `ariaLabel`). */
|
|
15
15
|
interface ModalBaseProps extends AriaAttributes {
|
|
16
|
-
/** The body. It scrolls when the panel reaches
|
|
16
|
+
/** The body. It scrolls when the panel reaches its height. A string or number renders as `Text`. */
|
|
17
17
|
children?: ReactNode;
|
|
18
18
|
/** The actions row, end-aligned with an 8px gap. Put the least destructive action first. */
|
|
19
19
|
footer?: ReactNode;
|
|
20
20
|
/** A strip between the title row and the body that stays in place while the body scrolls: an `Alert isBanner`. */
|
|
21
21
|
banner?: ReactNode;
|
|
22
|
+
/** A navigation column at the panel's start, its full height: a `SidebarNav` with `hasDividers={false}`, a vertical `Stepper`. The title row, body and footer sit in the column beside it, and the panel holds a fixed height (480 / 560 / 640 / 720px by `size`, less on a shorter viewport). */
|
|
23
|
+
sidebar?: ReactNode;
|
|
24
|
+
/** A second panel beside the dialog's end edge, for context on the body (a preview, the matches for what was typed). Slides out when set and back in when `null`. It takes its child's width (set it with `Box width`), at most half the viewport, and shares the panel's height; no padding: the app pads it. */
|
|
25
|
+
aside?: ReactNode;
|
|
22
26
|
/**
|
|
23
27
|
* Hairlines between the title row and the body, and between the body and the footer. For a body that scrolls.
|
|
24
28
|
* @default false
|
|
@@ -30,10 +34,15 @@ interface ModalBaseProps extends AriaAttributes {
|
|
|
30
34
|
*/
|
|
31
35
|
isFlush?: boolean;
|
|
32
36
|
/**
|
|
33
|
-
* Panel width: 400 / 560 /
|
|
37
|
+
* Panel width: 400 / 560 / 720 / 960px. `X_LARGE` also holds a fixed 720px height.
|
|
34
38
|
* @default ModalSize.MEDIUM
|
|
35
39
|
*/
|
|
36
40
|
size?: ModalSize;
|
|
41
|
+
/**
|
|
42
|
+
* Fill the viewport less 32px on each side (16px on a phone). Replaces `size`.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
isFullscreen?: boolean;
|
|
37
46
|
/**
|
|
38
47
|
* Escape, a backdrop click and the close button close the dialog. When `false` there is no close button, and only the app (usually a `footer` action) can close it.
|
|
39
48
|
* @default true
|
|
@@ -48,18 +57,18 @@ interface ModalBaseProps extends AriaAttributes {
|
|
|
48
57
|
defaultIsOpen?: boolean;
|
|
49
58
|
/** Called with `false` on Escape, a backdrop click and the close button. */
|
|
50
59
|
onOpenChange?: (isOpen: boolean) => void;
|
|
51
|
-
/** DOM id on the
|
|
60
|
+
/** DOM id on the dialog (`role="dialog"`, the panel and its aside). @default a `useId()` value */
|
|
52
61
|
id?: string;
|
|
53
|
-
/** Any `data-*` attribute, forwarded to the
|
|
62
|
+
/** Any `data-*` attribute, forwarded to the dialog. */
|
|
54
63
|
[dataAttribute: `data-${string}`]: string | number | boolean | undefined;
|
|
55
|
-
/** Extra class on the
|
|
64
|
+
/** Extra class on the dialog. */
|
|
56
65
|
className?: string;
|
|
57
|
-
/** Inline style on the
|
|
66
|
+
/** Inline style on the dialog; only for setting CSS custom properties. */
|
|
58
67
|
style?: CSSProperties;
|
|
59
68
|
}
|
|
60
69
|
/** A title row names the dialog. */
|
|
61
70
|
interface ModalTitledProps {
|
|
62
|
-
/** The title row. A string renders as an `h2` `Text` and names the dialog; a node renders as it is, in a first line one control tall.
|
|
71
|
+
/** The title row. A string renders as an `h2` `Text` and names the dialog; a node renders as it is, in a first line one control tall. Without it there is no title row and the close button floats in the top-end corner; `ariaLabel` is then required. */
|
|
63
72
|
header: ReactNode;
|
|
64
73
|
/** A secondary line under the title. Describes the dialog. */
|
|
65
74
|
subheader?: string | undefined;
|
|
@@ -70,7 +79,7 @@ interface ModalTitledProps {
|
|
|
70
79
|
}
|
|
71
80
|
/** No title row: the accessible name is required. */
|
|
72
81
|
interface ModalUntitledProps {
|
|
73
|
-
/** The title row. A string renders as an `h2` `Text` and names the dialog; a node renders as it is.
|
|
82
|
+
/** The title row. A string renders as an `h2` `Text` and names the dialog; a node renders as it is. Without it there is no title row and the close button floats in the top-end corner; `ariaLabel` is then required. */
|
|
74
83
|
header?: undefined;
|
|
75
84
|
/** A secondary line under the title. Needs `header`. */
|
|
76
85
|
subheader?: undefined;
|