@yamatozhen/design_system 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +101 -101
  3. package/package.json +50 -49
  4. package/scripts/postinstall.js +91 -105
  5. package/template/app/ClientNav.tsx +258 -310
  6. package/template/app/globals.css +2 -167
  7. package/template/app/layout.tsx +94 -128
  8. package/template/app/themes/dark-mc 2.css +51 -0
  9. package/template/app/themes/dark-mc.css +51 -51
  10. package/template/app/themes/dark.css +51 -51
  11. package/template/app/themes/light 2.css +51 -0
  12. package/template/app/themes/light-mc 2.css +51 -0
  13. package/template/app/themes/light-mc.css +51 -51
  14. package/template/app/themes/light.css +51 -51
  15. package/template/app/themes/theme 2.css +272 -0
  16. package/template/app/themes/theme.css +272 -82
  17. package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
  18. package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
  19. package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
  20. package/template/components/(buttons)/button.tsx +164 -0
  21. package/template/components/(controls)/slider/Slider.module.css +250 -0
  22. package/template/components/(controls)/slider/Slider.tsx +386 -0
  23. package/template/components/(controls)/switch/Switch.module.css +108 -0
  24. package/template/components/(controls)/switch/Switch.tsx +69 -0
  25. package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
  26. package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
  27. package/template/components/(date & time)/dateField/DateField.module.css +25 -0
  28. package/template/components/(date & time)/dateField/DateField.tsx +193 -0
  29. package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
  30. package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
  31. package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
  32. package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
  33. package/template/components/(date & time)/shared/dateUtils.ts +107 -0
  34. package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
  35. package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
  36. package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
  37. package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
  38. package/template/components/(feedback)/meter/Meter.tsx +111 -0
  39. package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
  40. package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
  41. package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
  42. package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
  43. package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
  44. package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
  45. package/template/components/(forms)/description/Description.tsx +34 -0
  46. package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
  47. package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
  48. package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
  49. package/template/components/(forms)/form/Form.tsx +54 -0
  50. package/template/components/(forms)/input/Input.tsx +50 -0
  51. package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
  52. package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
  53. package/template/components/(forms)/label/Label.tsx +46 -0
  54. package/template/components/(forms)/numberField/NumberField.tsx +292 -0
  55. package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
  56. package/template/components/(forms)/searchField/SearchField.tsx +139 -0
  57. package/template/components/(forms)/shared/field.module.css +75 -0
  58. package/template/components/(forms)/shared/fieldContext.ts +28 -0
  59. package/template/components/(forms)/textArea/TextArea.tsx +55 -0
  60. package/template/components/(forms)/textField/TextField.tsx +91 -0
  61. package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
  62. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
  63. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
  64. package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
  65. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
  66. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
  67. package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
  68. package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
  69. package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
  70. package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
  71. package/template/components/(layout)/accordion/Accordion.module.css +108 -0
  72. package/template/components/(layout)/accordion/Accordion.tsx +251 -0
  73. package/template/components/(layout)/card/Card.module.css +136 -0
  74. package/template/components/(layout)/card/Card.tsx +371 -0
  75. package/template/components/(layout)/list/List.module.css +83 -0
  76. package/template/components/(layout)/list/List.tsx +332 -0
  77. package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
  78. package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
  79. package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
  80. package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
  81. package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
  82. package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
  83. package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
  84. package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
  85. package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
  86. package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
  87. package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
  88. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
  89. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
  90. package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
  91. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
  92. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -478
  93. package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
  94. package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
  95. package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
  96. package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
  97. package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
  98. package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
  99. package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
  100. package/template/components/(layout)/separator/Separator.tsx +112 -0
  101. package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
  102. package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
  103. package/template/components/(overlays)/modal/Modal.tsx +654 -0
  104. package/template/components/(overlays)/popover/Popover.tsx +420 -0
  105. package/template/components/(overlays)/toast/Toast.tsx +692 -0
  106. package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
  107. package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
  108. package/template/components/(pickers)/select/Select.tsx +188 -0
  109. package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
  110. package/template/components/(pickers)/shared/PickerItem.ts +13 -0
  111. package/template/components/tools/CustomScrollbar 2.tsx +107 -0
  112. package/template/components/tools/CustomScrollbar.tsx +107 -0
  113. package/template/components/tools/Divider 2.tsx +11 -0
  114. package/template/components/tools/Divider.tsx +11 -11
  115. package/template/components/tools/ReduceMotionContext 2.tsx +5 -0
  116. package/template/components/tools/ReduceMotionContext.tsx +5 -5
  117. package/template/components/tools/Sinewave 2.tsx +206 -0
  118. package/template/components/tools/Sinewave.tsx +396 -199
  119. package/template/components/tools/SinewaveProgress 2.tsx +140 -0
  120. package/template/components/tools/SinewaveProgress.tsx +140 -135
  121. package/template/components/tools/badge/Badge 2.tsx +28 -0
  122. package/template/components/tools/badge/Badge.tsx +28 -28
  123. package/template/components/tools/dropdown/drop.module.css +196 -0
  124. package/template/components/tools/dropdown/drop.tsx +568 -0
  125. package/template/components/tools/easing.ts +118 -0
  126. package/template/components/tools/flubber.d 2.ts +7 -0
  127. package/template/components/tools/flubber.d.ts +6 -6
  128. package/template/components/tools/footer/Footer.tsx +20 -0
  129. package/template/components/tools/input/Input 2.tsx +99 -0
  130. package/template/components/tools/input/Input.module 2.css +45 -0
  131. package/template/components/tools/input/Input.module.css +45 -0
  132. package/template/components/tools/input/Input.tsx +99 -0
  133. package/template/components/tools/label/Icon 2.tsx +39 -0
  134. package/template/components/tools/label/Icon.tsx +39 -0
  135. package/template/components/tools/label/Label 2.tsx +150 -0
  136. package/template/components/tools/label/Label.tsx +156 -0
  137. package/template/components/tools/mobileViewProvider 2.tsx +53 -0
  138. package/template/components/tools/mobileViewProvider.tsx +53 -58
  139. package/template/components/tools/ripple/ripple 2.css +38 -0
  140. package/template/components/tools/ripple/ripple 2.tsx +78 -0
  141. package/template/components/tools/ripple/ripple.css +38 -41
  142. package/template/components/tools/ripple/ripple.tsx +78 -53
  143. package/template/components/tools/shape/{ShapeMorph.tsx → Shape 2.tsx } +313 -190
  144. package/template/components/tools/shape/Shape.module 2.css +21 -0
  145. package/template/components/tools/shape/Shape.module.css +25 -0
  146. package/template/components/tools/shape/Shape.tsx +316 -0
  147. package/template/components/tools/shape/ShapeLoader 2.tsx +104 -0
  148. package/template/components/tools/shape/ShapeLoader.tsx +104 -101
  149. package/template/components/tools/shape/ShapePaths 2.ts +116 -0
  150. package/template/components/tools/shape/ShapePaths.ts +116 -116
  151. package/template/components/{layout/switch/Switch.tsx → tools/switch/Switch 2.tsx } +48 -48
  152. package/template/components/{layout/switch/Switch.module.css → tools/switch/Switch.module 2.css } +102 -102
  153. package/template/components/tools/switch/Switch.module.css +102 -102
  154. package/template/components/tools/switch/Switch.tsx +48 -48
  155. package/template/components/tools/useBodyScrollLock 2.tsx +27 -0
  156. package/template/components/tools/useBodyScrollLock.tsx +27 -27
  157. package/template/components/tools/useImageColor 2.ts +47 -0
  158. package/template/components/tools/useImageColor.ts +47 -47
  159. package/template/components/tools/useNavSheetDrag 2.tsx +196 -0
  160. package/template/components/tools/useNavSheetDrag.tsx +196 -196
  161. package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght 2.woff2 +0 -0
  162. package/template/components/layout/accordion/Accordion.module.css +0 -149
  163. package/template/components/layout/accordion/Accordion.tsx +0 -114
  164. package/template/components/layout/button/button.tsx +0 -128
  165. package/template/components/layout/button/drop.module.css +0 -229
  166. package/template/components/layout/button/drop.tsx +0 -516
  167. package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
  168. package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
  169. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
  170. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
  171. package/template/components/layout/modals/alert/Alert.tsx +0 -188
  172. package/template/components/layout/navigation/MioCard.module.css +0 -88
  173. package/template/components/layout/navigation/MioCard.tsx +0 -266
  174. package/template/components/tools/ProgressiveBlur.tsx +0 -73
  175. package/template/components/tools/icon/SocialIcons.tsx +0 -88
  176. package/template/components/tools/icon/icon.module.css +0 -0
  177. package/template/components/tools/icon/icon.tsx +0 -125
  178. package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
  179. package/template/components/tools/react-bits/FadeContent.tsx +0 -90
  180. package/template/components/tools/react-bits/GlareHover.tsx +0 -73
  181. package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
  182. package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
  183. package/template/components/tools/react-bits/Magnet.tsx +0 -118
  184. package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
  185. 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
+ }
@@ -0,0 +1,108 @@
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
+ }
@@ -0,0 +1,69 @@
1
+ "use client";
2
+ import styles from "./Switch.module.css";
3
+ import { useState, type CSSProperties } from "react";
4
+ import Icon from "../../tools/label/Icon";
5
+
6
+ export type SwitchVariant = "primary" | "secondary" | "tertiary";
7
+
8
+ export default function Switch({
9
+ id,
10
+ onClick,
11
+ systemIcon = false,
12
+ checked: controlledChecked,
13
+ onChange,
14
+ onToggleOn,
15
+ onToggleOff,
16
+ variant = "primary",
17
+ }: {
18
+ id?: string;
19
+ onClick?: () => void;
20
+ systemIcon?: boolean;
21
+ /** If provided the Switch runs in controlled mode */
22
+ checked?: boolean;
23
+ onChange?: (checked: boolean) => void;
24
+ /** Fired instead of/alongside onChange when the switch turns on or off —
25
+ * split out since consumers often only care about one direction. */
26
+ onToggleOn?: () => void;
27
+ onToggleOff?: () => void;
28
+ /** Checked-state color. No "default"/neutral option — a checked switch is
29
+ * always tinted, there's no neutral "on" look. */
30
+ variant?: SwitchVariant;
31
+ }) {
32
+ const [internalChecked, setInternalChecked] = useState(false);
33
+ const isControlled = controlledChecked !== undefined;
34
+ const isChecked = isControlled ? controlledChecked : internalChecked;
35
+
36
+ const handleChange = () => {
37
+ const next = !isChecked;
38
+ if (!isControlled) setInternalChecked(next);
39
+ onChange?.(next);
40
+ if (next) onToggleOn?.();
41
+ else onToggleOff?.();
42
+ onClick?.();
43
+ };
44
+
45
+ const variantStyle = {
46
+ "--switch-on-bg": `var(--md-sys-color-${variant})`,
47
+ "--switch-on-thumb": `var(--md-sys-color-on-${variant})`,
48
+ } as CSSProperties;
49
+
50
+ return (
51
+ <>
52
+ <label
53
+ className={`${styles.switchContainer} ${isChecked ? styles.checked : ""}`}
54
+ style={variantStyle}
55
+ >
56
+ <input type="checkbox" checked={isChecked} onChange={handleChange} />
57
+ <span className={styles.switchBg}>
58
+ <span
59
+ id={`switch-icon md-18${id}`}
60
+ className={styles.switchIcon}
61
+ style={systemIcon == false ? { opacity: 0 } : {}}
62
+ >
63
+ <Icon systemName={isChecked ? "check" : "close"} />
64
+ </span>
65
+ </span>
66
+ </label>
67
+ </>
68
+ );
69
+ }
@@ -0,0 +1,125 @@
1
+ .calendar {
2
+ display: inline-flex;
3
+ flex-direction: column;
4
+ gap: 8px;
5
+ width: fit-content;
6
+ padding: 12px;
7
+ border-radius: var(--borderRadius-md);
8
+ background: transparent;
9
+ }
10
+
11
+ .header {
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: space-between;
15
+ }
16
+
17
+ .heading {
18
+ font-size: 14px;
19
+ font-weight: 600;
20
+ color: var(--md-sys-color-on-surface);
21
+ }
22
+
23
+ .navButton {
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ width: 32px;
28
+ height: 32px;
29
+ border: none;
30
+ border-radius: var(--borderRadius-sm);
31
+ background: transparent;
32
+ color: var(--md-sys-color-on-surface);
33
+ cursor: pointer;
34
+ transition: background-color var(--transition-expressive-color);
35
+ }
36
+ .navButton:hover:not(:disabled) {
37
+ background: var(--md-sys-color-surface-container-highest);
38
+ }
39
+ .navButton:disabled {
40
+ opacity: 0.4;
41
+ cursor: not-allowed;
42
+ }
43
+
44
+ .grid {
45
+ display: flex;
46
+ flex-direction: column;
47
+ gap: 2px;
48
+ }
49
+
50
+ .gridHeaderRow,
51
+ .gridBody {
52
+ display: grid;
53
+ grid-template-columns: repeat(7, 1fr);
54
+ }
55
+
56
+ .headerCell {
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ height: 32px;
61
+ font-size: 14px;
62
+ font-weight: 600;
63
+ color: var(--md-sys-color-on-surface-variant);
64
+ }
65
+
66
+ .cell {
67
+ position: relative;
68
+ z-index: 0;
69
+ display: flex;
70
+ align-items: center;
71
+ justify-content: center;
72
+ margin: 2px 0;
73
+ height: 38px;
74
+ min-width: 38px;
75
+ border-radius: var(--borderRadius-xs);
76
+ border: none;
77
+ background: transparent;
78
+ color: var(--md-sys-color-on-surface);
79
+ font-size: 14px;
80
+ cursor: pointer;
81
+ filter: none;
82
+ transition:
83
+ background-color var(--transition-expressive-color),
84
+ border-radius var(--transition-expressive-fast);
85
+ }
86
+
87
+ .cell[data-outside-month="true"] {
88
+ color: var(--md-sys-color-on-surface-variant);
89
+ opacity: 0.4;
90
+ }
91
+
92
+ .cell[data-today="true"] {
93
+ font-weight: 700;
94
+ border-radius: var(--borderRadius-md);
95
+ box-shadow: inset 0 0 0 2px var(--md-sys-color-primary);
96
+ }
97
+
98
+ .cell:hover:not(:disabled) {
99
+ background: var(--md-sys-color-surface-container-low);
100
+ filter: var(--filterBrightness);
101
+ }
102
+
103
+ .cell[data-selected="true"] {
104
+ background: var(--md-sys-color-primary) !important;
105
+ color: var(--md-sys-color-on-primary) !important;
106
+ font-weight: 600;
107
+ border-radius: var(--borderRadius-md) !important;
108
+ box-shadow:
109
+ 0 0 0 1px var(--globalUIBorder),
110
+ 0 1px 1px rgba(0, 0, 0, 0.1),
111
+ 0 1px 3px rgba(0, 0, 0, 0.1),
112
+ 0 2px 6px rgba(0, 0, 0, 0.1);
113
+ }
114
+
115
+ .cell[data-unavailable="true"],
116
+ .cell:disabled {
117
+ opacity: 0.35;
118
+ cursor: not-allowed;
119
+ text-decoration: line-through;
120
+ }
121
+
122
+ .cell:focus-visible {
123
+ outline: 2px solid var(--md-sys-color-primary);
124
+ outline-offset: 1px;
125
+ }