@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,654 @@
1
+ "use client";
2
+ import { AnimatePresence, motion, MotionConfig } from "framer-motion";
3
+ import React, {
4
+ createContext,
5
+ useCallback,
6
+ useContext,
7
+ useEffect,
8
+ useId,
9
+ useMemo,
10
+ useRef,
11
+ useState,
12
+ } from "react";
13
+ import { createPortal } from "react-dom";
14
+ import { useBodyScrollLock } from "@/components/tools/useBodyScrollLock";
15
+ import Button, { type ButtonVariant } from "@/components/(buttons)/button";
16
+ import Icon from "@/components/tools/label/Icon";
17
+ import Label from "@/components/tools/label/Label";
18
+ import Shape from "@/components/tools/shape/Shape";
19
+ import { useReduceMotion } from "@/components/tools/ReduceMotionContext";
20
+ import CustomScrollbar from "@/components/tools/CustomScrollbar";
21
+ import { ShapeInput } from "@/components/tools/shape/ShapePaths";
22
+ import ScrollShadow from "@/components/(layout)/scrollShadow/ScrollShadow";
23
+
24
+ export type ModalVariant =
25
+ | "default"
26
+ | "primary"
27
+ | "secondary"
28
+ | "tertiary"
29
+ | "success"
30
+ | "error";
31
+ export type ModalSize = "xs" | "sm" | "md" | "lg" | "cover";
32
+ export type ModalPlacement = "auto" | "center" | "top" | "bottom";
33
+
34
+ interface ModalProps {
35
+ isPresented: boolean;
36
+ onOpenChange: (open: boolean) => void;
37
+ isDismissable?: boolean;
38
+ isKeyboardDismissDisabled?: boolean;
39
+ role?: "modal" | "alertmodal";
40
+ size?: ModalSize;
41
+ placement?: ModalPlacement;
42
+ // Tints the backdrop and forces the Footer's cancel/confirm button styles
43
+ // (outlined / {variant}-bold) regardless of whatever variant props those
44
+ // buttons carry on the call site.
45
+ variant?: ModalVariant;
46
+ style?: React.CSSProperties;
47
+ children?: React.ReactNode;
48
+ }
49
+
50
+ // Button has no success-bold or default-bold — those two fall back to
51
+ // primary-bold.
52
+ const CONFIRM_BUTTON_VARIANT: Record<ModalVariant, ButtonVariant> = {
53
+ default: "primary-bold",
54
+ primary: "primary-bold",
55
+ secondary: "secondary-bold",
56
+ tertiary: "tertiary-bold",
57
+ success: "primary-bold",
58
+ error: "error-bold",
59
+ };
60
+
61
+ // Spread before setting `variant` on a cloned Button — Button's own boolean
62
+ // shorthand props (primary, error, outlined, ...) take priority over
63
+ // `variant` internally, so any boolean the call site set has to be cleared
64
+ // first or the forced variant silently loses.
65
+ const RESET_BUTTON_BOOLEAN_VARIANTS: Partial<
66
+ React.ComponentProps<typeof Button>
67
+ > = {
68
+ primary: undefined,
69
+ "primary-bold": undefined,
70
+ secondary: undefined,
71
+ "secondary-bold": undefined,
72
+ tertiary: undefined,
73
+ "tertiary-bold": undefined,
74
+ error: undefined,
75
+ "error-bold": undefined,
76
+ outlined: undefined,
77
+ text: undefined,
78
+ link: undefined,
79
+ };
80
+
81
+ const FOCUSABLE_SELECTOR =
82
+ 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
83
+
84
+ function getFocusable(container: HTMLElement): HTMLElement[] {
85
+ return Array.from(
86
+ container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),
87
+ ).filter((el) => el.offsetParent !== null);
88
+ }
89
+
90
+ function iconColors(variant: ModalVariant = "default") {
91
+ if (variant === "default") {
92
+ return {
93
+ bg: "var(--md-sys-color-surface-container-high)",
94
+ fg: "var(--md-sys-color-on-surface-variant)",
95
+ };
96
+ }
97
+ return {
98
+ bg: `var(--md-sys-color-${variant}-container)`,
99
+ fg: `var(--md-sys-color-on-${variant}-container)`,
100
+ };
101
+ }
102
+
103
+ const SIZE_STYLES: Record<ModalSize, React.CSSProperties> = {
104
+ xs: { minWidth: 280, maxWidth: 360 },
105
+ sm: { minWidth: 360, maxWidth: 420 },
106
+ md: { minWidth: 400, maxWidth: 520 },
107
+ lg: { minWidth: 480, maxWidth: 680 },
108
+ cover: { width: "94vw", maxWidth: 1100 },
109
+ };
110
+
111
+ function overlayAlignItems(placement: ModalPlacement) {
112
+ switch (placement) {
113
+ case "top":
114
+ return "flex-start";
115
+ case "bottom":
116
+ return "flex-end";
117
+ default:
118
+ return "center";
119
+ }
120
+ }
121
+
122
+ const modalStyle: React.CSSProperties = {
123
+ position: "relative",
124
+ display: "flex",
125
+ flexDirection: "column",
126
+ alignItems: "center",
127
+ justifyContent: "space-between",
128
+ width: "min-content",
129
+ height: "auto",
130
+ minHeight: 200,
131
+ maxWidth: "100dvw",
132
+ maxHeight: "90dvh",
133
+ margin: "5dvh 0",
134
+ overflow: "hidden",
135
+ scrollBehavior: "smooth",
136
+ borderRadius: "var(--borderRadius-l)",
137
+ boxShadow:
138
+ "0 0 0 1px var(--globalUIBorderCard),0 1px 1px rgba(0, 0, 0, 0.1),0 1px 3px rgba(0, 0, 0, 0.1),0 2px 6px rgba(0, 0, 0, 0.1)",
139
+ zIndex: 100002,
140
+ backgroundColor: "var(--md-sys-color-surface-container-low)",
141
+ };
142
+ const headerBaseStyle: React.CSSProperties = {
143
+ flexShrink: 0,
144
+ width: "100%",
145
+ display: "flex",
146
+ alignItems: "center",
147
+ justifyContent: "flex-start",
148
+ gap: 0,
149
+ padding: "12px",
150
+ background: "var(--md-sys-color-surface-container-low)",
151
+ };
152
+
153
+ const footerBaseStyle: React.CSSProperties = {
154
+ flexShrink: 0,
155
+ display: "flex",
156
+ alignItems: "center",
157
+ gap: 12,
158
+ justifyContent: "space-between",
159
+ width: "100%",
160
+ padding: "12px",
161
+ background: "var(--md-sys-color-surface-container-low)",
162
+ };
163
+
164
+ // flex/minHeight (not height: "fit-content") is what actually makes this the
165
+ // height-constrained scroll region within the modal — ScrollShadow's own
166
+ // overflow-y: auto only ever clips/scrolls if its box is bounded, otherwise
167
+ // it just grows to fit content and never overflows. No padding here — the
168
+ // shadow overlays are direct children of this element and need to span its
169
+ // full width/height to sit flush against the modal edges; padding belongs on
170
+ // contentInnerStyle instead, one level in.
171
+ const contentStyle: React.CSSProperties = {
172
+ flex: "1 1 auto",
173
+ minHeight: 0,
174
+ width: "100%",
175
+ };
176
+
177
+ const contentInnerStyle: React.CSSProperties = {
178
+ display: "flex",
179
+ alignItems: "flex-start",
180
+ justifyContent: "space-between",
181
+ flexDirection: "column",
182
+ gap: 24,
183
+ width: "100%",
184
+ minHeight: "100%",
185
+ color: "var(--md-sys-color-on-surface-variant)",
186
+ padding: 12,
187
+ };
188
+
189
+ interface ModalContextValue {
190
+ close: () => void;
191
+ scrollRef: React.RefObject<HTMLDivElement | null>;
192
+ scrolledFromTop: boolean;
193
+ canScrollDown: boolean;
194
+ scrollByPage: () => void;
195
+ variant: ModalVariant;
196
+ titleId: string;
197
+ descriptionId: string;
198
+ }
199
+
200
+ const ModalContext = createContext<ModalContextValue | null>(null);
201
+
202
+ function useModalContext(component: string) {
203
+ const ctx = useContext(ModalContext);
204
+ if (!ctx) {
205
+ throw new Error(`<Modal.${component}> must be rendered inside <Modal>`);
206
+ }
207
+ return ctx;
208
+ }
209
+
210
+ function Modal({
211
+ isPresented,
212
+ onOpenChange,
213
+ isDismissable = false,
214
+ // Alert modals guard destructive actions, so ESC stays enabled by default —
215
+ // this is the one place we diverge from HeroUI's stricter default, to keep
216
+ // the shortcut this design system already shipped with.
217
+ isKeyboardDismissDisabled = false,
218
+ role = "alertmodal",
219
+ size = "md",
220
+ placement = "auto",
221
+ variant = "default",
222
+ style,
223
+ children,
224
+ }: ModalProps) {
225
+ const rm = useReduceMotion();
226
+ useBodyScrollLock(isPresented);
227
+ const [mounted, setMounted] = useState(false);
228
+ // Portal-safety: defer createPortal until after client hydration, which
229
+ // can only be detected post-mount.
230
+ // eslint-disable-next-line react-hooks/set-state-in-effect
231
+ useEffect(() => setMounted(true), []);
232
+
233
+ const titleId = useId();
234
+ const descriptionId = useId();
235
+
236
+ const close = useCallback(() => onOpenChange(false), [onOpenChange]);
237
+
238
+ const surfaceRef = useRef<HTMLDivElement>(null);
239
+ const previouslyFocused = useRef<HTMLElement | null>(null);
240
+
241
+ // Focus enters the modal on open and returns to whatever triggered it on close.
242
+ useEffect(() => {
243
+ if (!isPresented) return;
244
+ previouslyFocused.current = document.activeElement as HTMLElement | null;
245
+ const raf = requestAnimationFrame(() => {
246
+ const el = surfaceRef.current;
247
+ if (!el) return;
248
+ const focusable = getFocusable(el);
249
+ (focusable[0] ?? el).focus();
250
+ });
251
+ return () => {
252
+ cancelAnimationFrame(raf);
253
+ previouslyFocused.current?.focus?.();
254
+ };
255
+ }, [isPresented]);
256
+
257
+ // Escape dismisses (unless disabled); Tab is trapped inside the modal.
258
+ useEffect(() => {
259
+ if (!isPresented) return;
260
+ const handleKeyDown = (e: KeyboardEvent) => {
261
+ if (e.key === "Escape") {
262
+ if (!isKeyboardDismissDisabled) {
263
+ e.preventDefault();
264
+ close();
265
+ }
266
+ return;
267
+ }
268
+ if (e.key !== "Tab") return;
269
+ const el = surfaceRef.current;
270
+ if (!el) return;
271
+ const focusable = getFocusable(el);
272
+ if (focusable.length === 0) {
273
+ e.preventDefault();
274
+ return;
275
+ }
276
+ const first = focusable[0];
277
+ const last = focusable[focusable.length - 1];
278
+ const active = document.activeElement;
279
+ if (e.shiftKey) {
280
+ if (active === first || !el.contains(active)) {
281
+ e.preventDefault();
282
+ last.focus();
283
+ }
284
+ } else if (active === last || !el.contains(active)) {
285
+ e.preventDefault();
286
+ first.focus();
287
+ }
288
+ };
289
+ window.addEventListener("keydown", handleKeyDown);
290
+ return () => window.removeEventListener("keydown", handleKeyDown);
291
+ }, [isPresented, isKeyboardDismissDisabled, close]);
292
+
293
+ const handleOverlayClick = useCallback(
294
+ (e: React.MouseEvent) => {
295
+ if (e.target !== e.currentTarget) return;
296
+ if (isDismissable) close();
297
+ },
298
+ [isDismissable, close],
299
+ );
300
+
301
+ const scrollRef = useRef<HTMLDivElement>(null);
302
+ const [canScrollDown, setCanScrollDown] = useState(false);
303
+ const [scrolledFromTop, setScrolledFromTop] = useState(false);
304
+
305
+ const checkScroll = useCallback(() => {
306
+ const el = scrollRef.current;
307
+ if (!el) return;
308
+ setCanScrollDown(el.scrollHeight - el.scrollTop - el.clientHeight > 1);
309
+ setScrolledFromTop(el.scrollTop > 0);
310
+ }, []);
311
+
312
+ useEffect(() => {
313
+ const el = scrollRef.current;
314
+ if (!el || !isPresented) return;
315
+ checkScroll();
316
+ el.addEventListener("scroll", checkScroll, { passive: true });
317
+ window.addEventListener("resize", checkScroll);
318
+ return () => {
319
+ el.removeEventListener("scroll", checkScroll);
320
+ window.removeEventListener("resize", checkScroll);
321
+ };
322
+ }, [checkScroll, isPresented]);
323
+
324
+ // One "page" short of the full viewport height, so the next screen always
325
+ // overlaps the last line or two of what was already visible — keeps
326
+ // reading context instead of jumping to an unfamiliar cut point.
327
+ const scrollByPage = useCallback(() => {
328
+ const el = scrollRef.current;
329
+ if (!el) return;
330
+ el.scrollBy({ top: el.clientHeight - 24, behavior: "smooth" });
331
+ }, []);
332
+
333
+ const overlayStyle = useMemo<React.CSSProperties>(
334
+ () => ({
335
+ position: "fixed",
336
+ top: 0,
337
+ left: 0,
338
+ width: "100%",
339
+ height: "100%",
340
+ background:
341
+ variant === "default"
342
+ ? "rgba(0, 0, 0, 0.4)"
343
+ : `linear-gradient(to bottom, rgba(0, 0, 0, 0.4), color-mix(in srgb, var(--md-sys-color-${variant}-container) 50%, transparent))`,
344
+ backdropFilter: "blur(12px)",
345
+ WebkitBackdropFilter: "blur(12px)",
346
+ display: "flex",
347
+ alignItems: overlayAlignItems(placement),
348
+ justifyContent: "center",
349
+ zIndex: 100000,
350
+ }),
351
+ [placement, variant],
352
+ );
353
+
354
+ const contextValue = useMemo<ModalContextValue>(
355
+ () => ({
356
+ close,
357
+ scrollRef,
358
+ scrolledFromTop,
359
+ canScrollDown,
360
+ scrollByPage,
361
+ variant,
362
+ titleId,
363
+ descriptionId,
364
+ }),
365
+ [
366
+ close,
367
+ scrollRef,
368
+ scrolledFromTop,
369
+ canScrollDown,
370
+ scrollByPage,
371
+ variant,
372
+ titleId,
373
+ descriptionId,
374
+ ],
375
+ );
376
+ const childArray = React.Children.toArray(children);
377
+ const headerChild = childArray.find(
378
+ (child) => React.isValidElement(child) && child.type === ModalHeader,
379
+ );
380
+ const footerChild = childArray.find(
381
+ (child) => React.isValidElement(child) && child.type === ModalFooter,
382
+ );
383
+ const middleChildren = childArray.filter(
384
+ (child) =>
385
+ !(
386
+ React.isValidElement(child) &&
387
+ (child.type === ModalHeader || child.type === ModalFooter)
388
+ ),
389
+ );
390
+
391
+ if (!mounted) return null;
392
+ return createPortal(
393
+ <MotionConfig reducedMotion={rm ? "always" : "never"}>
394
+ <AnimatePresence>
395
+ {isPresented && (
396
+ <motion.div
397
+ initial={{ opacity: 0 }}
398
+ animate={{ opacity: 1 }}
399
+ exit={{ opacity: 0 }}
400
+ style={overlayStyle}
401
+ onClick={handleOverlayClick}
402
+ >
403
+ <motion.div
404
+ ref={surfaceRef}
405
+ role={role}
406
+ aria-modal="true"
407
+ aria-labelledby={titleId}
408
+ aria-describedby={descriptionId}
409
+ tabIndex={-1}
410
+ initial={{ opacity: 0, scale: 1.1 }}
411
+ animate={{ opacity: 1, scale: 1 }}
412
+ exit={{ opacity: 0 }}
413
+ transition={{ duration: 0.3, ease: [0.45, 0.47, 0, 1.48] }}
414
+ style={{ ...modalStyle, ...SIZE_STYLES[size], ...style }}
415
+ className="a11y-modal-surface"
416
+ >
417
+ <ModalContext.Provider value={contextValue}>
418
+ {headerChild}
419
+ <div
420
+ style={{
421
+ position: "relative",
422
+ display: "flex",
423
+ flexDirection: "column",
424
+ flex: "1 1 auto",
425
+ minHeight: 0,
426
+ width: "100%",
427
+ }}
428
+ >
429
+ {/* middleChildren is Modal.Content, which now renders
430
+ ScrollShadow as the actual scroll container — no
431
+ separate scrollRef-holding wrapper needed here
432
+ anymore, that would just create a second (broken)
433
+ nested scroll container. */}
434
+ {middleChildren}
435
+ <CustomScrollbar targetRef={scrollRef} />
436
+ </div>
437
+ {footerChild}
438
+ </ModalContext.Provider>
439
+ </motion.div>
440
+ </motion.div>
441
+ )}
442
+ </AnimatePresence>
443
+ </MotionConfig>,
444
+ document.body,
445
+ );
446
+ }
447
+
448
+ type ModalHeaderProps = {
449
+ title: string;
450
+ withIcon?: {
451
+ systemName: string;
452
+ variant?: ModalVariant;
453
+ shapePath: ShapeInput;
454
+ };
455
+ closeTrigger?: boolean;
456
+ style?: React.CSSProperties;
457
+ };
458
+
459
+ function ModalHeader({
460
+ title,
461
+ withIcon,
462
+ closeTrigger,
463
+ style,
464
+ }: ModalHeaderProps) {
465
+ const { scrolledFromTop, titleId, close, variant } =
466
+ useModalContext("Header");
467
+ const colors = withIcon ? iconColors(withIcon.variant) : null;
468
+ return (
469
+ <div
470
+ style={{
471
+ ...headerBaseStyle,
472
+ borderBottom: `1px solid ${scrolledFromTop ? "var(--globalUIBorder)" : "transparent"}`,
473
+ transition: "border-color var(--transition-expressive-color)",
474
+ ...style,
475
+ }}
476
+ >
477
+ {withIcon && colors && (
478
+ <Shape
479
+ systemName={withIcon.systemName}
480
+ shapePath={withIcon.shapePath}
481
+ background={colors.bg}
482
+ color={colors.fg}
483
+ size="sm"
484
+ isHovered={false}
485
+ interactive={false}
486
+ />
487
+ )}
488
+ <h4
489
+ id={titleId}
490
+ style={{
491
+ flex: 1,
492
+ margin: 0,
493
+ padding: "0 12px",
494
+ fontWeight: 500,
495
+ color:
496
+ variant === "default"
497
+ ? "var(--md-sys-color-on-surface)"
498
+ : `var(--md-sys-color-on-${variant}-container)`,
499
+ }}
500
+ >
501
+ {title}
502
+ </h4>
503
+ {closeTrigger && (
504
+ <Button
505
+ text
506
+ onClick={close}
507
+ aria-label="Close"
508
+ style={{
509
+ marginLeft: "auto",
510
+ minWidth: 44,
511
+ color: "var(--md-sys-color-secondary)",
512
+ }}
513
+ >
514
+ <Icon systemName="close" />
515
+ </Button>
516
+ )}
517
+ </div>
518
+ );
519
+ }
520
+
521
+ type ModalContentProps = {
522
+ children?: React.ReactNode;
523
+ style?: React.CSSProperties;
524
+ };
525
+
526
+ function ModalContent({ children, style }: ModalContentProps) {
527
+ const { descriptionId, scrollRef } = useModalContext("Content");
528
+ return (
529
+ <ScrollShadow ref={scrollRef} variant="low" style={contentStyle}>
530
+ <div id={descriptionId} style={{ ...contentInnerStyle, ...style }}>
531
+ {children}
532
+ </div>
533
+ </ScrollShadow>
534
+ );
535
+ }
536
+
537
+ type ModalFooterProps = {
538
+ children?: React.ReactNode;
539
+ style?: React.CSSProperties;
540
+ };
541
+
542
+ // Scans its children for plain <Button value="cancel"> / <Button
543
+ // value="confirm"> — no dedicated trigger components, just the native
544
+ // `value` attribute Button already forwards. Cancel is always forced to
545
+ // "outlined" and always closes after your own onClick runs. Confirm is
546
+ // always forced to {variant}-bold and only gets intercepted while there's
547
+ // more to scroll (paging down instead of firing your handler); once
548
+ // scrolled to the end your onClick runs unmodified and you decide whether to
549
+ // close. Whatever variant/boolean props the button carries at the call site
550
+ // are overridden either way — that styling isn't optional per-button.
551
+ // data-continue-label on the same button (also just a plain forwarded
552
+ // attribute) swaps its label while that's active — no icon, label only.
553
+ function ModalFooter({ children, style }: ModalFooterProps) {
554
+ const { canScrollDown, scrollByPage, close, variant } =
555
+ useModalContext("Footer");
556
+
557
+ const processedChildren = React.Children.map(children, (child) => {
558
+ if (!React.isValidElement<React.ComponentProps<typeof Button>>(child)) {
559
+ return child;
560
+ }
561
+
562
+ if (child.props.value === "cancel") {
563
+ return React.cloneElement(child, {
564
+ ...RESET_BUTTON_BOOLEAN_VARIANTS,
565
+ variant: "outlined",
566
+ onClick: (e: React.MouseEvent<HTMLButtonElement>) => {
567
+ child.props.onClick?.(e);
568
+ close();
569
+ },
570
+ });
571
+ }
572
+
573
+ if (child.props.value === "confirm") {
574
+ const confirmVariant = CONFIRM_BUTTON_VARIANT[variant];
575
+ if (!canScrollDown) {
576
+ return React.cloneElement(child, {
577
+ ...RESET_BUTTON_BOOLEAN_VARIANTS,
578
+ variant: confirmVariant,
579
+ });
580
+ }
581
+ const continueLabel = (child.props as Record<string, unknown>)[
582
+ "data-continue-label"
583
+ ] as string | undefined;
584
+ return React.cloneElement(child, {
585
+ ...RESET_BUTTON_BOOLEAN_VARIANTS,
586
+ variant: confirmVariant,
587
+ onClick: () => scrollByPage(),
588
+ children: continueLabel ? (
589
+ <Label label={continueLabel} />
590
+ ) : (
591
+ child.props.children
592
+ ),
593
+ });
594
+ }
595
+
596
+ return child;
597
+ });
598
+
599
+ return (
600
+ <div
601
+ style={{
602
+ ...footerBaseStyle,
603
+ borderTop: `1px solid ${canScrollDown ? "var(--globalUIBorder)" : "transparent"}`,
604
+ transition: "border-color var(--transition-expressive-color)",
605
+ ...style,
606
+ }}
607
+ >
608
+ {processedChildren}
609
+ </div>
610
+ );
611
+ }
612
+
613
+ export default Object.assign(Modal, {
614
+ Header: ModalHeader,
615
+ Content: ModalContent,
616
+ Footer: ModalFooter,
617
+ });
618
+
619
+ /* Example usage:
620
+
621
+ <Modal isPresented={open} onOpenChange={setOpen} size="sm">
622
+ <Modal.Header
623
+ title="Delete this item?"
624
+ withIcon={{ systemName: "delete", variant: "error" }}
625
+ closeTrigger
626
+ />
627
+ <Modal.Content>
628
+ <p>This action cannot be undone.</p>
629
+ </Modal.Content>
630
+ <Modal.Footer>
631
+ <Button value="cancel" text>
632
+ <Label label="Cancel" />
633
+ </Button>
634
+ <Button value="confirm" error onClick={handleDelete}>
635
+ <Label label="Delete" />
636
+ </Button>
637
+ </Modal.Footer>
638
+ </Modal>
639
+
640
+ // Long content — Confirm becomes "Continue" and pages down until you've
641
+ // scrolled to the end, then reverts to Accept and fires onClick as normal.
642
+ <Modal.Footer>
643
+ <Button value="cancel" text><Label label="Decline" /></Button>
644
+ <Button
645
+ value="confirm"
646
+ primary
647
+ onClick={handleAccept}
648
+ data-continue-label="Continue"
649
+ >
650
+ <Label label="Accept" />
651
+ </Button>
652
+ </Modal.Footer>
653
+
654
+ */