@yamatozhen/design_system 1.0.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +101 -101
  3. package/package.json +50 -50
  4. package/scripts/postinstall.js +91 -91
  5. package/template/app/ClientNav.tsx +258 -310
  6. package/template/app/globals.css +2 -167
  7. package/template/app/layout.tsx +94 -82
  8. package/template/app/themes/dark-mc.css +51 -51
  9. package/template/app/themes/dark.css +51 -51
  10. package/template/app/themes/light-mc.css +51 -51
  11. package/template/app/themes/light.css +51 -51
  12. package/template/app/themes/theme.css +272 -82
  13. package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
  14. package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
  15. package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
  16. package/template/components/(buttons)/button.tsx +164 -0
  17. package/template/components/(controls)/slider/Slider.module.css +250 -0
  18. package/template/components/(controls)/slider/Slider.tsx +386 -0
  19. package/template/components/{layout → (controls)}/switch/Switch.module.css +108 -102
  20. package/template/components/{layout → (controls)}/switch/Switch.tsx +69 -48
  21. package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
  22. package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
  23. package/template/components/(date & time)/dateField/DateField.module.css +25 -0
  24. package/template/components/(date & time)/dateField/DateField.tsx +193 -0
  25. package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
  26. package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
  27. package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
  28. package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
  29. package/template/components/(date & time)/shared/dateUtils.ts +107 -0
  30. package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
  31. package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
  32. package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
  33. package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
  34. package/template/components/(feedback)/meter/Meter.tsx +111 -0
  35. package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
  36. package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
  37. package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
  38. package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
  39. package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
  40. package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
  41. package/template/components/(forms)/description/Description.tsx +34 -0
  42. package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
  43. package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
  44. package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
  45. package/template/components/(forms)/form/Form.tsx +54 -0
  46. package/template/components/(forms)/input/Input.tsx +50 -0
  47. package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
  48. package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
  49. package/template/components/(forms)/label/Label.tsx +46 -0
  50. package/template/components/(forms)/numberField/NumberField.tsx +292 -0
  51. package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
  52. package/template/components/(forms)/searchField/SearchField.tsx +139 -0
  53. package/template/components/(forms)/shared/field.module.css +75 -0
  54. package/template/components/(forms)/shared/fieldContext.ts +28 -0
  55. package/template/components/(forms)/textArea/TextArea.tsx +55 -0
  56. package/template/components/(forms)/textField/TextField.tsx +91 -0
  57. package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
  58. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
  59. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
  60. package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
  61. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
  62. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
  63. package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
  64. package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
  65. package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
  66. package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
  67. package/template/components/(layout)/accordion/Accordion.module.css +108 -0
  68. package/template/components/(layout)/accordion/Accordion.tsx +251 -0
  69. package/template/components/(layout)/card/Card.module.css +136 -0
  70. package/template/components/(layout)/card/Card.tsx +371 -0
  71. package/template/components/(layout)/list/List.module.css +83 -0
  72. package/template/components/(layout)/list/List.tsx +332 -0
  73. package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
  74. package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
  75. package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
  76. package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
  77. package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
  78. package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
  79. package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
  80. package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
  81. package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
  82. package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
  83. package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
  84. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
  85. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
  86. package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
  87. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
  88. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -473
  89. package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
  90. package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
  91. package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
  92. package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
  93. package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
  94. package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
  95. package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
  96. package/template/components/(layout)/separator/Separator.tsx +112 -0
  97. package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
  98. package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
  99. package/template/components/(overlays)/modal/Modal.tsx +654 -0
  100. package/template/components/(overlays)/popover/Popover.tsx +420 -0
  101. package/template/components/(overlays)/toast/Toast.tsx +692 -0
  102. package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
  103. package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
  104. package/template/components/(pickers)/select/Select.tsx +188 -0
  105. package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
  106. package/template/components/(pickers)/shared/PickerItem.ts +13 -0
  107. package/template/components/tools/CustomScrollbar.tsx +107 -0
  108. package/template/components/tools/Divider.tsx +11 -11
  109. package/template/components/tools/ReduceMotionContext.tsx +5 -5
  110. package/template/components/tools/Sinewave.tsx +396 -199
  111. package/template/components/tools/SinewaveProgress.tsx +140 -135
  112. package/template/components/tools/badge/Badge.tsx +28 -28
  113. package/template/components/tools/dropdown/drop.module.css +196 -0
  114. package/template/components/tools/dropdown/drop.tsx +568 -0
  115. package/template/components/tools/easing.ts +118 -0
  116. package/template/components/tools/flubber.d.ts +6 -6
  117. package/template/components/tools/footer/Footer.tsx +20 -0
  118. package/template/components/tools/input/Input.module.css +45 -0
  119. package/template/components/tools/input/Input.tsx +99 -0
  120. package/template/components/tools/label/Icon.tsx +39 -0
  121. package/template/components/tools/label/Label.tsx +156 -0
  122. package/template/components/tools/mobileViewProvider.tsx +53 -58
  123. package/template/components/tools/ripple/ripple.css +38 -41
  124. package/template/components/tools/ripple/ripple.tsx +78 -53
  125. package/template/components/tools/shape/Shape.module.css +25 -0
  126. package/template/components/tools/shape/{ShapeMorph.tsx → Shape.tsx} +316 -190
  127. package/template/components/tools/shape/ShapeLoader.tsx +104 -101
  128. package/template/components/tools/shape/ShapePaths.ts +116 -116
  129. package/template/components/tools/switch/Switch.module.css +102 -102
  130. package/template/components/tools/switch/Switch.tsx +48 -48
  131. package/template/components/tools/useBodyScrollLock.tsx +27 -27
  132. package/template/components/tools/useImageColor.ts +47 -47
  133. package/template/components/tools/useNavSheetDrag.tsx +196 -196
  134. package/template/components/layout/accordion/Accordion.module.css +0 -149
  135. package/template/components/layout/accordion/Accordion.tsx +0 -114
  136. package/template/components/layout/button/button.tsx +0 -128
  137. package/template/components/layout/button/drop.module.css +0 -229
  138. package/template/components/layout/button/drop.tsx +0 -516
  139. package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
  140. package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
  141. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
  142. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
  143. package/template/components/layout/modals/alert/Alert.tsx +0 -188
  144. package/template/components/layout/navigation/MioCard.module.css +0 -88
  145. package/template/components/layout/navigation/MioCard.tsx +0 -266
  146. package/template/components/tools/ProgressiveBlur.tsx +0 -73
  147. package/template/components/tools/icon/icon.module.css +0 -0
  148. package/template/components/tools/icon/icon.tsx +0 -125
  149. package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
  150. package/template/components/tools/react-bits/FadeContent.tsx +0 -90
  151. package/template/components/tools/react-bits/GlareHover.tsx +0 -73
  152. package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
  153. package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
  154. package/template/components/tools/react-bits/Magnet.tsx +0 -118
  155. package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
  156. package/template/components/tools/react-bits/Stepper/Stepper.tsx +0 -412
@@ -0,0 +1,386 @@
1
+ "use client";
2
+ import {
3
+ useCallback,
4
+ useId,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ type CSSProperties,
9
+ type KeyboardEvent as ReactKeyboardEvent,
10
+ type PointerEvent as ReactPointerEvent,
11
+ } from "react";
12
+ import styles from "./Slider.module.css";
13
+
14
+ export type SliderOrientation = "horizontal" | "vertical";
15
+ export type SliderVariant = "primary" | "secondary" | "tertiary";
16
+ export type SliderValue = number | number[];
17
+
18
+ export interface SliderProps {
19
+ value?: SliderValue;
20
+ defaultValue?: SliderValue;
21
+ onChange?: (value: SliderValue) => void;
22
+ onChangeEnd?: (value: SliderValue) => void;
23
+ minValue?: number;
24
+ maxValue?: number;
25
+ step?: number;
26
+ formatOptions?: Intl.NumberFormatOptions;
27
+ locale?: string;
28
+ orientation?: SliderOrientation;
29
+ isDisabled?: boolean;
30
+ variant?: SliderVariant;
31
+ label?: string;
32
+ /** true: show the computed/formatted current value(s). string: show this
33
+ * exact string instead (e.g. a custom label derived from the value). */
34
+ showOutput?: boolean | string;
35
+ /** Number of equally spaced snap points across the track, counting BOTH
36
+ * ends — `stops={5}` gives 0/25/50/75/100%. The thumb can only rest on
37
+ * these, and each is marked by a dot below the track. Takes precedence over
38
+ * `step`. Ignored below 2, which has nothing to space out. */
39
+ stops?: number;
40
+ style?: CSSProperties;
41
+ className?: string;
42
+ "aria-label"?: string;
43
+ }
44
+
45
+ const BIG_STEP_MULTIPLIER = 10;
46
+ const THUMB_LENGTH = 28;
47
+ const THUMB_LENGTH_DRAGGING = 32;
48
+ const TRACK_GAP = -8;
49
+
50
+ function clamp(value: number, min: number, max: number) {
51
+ return Math.min(max, Math.max(min, value));
52
+ }
53
+
54
+ function roundToStep(value: number, min: number, step: number) {
55
+ return min + Math.round((value - min) / step) * step;
56
+ }
57
+
58
+ function formatValue(
59
+ value: number,
60
+ locale: string,
61
+ formatOptions?: Intl.NumberFormatOptions,
62
+ ) {
63
+ const resolvedOptions =
64
+ formatOptions?.style === "currency" && !formatOptions.currencyDisplay
65
+ ? { ...formatOptions, currencyDisplay: "narrowSymbol" as const }
66
+ : formatOptions;
67
+ return new Intl.NumberFormat(locale, resolvedOptions).format(value);
68
+ }
69
+ function percentFromPointer(
70
+ clientX: number,
71
+ clientY: number,
72
+ rect: DOMRect,
73
+ orientation: SliderOrientation,
74
+ ) {
75
+ if (orientation === "horizontal") {
76
+ return clamp((clientX - rect.left) / rect.width, 0, 1);
77
+ }
78
+ return clamp(1 - (clientY - rect.top) / rect.height, 0, 1);
79
+ }
80
+
81
+ export default function Slider({
82
+ value: controlledValue,
83
+ defaultValue,
84
+ onChange,
85
+ onChangeEnd,
86
+ minValue = 0,
87
+ maxValue = 100,
88
+ step = 1,
89
+ formatOptions,
90
+ locale = "en-US",
91
+ orientation = "horizontal",
92
+ isDisabled = false,
93
+ variant = "primary",
94
+ label,
95
+ showOutput = true,
96
+ stops,
97
+ style,
98
+ className,
99
+ "aria-label": ariaLabel,
100
+ }: SliderProps) {
101
+ const isRange = Array.isArray(controlledValue ?? defaultValue);
102
+ const [internalValue, setInternalValue] = useState<SliderValue>(
103
+ () => defaultValue ?? (isRange ? [minValue, maxValue] : minValue),
104
+ );
105
+ const isControlled = controlledValue !== undefined;
106
+ const rawValue = isControlled ? controlledValue! : internalValue;
107
+ const values = useMemo(
108
+ () => (Array.isArray(rawValue) ? rawValue : [rawValue]),
109
+ [rawValue],
110
+ );
111
+
112
+ const trackRef = useRef<HTMLDivElement>(null);
113
+ const thumbRefs = useRef<(HTMLButtonElement | null)[]>([]);
114
+ const [draggingIndex, setDraggingIndex] = useState<number | null>(null);
115
+ const labelId = useId();
116
+
117
+ // Stop positions, evenly spaced INCLUDING both ends — n stops means n-1
118
+ // gaps, so the i-th sits at i/(n-1) of the way along.
119
+ const stopValues = useMemo(() => {
120
+ if (!stops || stops < 2) return null;
121
+ return Array.from(
122
+ { length: stops },
123
+ (_, i) => minValue + (i / (stops - 1)) * (maxValue - minValue),
124
+ );
125
+ }, [stops, minValue, maxValue]);
126
+
127
+ const commit = useCallback(
128
+ (next: number[], fireEnd: boolean) => {
129
+ const nextValue: SliderValue = isRange ? next : next[0];
130
+ if (!isControlled) setInternalValue(nextValue);
131
+ onChange?.(nextValue);
132
+ if (fireEnd) onChangeEnd?.(nextValue);
133
+ },
134
+ [isRange, isControlled, onChange, onChangeEnd],
135
+ );
136
+ const setThumbValue = useCallback(
137
+ (index: number, rawNext: number, fireEnd: boolean) => {
138
+ // Stops replace `step` entirely when present — the thumb may only land
139
+ // on one of them, so snap to whichever is closest.
140
+ const snapped = stopValues
141
+ ? stopValues.reduce((best, v) =>
142
+ Math.abs(v - rawNext) < Math.abs(best - rawNext) ? v : best,
143
+ )
144
+ : roundToStep(rawNext, minValue, step);
145
+ const stepped = clamp(snapped, minValue, maxValue);
146
+ const next = [...values];
147
+ const lowerBound = index > 0 ? next[index - 1] : minValue;
148
+ const upperBound = index < next.length - 1 ? next[index + 1] : maxValue;
149
+ next[index] = clamp(stepped, lowerBound, upperBound);
150
+ commit(next, fireEnd);
151
+ },
152
+ [values, minValue, maxValue, step, stopValues, commit],
153
+ );
154
+
155
+ // Pointer gestures are handled by the TRACK rather than by each thumb.
156
+ // That is what lets a click anywhere on the track send the nearest thumb
157
+ // there, and it keeps click-then-drag as one continuous gesture. A press on
158
+ // a thumb bubbles up here too and simply resolves to that same thumb, so
159
+ // grabbing one still behaves exactly as before.
160
+ const valueFromPointer = useCallback(
161
+ (clientX: number, clientY: number) => {
162
+ const rect = trackRef.current?.getBoundingClientRect();
163
+ if (!rect) return null;
164
+ const percent = percentFromPointer(clientX, clientY, rect, orientation);
165
+ return minValue + percent * (maxValue - minValue);
166
+ },
167
+ [orientation, minValue, maxValue],
168
+ );
169
+
170
+ const nearestIndex = useCallback(
171
+ (raw: number) => {
172
+ let best = 0;
173
+ let bestDist = Math.abs(values[0] - raw);
174
+ for (let i = 1; i < values.length; i++) {
175
+ const dist = Math.abs(values[i] - raw);
176
+ // Tie-break matters when two thumbs sit on top of each other: pick the
177
+ // one that can actually travel toward the pointer, or a collapsed
178
+ // range would jam against its own neighbour and never reopen.
179
+ if (dist < bestDist || (dist === bestDist && raw > values[i])) {
180
+ best = i;
181
+ bestDist = dist;
182
+ }
183
+ }
184
+ return best;
185
+ },
186
+ [values],
187
+ );
188
+
189
+ const handleTrackPointerDown = useCallback(
190
+ (e: ReactPointerEvent<HTMLDivElement>) => {
191
+ if (isDisabled) return;
192
+ const raw = valueFromPointer(e.clientX, e.clientY);
193
+ if (raw === null) return;
194
+ e.preventDefault();
195
+ const index = nearestIndex(raw);
196
+ trackRef.current?.setPointerCapture(e.pointerId);
197
+ setDraggingIndex(index);
198
+ // preventDefault above suppresses the native focus, so do it by hand —
199
+ // otherwise the keyboard can't carry on from where the click left off.
200
+ thumbRefs.current[index]?.focus();
201
+ setThumbValue(index, raw, false);
202
+ },
203
+ [isDisabled, valueFromPointer, nearestIndex, setThumbValue],
204
+ );
205
+
206
+ const handleTrackPointerMove = useCallback(
207
+ (e: ReactPointerEvent<HTMLDivElement>) => {
208
+ if (draggingIndex === null) return;
209
+ const raw = valueFromPointer(e.clientX, e.clientY);
210
+ if (raw === null) return;
211
+ setThumbValue(draggingIndex, raw, false);
212
+ },
213
+ [draggingIndex, valueFromPointer, setThumbValue],
214
+ );
215
+
216
+ const endDrag = useCallback(() => {
217
+ if (draggingIndex === null) return;
218
+ setDraggingIndex(null);
219
+ onChangeEnd?.(isRange ? values : values[0]);
220
+ }, [draggingIndex, onChangeEnd, isRange, values]);
221
+
222
+ const handleKeyDown = useCallback(
223
+ (index: number) => (e: ReactKeyboardEvent<HTMLButtonElement>) => {
224
+ if (isDisabled) return;
225
+ const increaseKey =
226
+ orientation === "horizontal" ? "ArrowRight" : "ArrowUp";
227
+ const decreaseKey =
228
+ orientation === "horizontal" ? "ArrowLeft" : "ArrowDown";
229
+ let delta = 0;
230
+ if (e.key === increaseKey) delta = step;
231
+ else if (e.key === decreaseKey) delta = -step;
232
+ else if (e.key === "PageUp") delta = step * BIG_STEP_MULTIPLIER;
233
+ else if (e.key === "PageDown") delta = -step * BIG_STEP_MULTIPLIER;
234
+ else if (e.key === "Home") {
235
+ e.preventDefault();
236
+ setThumbValue(index, minValue, true);
237
+ return;
238
+ } else if (e.key === "End") {
239
+ e.preventDefault();
240
+ setThumbValue(index, maxValue, true);
241
+ return;
242
+ } else {
243
+ return;
244
+ }
245
+ e.preventDefault();
246
+ setThumbValue(index, values[index] + delta, true);
247
+ },
248
+ [isDisabled, orientation, step, minValue, maxValue, values, setThumbValue],
249
+ );
250
+
251
+ const variantStyle = {
252
+ "--slider-color": `var(--md-sys-color-${variant})`,
253
+ } as CSSProperties;
254
+
255
+ const pct = (v: number) => ((v - minValue) / (maxValue - minValue)) * 100;
256
+ const thumbLength = (index: number) =>
257
+ draggingIndex === index ? THUMB_LENGTH_DRAGGING : THUMB_LENGTH;
258
+ const isHorizontal = orientation === "horizontal";
259
+ const startProp = isHorizontal ? "left" : "bottom";
260
+ const sizeProp = isHorizontal ? "width" : "height";
261
+ const zeroEdgeProp = startProp;
262
+ const fullEdgeProp = isHorizontal ? "right" : "top";
263
+ const startPct = pct(values[0]);
264
+ const endPct = pct(values[values.length - 1]);
265
+ const fillStartPct = values.length === 1 ? 0 : startPct;
266
+ const fillStyle: CSSProperties = {
267
+ [startProp]: `${fillStartPct}%`,
268
+ [sizeProp]: `${endPct - fillStartPct}%`,
269
+ };
270
+ const remainingSegments: { key: string; style: CSSProperties }[] =
271
+ values.length === 1
272
+ ? [
273
+ {
274
+ key: "after",
275
+ style: {
276
+ [startProp]: `calc(${startPct}% + ${thumbLength(0) + TRACK_GAP}px)`,
277
+ [sizeProp]: `max(0px, calc(100% - ${startPct}% - ${thumbLength(0) + TRACK_GAP}px))`,
278
+ },
279
+ },
280
+ ]
281
+ : [
282
+ {
283
+ key: "before",
284
+ style: {
285
+ [startProp]: 0,
286
+ [sizeProp]: `max(0px, calc(${startPct}% - ${thumbLength(0) + TRACK_GAP}px))`,
287
+ },
288
+ },
289
+ {
290
+ key: "after",
291
+ style: {
292
+ [startProp]: `calc(${endPct}% + ${thumbLength(values.length - 1) + TRACK_GAP}px)`,
293
+ [sizeProp]: `max(0px, calc(100% - ${endPct}% - ${thumbLength(values.length - 1) + TRACK_GAP}px))`,
294
+ },
295
+ },
296
+ ];
297
+
298
+ const outputText =
299
+ typeof showOutput === "string"
300
+ ? showOutput
301
+ : showOutput
302
+ ? values.map((v) => formatValue(v, locale, formatOptions)).join(" – ")
303
+ : null;
304
+
305
+ return (
306
+ <div
307
+ className={[styles.slider, className].filter(Boolean).join(" ")}
308
+ data-orientation={orientation}
309
+ data-disabled={isDisabled || undefined}
310
+ style={{ ...variantStyle, ...style }}
311
+ >
312
+ {(label || outputText) && (
313
+ <div className={styles.header}>
314
+ {label && (
315
+ <span id={labelId} className={styles.label}>
316
+ {label}
317
+ </span>
318
+ )}
319
+ {outputText && <span className={styles.output}>{outputText}</span>}
320
+ </div>
321
+ )}
322
+ <div
323
+ ref={trackRef}
324
+ className={styles.track}
325
+ onPointerDown={handleTrackPointerDown}
326
+ onPointerMove={handleTrackPointerMove}
327
+ onPointerUp={endDrag}
328
+ onPointerCancel={endDrag}
329
+ >
330
+ <div className={styles.fill} style={fillStyle} />
331
+ {remainingSegments.map((seg) => (
332
+ <div key={seg.key} className={styles.remaining} style={seg.style} />
333
+ ))}
334
+ {stopValues && (
335
+ <div aria-hidden="true" className={styles.stopTrack}>
336
+ {stopValues.map((v, i) => (
337
+ <span
338
+ key={`stop-${i}`}
339
+ className={styles.stopDot}
340
+ style={{ [startProp]: `${pct(v)}%` }}
341
+ />
342
+ ))}
343
+ </div>
344
+ )}
345
+ <span className={styles.endDot} style={{ [fullEdgeProp]: 0 }} />
346
+ {isRange && (
347
+ <span className={styles.endDot} style={{ [zeroEdgeProp]: 0 }} />
348
+ )}
349
+ {values.map((v, index) => (
350
+ <button
351
+ key={index}
352
+ ref={(el) => {
353
+ thumbRefs.current[index] = el;
354
+ }}
355
+ type="button"
356
+ role="slider"
357
+ aria-orientation={orientation}
358
+ aria-valuemin={index > 0 ? values[index - 1] : minValue}
359
+ aria-valuemax={
360
+ index < values.length - 1 ? values[index + 1] : maxValue
361
+ }
362
+ aria-valuenow={v}
363
+ aria-valuetext={formatValue(v, locale, formatOptions)}
364
+ aria-label={ariaLabel}
365
+ aria-labelledby={label ? labelId : undefined}
366
+ aria-disabled={isDisabled || undefined}
367
+ disabled={isDisabled}
368
+ tabIndex={isDisabled ? -1 : 0}
369
+ data-dragging={draggingIndex === index || undefined}
370
+ className={styles.thumb}
371
+ style={
372
+ orientation === "horizontal"
373
+ ? {
374
+ left: `${((v - minValue) / (maxValue - minValue)) * 100}%`,
375
+ }
376
+ : {
377
+ bottom: `${((v - minValue) / (maxValue - minValue)) * 100}%`,
378
+ }
379
+ }
380
+ onKeyDown={handleKeyDown(index)}
381
+ />
382
+ ))}
383
+ </div>
384
+ </div>
385
+ );
386
+ }
@@ -1,102 +1,108 @@
1
- .switchContainer {
2
- display: inline-flex;
3
- align-items: center;
4
- position: relative;
5
- margin: 0;
6
- }
7
-
8
- /* ── Accessibility: Show Borders ──────────────────────────────────────────── */
9
- :global([data-show-borders="true"]) .switchBg,
10
- :global([data-show-borders="true"]) .checked .switchBg {
11
- border: var(--a11y-border) !important;
12
- }
13
-
14
- .switchBg {
15
- position: relative;
16
- display: flex;
17
- align-items: center;
18
- overflow: hidden;
19
- justify-content: center;
20
- border: 2px solid var(--md-sys-color-outline);
21
- border-radius: 50px;
22
- background-color: transparent;
23
- width: 48px;
24
- height: 28px;
25
- cursor: pointer;
26
- &:hover {
27
- filter: var(--filterBrightness);
28
- }
29
- will-change: transform, background-color;
30
- transition:
31
- transform var(--transition-expressive),
32
- background-color var(--transition-expressive-color),
33
- filter var(--transition-expressive-color),
34
- border var(--transition-expressive-color);
35
- }
36
-
37
- .switchBg::after {
38
- content: "";
39
- position: absolute;
40
- transform: translate(-10px, 0px);
41
- width: 12px;
42
- height: 12px;
43
- border-radius: 50%;
44
- background-color: var(--md-sys-color-outline);
45
- will-change: transform, width, height, background-color;
46
- transition:
47
- transform var(--transition-expressive),
48
- width var(--transition-expressive-fast),
49
- height var(--transition-expressive-fast),
50
- background-color var(--transition-expressive-color),
51
- border var(--transition-expressive-color),
52
- left var(--transition-expressive),
53
- right var(--transition-expressive);
54
- }
55
-
56
- .switchBg .switchIcon {
57
- opacity: 0;
58
- position: absolute;
59
- scale: 0.5 !important;
60
- z-index: 99;
61
- transform: translate(-20px, 1px);
62
- color: var(--md-sys-color-outline);
63
- transform-origin: center;
64
- padding: 0;
65
- transition:
66
- transform var(--transition-expressive),
67
- padding var(--transition-expressive),
68
- color var(--transition-expressive-color),
69
- scale var(--transition-expressive),
70
- opacity var(--transition-expressive-color);
71
- }
72
-
73
- .checked .switchBg {
74
- background-color: var(--md-sys-color-primary);
75
- border: 2px solid var(--md-sys-color-primary);
76
- }
77
-
78
- .checked .switchBg::after {
79
- background-color: var(--md-sys-color-on-primary);
80
- transform: translate(10px, 0px);
81
- width: 22px;
82
- height: 22px;
83
- transition:
84
- background-color var(--transition-expressive-color),
85
- transform var(--transition-expressive);
86
- }
87
-
88
- .checked .switchIcon {
89
- transform: translate(13px, 1px);
90
- opacity: 1;
91
- scale: 0.8 !important;
92
- color: var(--md-sys-color-on-surface);
93
- transition:
94
- color var(--transition-expressive-color),
95
- scale var(--transition-expressive),
96
- transform var(--transition-expressive),
97
- opacity var(--transition-expressive-color);
98
- }
99
-
100
- .switchContainer input[type="checkbox"] {
101
- display: none;
102
- }
1
+ .switchContainer {
2
+ display: inline-flex;
3
+ align-items: center;
4
+ position: relative;
5
+ margin: 0;
6
+ max-height: 28px;
7
+ }
8
+
9
+ /* ── Accessibility: Show Borders ──────────────────────────────────────────── */
10
+ :global([data-show-borders="true"]) .switchBg,
11
+ :global([data-show-borders="true"]) .checked .switchBg {
12
+ box-shadow: var(--a11y-border) !important;
13
+ }
14
+
15
+ .switchBg {
16
+ position: relative;
17
+ display: flex;
18
+ align-items: center;
19
+ overflow: hidden;
20
+ justify-content: center;
21
+ box-shadow: inset 0 0 0 2px
22
+ color-mix(var(--md-sys-color-on-surface) 50%, transparent 100%);
23
+ border-radius: 50px;
24
+ background-color: transparent;
25
+ width: 48px;
26
+ height: 28px;
27
+ cursor: pointer;
28
+ &:hover {
29
+ filter: var(--filterBrightness);
30
+ }
31
+ will-change: transform, background-color;
32
+ transition:
33
+ transform var(--transition-expressive-slow),
34
+ background-color var(--transition-expressive-color),
35
+ filter var(--transition-expressive-color),
36
+ border var(--transition-expressive-color);
37
+ }
38
+
39
+ .switchBg::after {
40
+ content: "";
41
+ position: absolute;
42
+ transform: translate(-10px, 0px);
43
+ width: 12px;
44
+ height: 12px;
45
+ border-radius: 50%;
46
+ background-color: color-mix(
47
+ var(--md-sys-color-on-surface) 50%,
48
+ transparent 100%
49
+ );
50
+ will-change: transform, width, height, background-color;
51
+ transition:
52
+ transform var(--transition-expressive-slow),
53
+ width var(--transition-expressive),
54
+ height var(--transition-expressive),
55
+ background-color var(--transition-expressive-color),
56
+ border var(--transition-expressive-color),
57
+ left var(--transition-expressive),
58
+ right var(--transition-expressive);
59
+ }
60
+
61
+ .switchBg .switchIcon {
62
+ opacity: 0;
63
+ position: absolute;
64
+ scale: 0.5 !important;
65
+ z-index: 99;
66
+ user-select: none;
67
+ transform: translate(-20px, 1px);
68
+ color: color-mix(var(--md-sys-color-on-surface) 50%, transparent 100%);
69
+ transform-origin: center;
70
+ padding: 0;
71
+ transition:
72
+ transform var(--transition-expressive),
73
+ padding var(--transition-expressive),
74
+ color var(--transition-expressive-color),
75
+ scale var(--transition-expressive),
76
+ opacity var(--transition-expressive-color);
77
+ }
78
+
79
+ .checked .switchBg {
80
+ background-color: var(--switch-on-bg, var(--md-sys-color-primary));
81
+ box-shadow: inset 0 0 0 2px var(--switch-on-bg, var(--md-sys-color-primary));
82
+ }
83
+
84
+ .checked .switchBg::after {
85
+ background-color: var(--switch-on-thumb, var(--md-sys-color-on-primary));
86
+ transform: translate(10px, 0px);
87
+ width: 22px;
88
+ height: 22px;
89
+ transition:
90
+ background-color var(--transition-expressive-color),
91
+ transform var(--transition-expressive);
92
+ }
93
+
94
+ .checked .switchIcon {
95
+ transform: translate(13px, 1px);
96
+ opacity: 1;
97
+ scale: 0.8 !important;
98
+ color: var(--md-sys-color-on-surface);
99
+ transition:
100
+ color var(--transition-expressive-color),
101
+ scale var(--transition-expressive),
102
+ transform var(--transition-expressive),
103
+ opacity var(--transition-expressive-color);
104
+ }
105
+
106
+ .switchContainer input[type="checkbox"] {
107
+ display: none;
108
+ }