@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,568 @@
1
+ // drop.tsx
2
+ "use client";
3
+
4
+ import React, {
5
+ createContext,
6
+ useCallback,
7
+ useContext,
8
+ useEffect,
9
+ useRef,
10
+ useState,
11
+ isValidElement,
12
+ cloneElement,
13
+ } from "react";
14
+ import { motion, AnimatePresence, easeInOut, easeOut } from "framer-motion";
15
+ import Icon from "@/components/tools/label/Icon";
16
+ import styles from "./drop.module.css";
17
+
18
+ const EASE_EXPRESSIVE = [0.01, 1.25, 0.23, 1.01] as const;
19
+ const MORPH = { duration: 0.4, ease: EASE_EXPRESSIVE };
20
+
21
+ // .drop shrinks to this scale while a submenu is open; .submenuCard (nested
22
+ // inside .drop) counter-scales by the reciprocal so it renders at 1:1
23
+ // despite inheriting its ancestor's transform.
24
+ const DROP_SUBMENU_SCALE = 0.94;
25
+ const SUBMENU_COUNTER_SCALE = 1 / DROP_SUBMENU_SCALE;
26
+
27
+ //MARK: types
28
+
29
+ type TriggerProps = {
30
+ onClick?: (e: React.MouseEvent) => void;
31
+ children?: React.ReactNode;
32
+ "aria-haspopup"?: React.AriaAttributes["aria-haspopup"];
33
+ "aria-expanded"?: React.AriaAttributes["aria-expanded"];
34
+ };
35
+
36
+ type RowProps = {
37
+ systemName?: string;
38
+ title?: string;
39
+ subtitle?: string;
40
+ href?: string;
41
+ onClick?: (e: React.MouseEvent<HTMLElement>) => void;
42
+ toggle?: boolean;
43
+ default?: boolean;
44
+ active?: boolean;
45
+ disabled?: boolean;
46
+ children?: React.ReactNode;
47
+ };
48
+
49
+ // Declarative marker only; its props are read via React.Children traversal
50
+ // in buildModel(), not accessed here.
51
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
52
+ function Row(_props: RowProps) {
53
+ return null;
54
+ }
55
+ Row.displayName = "Drop.Row";
56
+
57
+ type ContentProps = {
58
+ children?: React.ReactNode;
59
+ };
60
+
61
+ // Declarative marker, same as Row — buildModel() reads its children directly
62
+ // and skips row rendering entirely for it. Use this for anything that isn't
63
+ // itself a Row: a plain div, a form, a custom block — it renders as-is,
64
+ // untouched by .row/.dividerRow styling or the aria-hidden divider treatment.
65
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
+ function Content(_props: ContentProps) {
67
+ return null;
68
+ }
69
+ Content.displayName = "Drop.Content";
70
+
71
+ type MenuNode = {
72
+ kind: "row" | "raw" | "content";
73
+ key: string;
74
+ id: string;
75
+ element?: React.ReactNode;
76
+ systemName?: string;
77
+ title?: string;
78
+ subtitle?: string;
79
+ href?: string;
80
+ onClick?: (e: React.MouseEvent<HTMLElement>) => void;
81
+ toggle?: boolean;
82
+ default?: boolean;
83
+ active?: boolean;
84
+ disabled?: boolean;
85
+ children: MenuNode[];
86
+ };
87
+
88
+ type MenuContextValue = {
89
+ submenuIcon: string;
90
+ activeIcon: string;
91
+ openSubmenuIndex: number | null;
92
+ openSubmenu: (index: number, el: HTMLElement | null) => void;
93
+ closeSubmenu: () => void;
94
+ closeAll: () => void;
95
+ isActive: (id: string) => boolean;
96
+ toggleActive: (id: string) => void;
97
+ };
98
+ const MenuContext = createContext<MenuContextValue | null>(null);
99
+
100
+ //MARK: model builder
101
+
102
+ function buildModel(children: React.ReactNode, prefix = ""): MenuNode[] {
103
+ return React.Children.toArray(children)
104
+ .filter((c): c is React.ReactElement => isValidElement(c))
105
+ .map((c, i) => {
106
+ const key = c.key != null ? String(c.key) : String(i);
107
+ const id = prefix ? `${prefix}/${key}` : key;
108
+
109
+ if (c.type === Content) {
110
+ const p = c.props as ContentProps;
111
+ return { kind: "content", key, id, element: p.children, children: [] };
112
+ }
113
+
114
+ if (c.type !== Row) {
115
+ return { kind: "raw", key, id, element: c, children: [] };
116
+ }
117
+
118
+ const p = c.props as RowProps;
119
+ return {
120
+ kind: "row",
121
+ key,
122
+ id,
123
+ systemName: p.systemName,
124
+ title: p.title,
125
+ subtitle: p.subtitle,
126
+ href: p.href,
127
+ onClick: p.onClick,
128
+ toggle: p.toggle,
129
+ default: p.default,
130
+ active: p.active,
131
+ disabled: p.disabled,
132
+ children: buildModel(p.children, id),
133
+ };
134
+ });
135
+ }
136
+
137
+ //MARK: row rendering
138
+
139
+ function RowContent({ node, active }: { node: MenuNode; active: boolean }) {
140
+ const ctx = useContext(MenuContext)!;
141
+ const iconName = active ? ctx.activeIcon : node.systemName;
142
+ const noIcon = active ? false : !node.systemName;
143
+ return (
144
+ <>
145
+ {iconName && <Icon systemName={iconName} />}
146
+ {(node.title || node.subtitle) && (
147
+ <span className={styles.rowText} data-noicon={noIcon || undefined}>
148
+ {node.title && <span className={styles.rowTitle}>{node.title}</span>}
149
+ {node.subtitle && (
150
+ <span className={styles.rowSubtitle}>{node.subtitle}</span>
151
+ )}
152
+ </span>
153
+ )}
154
+ </>
155
+ );
156
+ }
157
+
158
+ function LeafRow({ node }: { node: MenuNode }) {
159
+ const ctx = useContext(MenuContext)!;
160
+ const controlled = node.active !== undefined;
161
+ const active = controlled
162
+ ? !!node.active
163
+ : !!node.toggle && ctx.isActive(node.id);
164
+
165
+ const handle = (e: React.MouseEvent<HTMLElement>) => {
166
+ if (node.disabled) return;
167
+ if (node.toggle) {
168
+ if (!controlled) ctx.toggleActive(node.id);
169
+ node.onClick?.(e);
170
+ // Toggle rows don't close the whole menu, but a click anywhere in the
171
+ // main list should still dismiss an open submenu.
172
+ if (ctx.openSubmenuIndex != null) ctx.closeSubmenu();
173
+ return;
174
+ }
175
+ node.onClick?.(e);
176
+ ctx.closeAll();
177
+ };
178
+
179
+ return node.href && !node.toggle ? (
180
+ <a
181
+ className={styles.row}
182
+ data-active={active || undefined}
183
+ aria-disabled={node.disabled || undefined}
184
+ href={node.disabled ? undefined : node.href}
185
+ onClick={handle}
186
+ >
187
+ <RowContent node={node} active={active} />
188
+ </a>
189
+ ) : (
190
+ <button
191
+ type="button"
192
+ className={styles.row}
193
+ data-active={active || undefined}
194
+ aria-pressed={node.toggle ? active : undefined}
195
+ disabled={node.disabled}
196
+ onClick={handle}
197
+ >
198
+ <RowContent node={node} active={active} />
199
+ </button>
200
+ );
201
+ }
202
+
203
+ function SubmenuTriggerRow({ node, index }: { node: MenuNode; index: number }) {
204
+ const ctx = useContext(MenuContext)!;
205
+ const ref = useRef<HTMLButtonElement>(null);
206
+ const isOpen = ctx.openSubmenuIndex === index;
207
+ return (
208
+ <button
209
+ ref={ref}
210
+ type="button"
211
+ className={styles.row}
212
+ aria-haspopup="menu"
213
+ aria-expanded={isOpen}
214
+ onClick={() => ctx.openSubmenu(index, ref.current)}
215
+ >
216
+ <RowContent node={node} active={false} />
217
+ <span className={styles.chev}>
218
+ <Icon systemName={ctx.submenuIcon} />
219
+ </span>
220
+ </button>
221
+ );
222
+ }
223
+
224
+ //MARK: DropDown
225
+
226
+ type DropDownProps = {
227
+ submenuIcon?: string;
228
+ activeIcon?: string;
229
+ exclusive?: boolean;
230
+ multiSelect?: boolean;
231
+ placement?: "bottom-start" | "bottom-end";
232
+ className?: string;
233
+ style?: React.CSSProperties;
234
+ children: React.ReactNode;
235
+ hideChevron?: boolean;
236
+ // Uncontrolled by default (own internal open state, as before — every
237
+ // existing call site keeps working unchanged). Pass both to drive it
238
+ // from outside instead — e.g. a ComboBox/Autocomplete that needs to
239
+ // open the panel on input focus/typing, not just a trigger click.
240
+ isOpen?: boolean;
241
+ onOpenChange?: (open: boolean) => void;
242
+ };
243
+
244
+ function DropDown({
245
+ submenuIcon = "chevron_right",
246
+ activeIcon = "check_small",
247
+ exclusive = true,
248
+ multiSelect,
249
+ placement = "bottom-start",
250
+ className,
251
+ style,
252
+ hideChevron = false,
253
+ children,
254
+ isOpen: controlledOpen,
255
+ onOpenChange,
256
+ }: DropDownProps) {
257
+ const childArr = React.Children.toArray(children);
258
+ const [trigger, ...itemChildren] = childArr;
259
+ const model = buildModel(itemChildren);
260
+ // Content nodes hold arbitrary caller-sized content, not text rows — the
261
+ // usual min/max-width band + overflow:auto clipping is the wrong model
262
+ // for them, so .drop switches to a bare, uncapped, unclipped mode via
263
+ // [data-content] whenever one is present.
264
+ const hasContent = model.some((n) => n.kind === "content");
265
+ const isExclusive = multiSelect !== undefined ? !multiSelect : exclusive;
266
+
267
+ //MARK: state
268
+
269
+ const isControlled = controlledOpen !== undefined;
270
+ const [internalOpen, setInternalOpen] = useState(false);
271
+ const open = isControlled ? controlledOpen : internalOpen;
272
+ // Stable identity (unlike a plain closure re-created every render) so
273
+ // closeAll/closeSubmenu below can safely list it as a dependency —
274
+ // takes `open` as an explicit param instead of closing over the
275
+ // outer variable, which is what makes that stability sound.
276
+ const setOpen = useCallback(
277
+ (next: boolean | ((prev: boolean) => boolean), current: boolean) => {
278
+ const resolved = typeof next === "function" ? next(current) : next;
279
+ if (!isControlled) setInternalOpen(resolved);
280
+ onOpenChange?.(resolved);
281
+ },
282
+ [isControlled, onOpenChange],
283
+ );
284
+ const [openSubmenuIndex, setOpenSubmenuIndex] = useState<number | null>(null);
285
+ const [submenuTop, setSubmenuTop] = useState(0);
286
+
287
+ const [activeIds, setActiveIds] = useState<Set<string>>(() => {
288
+ const defaults = new Set<string>();
289
+ const walk = (nodes: MenuNode[]) =>
290
+ nodes.forEach((n) => {
291
+ if (n.default && !(isExclusive && defaults.size > 0))
292
+ defaults.add(n.id);
293
+ walk(n.children);
294
+ });
295
+ walk(model);
296
+ return defaults;
297
+ });
298
+
299
+ const isActive = (id: string) => activeIds.has(id);
300
+ const toggleActive = (id: string) => {
301
+ setActiveIds((prev) => {
302
+ const next = new Set(prev);
303
+ const was = next.has(id);
304
+ if (was && isExclusive) return prev;
305
+ if (was) next.delete(id);
306
+ else {
307
+ if (isExclusive) next.clear();
308
+ next.add(id);
309
+ }
310
+ return next;
311
+ });
312
+ };
313
+
314
+ const rootRef = useRef<HTMLDivElement>(null);
315
+ const menuRef = useRef<HTMLDivElement>(null);
316
+
317
+ //MARK: open / close handlers
318
+
319
+ const closeAll = useCallback(() => {
320
+ setOpenSubmenuIndex(null);
321
+ setOpen(false, open);
322
+ }, [setOpen, open]);
323
+ const closeSubmenu = useCallback(() => setOpenSubmenuIndex(null), []);
324
+
325
+ const openSubmenu = (index: number, el: HTMLElement | null) => {
326
+ if (el && menuRef.current) {
327
+ setSubmenuTop(
328
+ el.getBoundingClientRect().top -
329
+ menuRef.current.getBoundingClientRect().top,
330
+ );
331
+ }
332
+ setOpenSubmenuIndex(index);
333
+ };
334
+
335
+ //MARK: outside click / escape
336
+
337
+ useEffect(() => {
338
+ if (!open) return;
339
+ const onDown = (e: MouseEvent) => {
340
+ if (rootRef.current && !rootRef.current.contains(e.target as Node)) {
341
+ if (openSubmenuIndex != null) closeSubmenu();
342
+ else closeAll();
343
+ }
344
+ };
345
+ const onKey = (e: KeyboardEvent) => {
346
+ if (e.key !== "Escape") return;
347
+ if (openSubmenuIndex != null) closeSubmenu();
348
+ else closeAll();
349
+ };
350
+ // Scrolling always closes the whole dropdown, submenu included — unlike
351
+ // outside-click/Escape, this never just steps back to the main list.
352
+ // Scrolling *inside* the dropdown's own scrollable list is excluded —
353
+ // that's just paging through a long menu, not a dismiss gesture.
354
+ const onScroll = (e: Event) => {
355
+ if (rootRef.current && rootRef.current.contains(e.target as Node)) return;
356
+ closeAll();
357
+ };
358
+ document.addEventListener("mousedown", onDown);
359
+ document.addEventListener("keydown", onKey);
360
+ window.addEventListener("scroll", onScroll, { capture: true });
361
+ return () => {
362
+ document.removeEventListener("mousedown", onDown);
363
+ document.removeEventListener("keydown", onKey);
364
+ window.removeEventListener("scroll", onScroll, { capture: true });
365
+ };
366
+ }, [open, openSubmenuIndex, closeAll, closeSubmenu]);
367
+
368
+ const submenuOpen = openSubmenuIndex != null;
369
+ const submenuNode = submenuOpen ? model[openSubmenuIndex!] : null;
370
+
371
+ const ctx: MenuContextValue = {
372
+ submenuIcon,
373
+ activeIcon,
374
+ openSubmenuIndex,
375
+ openSubmenu,
376
+ closeSubmenu,
377
+ closeAll,
378
+ isActive,
379
+ toggleActive,
380
+ };
381
+
382
+ //MARK: render
383
+
384
+ return (
385
+ <MenuContext.Provider value={ctx}>
386
+ <div
387
+ ref={rootRef}
388
+ className={[styles.root, className].filter(Boolean).join(" ")}
389
+ style={style}
390
+ >
391
+ {isValidElement<TriggerProps>(trigger)
392
+ ? cloneElement(trigger, {
393
+ // Uncontrolled: clicking the trigger is the only way open
394
+ // ever changes, so it owns toggling it. Controlled: the
395
+ // consumer already owns open/close from outside (e.g. an
396
+ // Autocomplete/ComboBox opening on input focus/typing
397
+ // rather than a click) — forcing a second, competing
398
+ // click-toggle on top of that would fight it, so this
399
+ // just passes the trigger's own onClick through unchanged.
400
+ onClick: isControlled
401
+ ? trigger.props.onClick
402
+ : (e: React.MouseEvent) => {
403
+ trigger.props.onClick?.(e);
404
+ // Closing via the trigger — reset any open submenu
405
+ // too, same as closeAll() does for outside-click.
406
+ if (open) setOpenSubmenuIndex(null);
407
+ setOpen((o) => !o, open);
408
+ },
409
+ "aria-haspopup": "menu",
410
+ "aria-expanded": open,
411
+ children: (
412
+ <>
413
+ {trigger.props.children}
414
+ {!hideChevron && (
415
+ <span
416
+ style={{
417
+ display: "inline-flex",
418
+ fontSize: 18,
419
+ marginLeft: 6,
420
+ transform: open ? "rotate(180deg)" : "rotate(0deg)",
421
+ transition:
422
+ "transform var(--transition-expressive-slow)",
423
+ }}
424
+ >
425
+ <Icon systemName="keyboard_arrow_down" />
426
+ </span>
427
+ )}
428
+ </>
429
+ ),
430
+ })
431
+ : trigger}
432
+ <AnimatePresence>
433
+ {open && (
434
+ <motion.div
435
+ ref={menuRef}
436
+ className={styles.drop}
437
+ data-placement={placement}
438
+ data-submenu-open={submenuOpen || undefined}
439
+ data-content={hasContent ? "" : undefined}
440
+ // "auto" clips + scrolls the main list (and gives the
441
+ // height-grow entrance its reveal clip); switches to
442
+ // "visible" while a submenu is open so its absolutely
443
+ // positioned card — not part of this box's own flow sizing —
444
+ // isn't clipped to the main list's bounds.
445
+ style={{
446
+ overflow: hasContent
447
+ ? "visible"
448
+ : submenuOpen
449
+ ? "visible"
450
+ : "auto",
451
+ }}
452
+ initial={{ opacity: 0, height: 48, scale: 0.94, y: -24 }}
453
+ animate={{
454
+ opacity: 1,
455
+ height: "fit-content",
456
+ scale: submenuOpen ? DROP_SUBMENU_SCALE : 1,
457
+ y: 0,
458
+ }}
459
+ exit={{ opacity: 0, height: 48, scale: 0.94, y: -12 }}
460
+ transition={{
461
+ ...MORPH,
462
+ opacity: {
463
+ duration: 0.1,
464
+ ease: easeOut,
465
+ },
466
+ }}
467
+ >
468
+ <ul
469
+ className={styles.list}
470
+ data-dimmed={submenuOpen || undefined}
471
+ >
472
+ {model.map((node, i) =>
473
+ node.kind === "raw" ? (
474
+ <li
475
+ key={node.key}
476
+ className={styles.dividerRow}
477
+ aria-hidden
478
+ >
479
+ {node.element}
480
+ </li>
481
+ ) : node.kind === "content" ? (
482
+ <li key={node.key} className={styles.contentRow}>
483
+ {node.element}
484
+ </li>
485
+ ) : node.children.length > 0 ? (
486
+ <li key={node.key}>
487
+ <SubmenuTriggerRow node={node} index={i} />
488
+ </li>
489
+ ) : (
490
+ <li key={node.key}>
491
+ <LeafRow node={node} />
492
+ </li>
493
+ ),
494
+ )}
495
+ </ul>
496
+
497
+ <AnimatePresence>
498
+ {submenuNode && (
499
+ <motion.div
500
+ className={styles.submenuCard}
501
+ style={{ top: submenuTop }}
502
+ // Counter-scales the parent .drop's simultaneous
503
+ // shrink so the submenu renders at 1:1, not 0.94x.
504
+ initial={{
505
+ opacity: 0,
506
+ scale: SUBMENU_COUNTER_SCALE,
507
+ height: 44,
508
+ marginTop: "-10px",
509
+ }}
510
+ animate={{
511
+ opacity: 1,
512
+ scale: SUBMENU_COUNTER_SCALE,
513
+ height: "fit-content",
514
+ marginTop: 0,
515
+ }}
516
+ exit={{
517
+ opacity: 0,
518
+ scale: SUBMENU_COUNTER_SCALE,
519
+ height: 44,
520
+ marginTop: "-10px",
521
+ }}
522
+ transition={{ ...MORPH, height: MORPH }}
523
+ >
524
+ <button
525
+ type="button"
526
+ className={styles.row}
527
+ aria-expanded
528
+ onClick={closeSubmenu}
529
+ >
530
+ <RowContent node={submenuNode} active={false} />
531
+ <span className={styles.chev}>
532
+ <Icon systemName="expand_more" />
533
+ </span>
534
+ </button>
535
+ <ul className={styles.submenuList}>
536
+ {submenuNode.children.map((child) =>
537
+ child.kind === "raw" ? (
538
+ <li
539
+ key={child.key}
540
+ className={styles.dividerRow}
541
+ aria-hidden
542
+ >
543
+ {child.element}
544
+ </li>
545
+ ) : child.kind === "content" ? (
546
+ <li key={child.key} className={styles.contentRow}>
547
+ {child.element}
548
+ </li>
549
+ ) : (
550
+ <li key={child.key}>
551
+ <LeafRow node={child} />
552
+ </li>
553
+ ),
554
+ )}
555
+ </ul>
556
+ </motion.div>
557
+ )}
558
+ </AnimatePresence>
559
+ </motion.div>
560
+ )}
561
+ </AnimatePresence>
562
+ </div>
563
+ </MenuContext.Provider>
564
+ );
565
+ }
566
+
567
+ const Drop = { Down: DropDown, Row, Content };
568
+ export default Drop;
@@ -0,0 +1,118 @@
1
+ "use client";
2
+ import React from "react";
3
+
4
+ // WebKit's UnitBezier algorithm — the same math browsers use to evaluate a
5
+ // CSS `cubic-bezier()` timing function. Lets JS-driven tweens move on the
6
+ // identical curve as a CSS `transition`, instead of approximating it with an
7
+ // unrelated easing shape (e.g. exponential decay).
8
+ export function cubicBezier(x1: number, y1: number, x2: number, y2: number) {
9
+ const cx = 3 * x1;
10
+ const bx = 3 * (x2 - x1) - cx;
11
+ const ax = 1 - cx - bx;
12
+ const cy = 3 * y1;
13
+ const by = 3 * (y2 - y1) - cy;
14
+ const ay = 1 - cy - by;
15
+
16
+ const sampleCurveX = (t: number) => ((ax * t + bx) * t + cx) * t;
17
+ const sampleCurveY = (t: number) => ((ay * t + by) * t + cy) * t;
18
+ const sampleCurveDerivativeX = (t: number) => (3 * ax * t + 2 * bx) * t + cx;
19
+
20
+ function solveCurveX(x: number, epsilon = 1e-6) {
21
+ let t = x;
22
+ for (let i = 0; i < 8; i++) {
23
+ const dx = sampleCurveX(t) - x;
24
+ if (Math.abs(dx) < epsilon) return t;
25
+ const d = sampleCurveDerivativeX(t);
26
+ if (Math.abs(d) < 1e-6) break;
27
+ t -= dx / d;
28
+ }
29
+ let lo = 0;
30
+ let hi = 1;
31
+ t = x;
32
+ if (t < lo) return lo;
33
+ if (t > hi) return hi;
34
+ while (lo < hi) {
35
+ const sample = sampleCurveX(t);
36
+ if (Math.abs(sample - x) < epsilon) return t;
37
+ if (x > sample) lo = t;
38
+ else hi = t;
39
+ t = (hi - lo) * 0.5 + lo;
40
+ }
41
+ return t;
42
+ }
43
+
44
+ return (x: number) => {
45
+ if (x <= 0) return 0;
46
+ if (x >= 1) return 1;
47
+ return sampleCurveY(solveCurveX(x));
48
+ };
49
+ }
50
+
51
+ // Matches this design system's PROGRESS_TRANSITION token ("1s linear") so
52
+ // anything tweened in JS with these defaults moves at the identical constant
53
+ // rate as that CSS transition — no easing curve, determinate progress isn't
54
+ // supposed to accelerate/decelerate.
55
+ export const DEFAULT_EASE = (t: number) => Math.max(0, Math.min(1, t));
56
+ export const DEFAULT_TWEEN_DURATION_MS = 1000;
57
+
58
+ export type Tween = { from: number; to: number; start: number | null };
59
+
60
+ export function makeTween(value: number): Tween {
61
+ return { from: value, to: value, start: null };
62
+ }
63
+
64
+ // Reads a tween's current value at `now`, retargeting from wherever it
65
+ // currently sits (not from scratch) if `target` has changed — the same
66
+ // "redirect mid-flight" behavior a CSS transition gets when its destination
67
+ // value changes before the previous transition finished.
68
+ export function readTween(
69
+ tween: Tween,
70
+ target: number,
71
+ now: number,
72
+ durationMs = DEFAULT_TWEEN_DURATION_MS,
73
+ ease = DEFAULT_EASE,
74
+ ): number {
75
+ const progressAt = (t: number | null) =>
76
+ t == null ? 1 : Math.min(1, (now - t) / durationMs);
77
+ if (tween.to !== target) {
78
+ const current = tween.from + (tween.to - tween.from) * ease(progressAt(tween.start));
79
+ tween.from = current;
80
+ tween.to = target;
81
+ tween.start = now;
82
+ }
83
+ return tween.from + (tween.to - tween.from) * ease(progressAt(tween.start));
84
+ }
85
+
86
+ export function snapTween(tween: Tween, value: number) {
87
+ tween.from = value;
88
+ tween.to = value;
89
+ tween.start = null;
90
+ }
91
+
92
+ /** Eases toward `target` on `PROGRESS_TRANSITION`'s own curve/duration by
93
+ * default, so a value derived from it in JS (e.g. a threshold check) crosses
94
+ * its boundary in sync with a sibling CSS transition animating the same
95
+ * underlying progress — not the instant the target prop changes. */
96
+ export function useEasedNumber(
97
+ target: number,
98
+ durationMs = DEFAULT_TWEEN_DURATION_MS,
99
+ ease = DEFAULT_EASE,
100
+ ): number {
101
+ const tweenRef = React.useRef<Tween | null>(null);
102
+ if (tweenRef.current == null) tweenRef.current = makeTween(target);
103
+ const [value, setValue] = React.useState(target);
104
+
105
+ React.useEffect(() => {
106
+ let frame: number;
107
+ const tick = (now: number) => {
108
+ const tween = tweenRef.current!;
109
+ setValue(readTween(tween, target, now, durationMs, ease));
110
+ const settled = tween.start == null || now - tween.start >= durationMs;
111
+ if (!settled) frame = requestAnimationFrame(tick);
112
+ };
113
+ frame = requestAnimationFrame(tick);
114
+ return () => cancelAnimationFrame(frame);
115
+ }, [target, durationMs, ease]);
116
+
117
+ return value;
118
+ }
@@ -1,7 +1,7 @@
1
- declare module "flubber" {
2
- export function interpolate(
3
- from: string,
4
- to: string,
5
- options?: { maxSegmentLength?: number },
6
- ): (t: number) => string;
1
+ declare module "flubber" {
2
+ export function interpolate(
3
+ from: string,
4
+ to: string,
5
+ options?: { maxSegmentLength?: number },
6
+ ): (t: number) => string;
7
7
  }