@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
@@ -1,399 +1,448 @@
1
- import React, {
2
- memo,
3
- useCallback,
4
- useContext,
5
- useEffect,
6
- useMemo,
7
- useRef,
8
- useState,
9
- } from "react";
10
- import { easeInOut, motion } from "framer-motion";
11
- import Icon from "@/components/tools/icon/icon";
12
- import {
13
- useNavRail,
14
- useHasHeader,
15
- NavFTBStickyContext,
16
- NavFTBEmbeddedContext,
17
- NavFTBGroupContext,
18
- } from "../NavContext";
19
- import { useReduceMotion } from "@/components/tools/ReduceMotionContext";
20
- import FadeContent from "@/components/tools/react-bits/FadeContent";
21
- import ProgressiveBlur from "@/components/tools/ProgressiveBlur";
22
- import styles from "./NavFTB.module.css";
23
- import { useTabIndicator } from "./useTabIndicator";
24
- import type {
25
- NavFTBProps,
26
- FTBRefProps,
27
- NavFTBGroupContextValue,
28
- } from "../NavContext";
29
- import MioCard from "@/components/layout/navigation/MioCard";
30
- import { Wrap } from "@/components/layout/navigation/Wrap";
31
- import type { ShapeType } from "@/components/tools/shape/ShapePaths";
32
- import { useBreakpoints } from "@/components/tools/mobileViewProvider";
33
-
34
- function FTBRef({ forLabel, children }: FTBRefProps) {
35
- const ctx = useContext(NavFTBGroupContext);
36
- if (!ctx) {
37
- if (process.env.NODE_ENV !== "production") {
38
- console.error("<FTB.Ref> must be used within <Nav.FTB>");
39
- }
40
- return null;
41
- }
42
- if (ctx.selectedLabel.toLowerCase() !== forLabel.toLowerCase()) return null;
43
- // Each tab's content mounts fresh when it becomes active, so FadeContent
44
- // replays its fade-from-bottom on every reveal. duration tuned snappy for a
45
- // tab switch (FadeContent defaults to 1000ms, too slow here).
46
- return (
47
- <FadeContent fadeFrom="bottom" blur={false} duration={300}>
48
- {children}
49
- </FadeContent>
50
- );
51
- }
52
-
53
- const NavFTBInner = memo(function NavFTB({
54
- tabs,
55
- id,
56
- onTabChange,
57
- activeTabId,
58
- inSection = false,
59
- children,
60
- }: NavFTBProps) {
61
- const [selected, setSelected] = useState(() => {
62
- if (activeTabId) {
63
- const idx = tabs.findIndex(
64
- (t) => t.label.toLowerCase() === activeTabId.toLowerCase(),
65
- );
66
- return idx >= 0 ? idx : 0;
67
- }
68
- const childArray = React.Children.toArray(children);
69
- for (const child of childArray) {
70
- if (
71
- React.isValidElement(child) &&
72
- (child.props as FTBRefProps).defaultTab
73
- ) {
74
- const label = (child.props as FTBRefProps).forLabel;
75
- const idx = tabs.findIndex(
76
- (t) => t.label.toLowerCase() === label.toLowerCase(),
77
- );
78
- if (idx >= 0) return idx;
79
- }
80
- }
81
- return 0;
82
- });
83
-
84
- useEffect(() => {
85
- if (process.env.NODE_ENV === "production") return;
86
- const childArray = React.Children.toArray(children);
87
- if (childArray.length === 0) return;
88
- const hasDefault = childArray.some(
89
- (child) =>
90
- React.isValidElement(child) && (child.props as FTBRefProps).defaultTab,
91
- );
92
- if (!hasDefault) {
93
- console.warn(
94
- "<Nav.FTB>: No <FTB.Ref defaultTab> found. " +
95
- "Add the defaultTab prop to the Ref that should be shown initially.",
96
- );
97
- }
98
- // eslint-disable-next-line react-hooks/exhaustive-deps
99
- }, []);
100
-
101
- useEffect(() => {
102
- if (!activeTabId) return;
103
- const idx = tabs.findIndex(
104
- (t) => t.label.toLowerCase() === activeTabId.toLowerCase(),
105
- );
106
- if (idx >= 0) setSelected(idx);
107
- // eslint-disable-next-line react-hooks/exhaustive-deps
108
- }, [activeTabId]);
109
-
110
- const isHeader = useHasHeader();
111
- // Sticky offset of the bar + the sentinel threshold that flips `elevated`.
112
- // Mirror of `top` in .FTBRoot — keep the two in sync. Only Nav.Header
113
- // reserves real space up top, so the threshold collapses to a small margin
114
- // when there's no header to clear.
115
- const marginHeader = isHeader ? 68 : 12;
116
-
117
- const sentinelRef = useRef<HTMLDivElement>(null);
118
- // Marks the bottom edge of the whole FTB block (bar + children). Lets
119
- // `elevated` turn back off once the block has scrolled past the top of the
120
- // viewport, instead of staying stuck for the rest of the page — the top
121
- // sentinel alone never re-crosses back below marginHeader once you've
122
- // scrolled past the entire section.
123
- const endSentinelRef = useRef<HTMLDivElement>(null);
124
- const [elevated, setElevated] = useState(false);
125
- const programmaticRef = useRef(false);
126
-
127
- // Mirrors .FTBRoot's height in NavFTB.module.css — keep the two in sync.
128
- const FTB_HEIGHT = 72;
129
-
130
- // Samples the sentinel every rAF during scroll to drive `elevated`. The
131
- // programmatic guard freezes it while the tab-change scroll runs so the
132
- // smooth scroll can't flap elevated across the threshold (which would mount/
133
- // unmount the mobile mirror mid-scroll and judder).
134
- useEffect(() => {
135
- const el = sentinelRef.current;
136
- if (!el) return;
137
- let ticking = false;
138
- const measure = () => {
139
- ticking = false;
140
- if (programmaticRef.current) return;
141
- const endEl = endSentinelRef.current;
142
- const stillOnScreen = endEl
143
- ? endEl.getBoundingClientRect().top > marginHeader + FTB_HEIGHT
144
- : true;
145
- setElevated(el.getBoundingClientRect().top < marginHeader && stillOnScreen);
146
- };
147
- const onScroll = () => {
148
- if (ticking) return;
149
- ticking = true;
150
- requestAnimationFrame(measure);
151
- };
152
- measure();
153
- document.addEventListener("scroll", onScroll, {
154
- capture: true,
155
- passive: true,
156
- });
157
- window.addEventListener("resize", onScroll, { passive: true });
158
- return () => {
159
- document.removeEventListener("scroll", onScroll, { capture: true });
160
- window.removeEventListener("resize", onScroll);
161
- };
162
- }, [marginHeader]);
163
-
164
- // On tab change, bring the new tab to the top. scrollIntoView + the
165
- // sentinel's scroll-margin-top clears the bar/chrome natively; `elevated` is
166
- // frozen for the duration so the mirror can't toggle mid-scroll.
167
- const didMountRef = useRef(false);
168
- useEffect(() => {
169
- if (!didMountRef.current) {
170
- didMountRef.current = true;
171
- return;
172
- }
173
- const el = sentinelRef.current;
174
- if (!el) return;
175
-
176
- programmaticRef.current = true;
177
- el.scrollIntoView({ behavior: "smooth", block: "start" });
178
-
179
- let done = false;
180
- const settle = () => {
181
- if (done) return;
182
- done = true;
183
- programmaticRef.current = false;
184
- const s = sentinelRef.current;
185
- const endEl = endSentinelRef.current;
186
- const stillOnScreen = endEl
187
- ? endEl.getBoundingClientRect().top > marginHeader + FTB_HEIGHT
188
- : true;
189
- if (s) setElevated(s.getBoundingClientRect().top < marginHeader && stillOnScreen);
190
- window.removeEventListener("scrollend", settle);
191
- window.clearTimeout(fallback);
192
- };
193
- const fallback = window.setTimeout(settle, 700);
194
- window.addEventListener("scrollend", settle);
195
- return () => {
196
- programmaticRef.current = false;
197
- window.removeEventListener("scrollend", settle);
198
- window.clearTimeout(fallback);
199
- };
200
- }, [selected, marginHeader]);
201
-
202
- const reduceMotion = useReduceMotion();
203
- const { isMobile, isTablet } = useBreakpoints();
204
- const isEmbedded = useContext(NavFTBEmbeddedContext);
205
- const stickyCtx = useContext(NavFTBStickyContext);
206
- const setFtbProps = stickyCtx?.setFtbProps;
207
-
208
- // Mirror the bar into the fixed top bar when it elevates on mobile.
209
- useEffect(() => {
210
- if (isEmbedded || !setFtbProps) return;
211
- if (elevated && isTablet) {
212
- setFtbProps({
213
- id,
214
- tabs,
215
- onTabChange: (index: number) => {
216
- setSelected(index);
217
- onTabChange?.(index);
218
- },
219
- activeTabId: tabs[selected]?.label,
220
- });
221
- } else {
222
- setFtbProps(null);
223
- }
224
- return () => setFtbProps(null);
225
- }, [
226
- elevated,
227
- isTablet,
228
- isEmbedded,
229
- setFtbProps,
230
- id,
231
- tabs,
232
- onTabChange,
233
- selected,
234
- ]);
235
-
236
- const {
237
- containerRef,
238
- indicatorRef,
239
- registerTab,
240
- remeasureAndSnap,
241
- onTabPointerEnter,
242
- onTabPointerLeave,
243
- } = useTabIndicator({
244
- selected,
245
- setSelected,
246
- tabs,
247
- elevated,
248
- isEmbedded,
249
- reduceMotion,
250
- onTabChange,
251
- });
252
-
253
- const handleClick = useCallback(
254
- (index: number) => {
255
- setSelected(index);
256
- onTabChange?.(index);
257
- },
258
- [onTabChange],
259
- );
260
-
261
- const selectTab = useCallback(
262
- (target: number | string) => {
263
- const index =
264
- typeof target === "number"
265
- ? target
266
- : tabs.findIndex(
267
- (t) => t.label.toLowerCase() === target.toLowerCase(),
268
- );
269
- if (index < 0 || index >= tabs.length) return;
270
- setSelected(index);
271
- onTabChange?.(index);
272
- },
273
- [tabs, onTabChange],
274
- );
275
-
276
- const selectedLabel = tabs[selected]?.label ?? "";
277
-
278
- const groupValue = useMemo<NavFTBGroupContextValue>(
279
- () => ({ selectedLabel, selectedIndex: selected, tabs, selectTab }),
280
- [selectedLabel, selected, tabs, selectTab],
281
- );
282
-
283
- return (
284
- <NavFTBGroupContext.Provider value={groupValue}>
285
- <div
286
- ref={sentinelRef}
287
- aria-hidden="true"
288
- className={styles.FTBsentinel}
289
- data-header={isHeader ? "" : undefined}
290
- />
291
-
292
- <motion.div
293
- className={styles.FTBRoot}
294
- data-elevated={elevated ? "" : undefined}
295
- data-embedded={isEmbedded ? "" : undefined}
296
- data-section={inSection ? "" : undefined}
297
- data-mobile={isTablet ? "" : undefined}
298
- data-header={isHeader ? "" : undefined}
299
- layout={!isEmbedded}
300
- whileHover={{ scale: !isTablet && elevated ? 1.02 : 1 }}
301
- transition={{
302
- ease: [0.01, 1.25, 0.23, 1.01],
303
- duration: 0.4,
304
- delay: 0,
305
- scale: { ease: easeInOut, duration: 0.2 },
306
- }}
307
- onLayoutAnimationComplete={remeasureAndSnap}
308
- >
309
- <div
310
- ref={containerRef}
311
- role="tablist"
312
- aria-label={id}
313
- className={styles.FTBscroller}
314
- >
315
- <div
316
- ref={indicatorRef}
317
- aria-hidden="true"
318
- className={styles.FTBindicator}
319
- />
320
- {tabs.map((tab, i) => (
321
- <span
322
- key={tab.label}
323
- ref={registerTab(i)}
324
- role="tab"
325
- aria-selected={selected === i}
326
- tabIndex={selected === i ? 0 : -1}
327
- onClick={() => handleClick(i)}
328
- onPointerEnter={() => onTabPointerEnter(i)}
329
- onPointerLeave={onTabPointerLeave}
330
- className={`${styles.tab} ${
331
- selected !== i ? styles.tabInactive : ""
332
- }`}
333
- >
334
- <Icon systemName={tab.systemName} label={tab.label} />
335
- </span>
336
- ))}
337
- </div>
338
- </motion.div>
339
-
340
- <div
341
- aria-hidden="true"
342
- className={styles.FTBfade}
343
- data-elevated={elevated ? "" : undefined}
344
- data-mobile={isTablet ? "" : undefined}
345
- data-header={isHeader ? "" : undefined}
346
- >
347
- {!isHeader && !isTablet && (
348
- <ProgressiveBlur snapTo="top" blur={14} definition={7} />
349
- )}
350
- </div>
351
-
352
- {children}
353
-
354
- <div ref={endSentinelRef} aria-hidden="true" className={styles.FTBendSentinel} />
355
- </NavFTBGroupContext.Provider>
356
- );
357
- });
358
-
359
- const DEFAULT_MIO_SHAPES: ShapeType[] = ["sunny", "bun", "gem", "flower"];
360
-
361
- const pickShape = (pool: ShapeType[]) =>
362
- pool[Math.floor(Math.random() * pool.length)];
363
-
364
- function FTBMio({ shapes = DEFAULT_MIO_SHAPES }: { shapes?: ShapeType[] }) {
365
- const ctx = useContext(NavFTBGroupContext);
366
- const prev = ctx ? ctx.tabs[ctx.selectedIndex - 1] : undefined;
367
- const next = ctx ? ctx.tabs[ctx.selectedIndex + 1] : undefined;
368
- // eslint-disable-next-line react-hooks/exhaustive-deps
369
- const prevShape = useMemo(() => pickShape(shapes), [prev?.label]);
370
- // eslint-disable-next-line react-hooks/exhaustive-deps
371
- const nextShape = useMemo(() => pickShape(shapes), [next?.label]);
372
-
373
- if (!ctx || (!prev && !next)) return null;
374
- const { selectedIndex, selectTab } = ctx;
375
-
376
- return (
377
- <Wrap>
378
- {prev && (
379
- <MioCard
380
- title={prev.label}
381
- navigate="previous"
382
- withIcon={{ systemName: prev.systemName, shape: prevShape }}
383
- onClick={() => selectTab(selectedIndex - 1)}
384
- />
385
- )}
386
- {next && (
387
- <MioCard
388
- title={next.label}
389
- navigate="next"
390
- withIcon={{ systemName: next.systemName, shape: nextShape }}
391
- onClick={() => selectTab(selectedIndex + 1)}
392
- />
393
- )}
394
- </Wrap>
395
- );
396
- }
397
-
398
- const NavFTB = Object.assign(NavFTBInner, { Ref: FTBRef, Mio: FTBMio });
399
- export default NavFTB;
1
+ import React, {
2
+ memo,
3
+ useCallback,
4
+ useContext,
5
+ useEffect,
6
+ useMemo,
7
+ useRef,
8
+ useState,
9
+ } from "react";
10
+ import { easeInOut, motion } from "framer-motion";
11
+ import Icon from "@/components/tools/label/Icon";
12
+ import Label from "@/components/tools/label/Label";
13
+ import {
14
+ useHasHeader,
15
+ NavFTBStickyContext,
16
+ NavFTBEmbeddedContext,
17
+ NavFTBGroupContext,
18
+ } from "../NavContext";
19
+ import { useReduceMotion } from "@/components/tools/ReduceMotionContext";
20
+ import styles from "./NavFTB.module.css";
21
+ import { useTabIndicator } from "./useTabIndicator";
22
+ import type {
23
+ NavFTBProps,
24
+ FTBRefProps,
25
+ NavFTBGroupContextValue,
26
+ } from "../NavContext";
27
+ import Card from "@/components/(layout)/card/Card";
28
+ import { Wrap } from "@/components/(layout)/navigation/Wrap";
29
+ import type { ShapeType } from "@/components/tools/shape/ShapePaths";
30
+ import { useBreakpoints } from "@/components/tools/mobileViewProvider";
31
+
32
+ function FTBRef({ forLabel, children }: FTBRefProps) {
33
+ const ctx = useContext(NavFTBGroupContext);
34
+ const rm = useReduceMotion();
35
+ if (!ctx) {
36
+ if (process.env.NODE_ENV !== "production") {
37
+ console.error("<FTB.Ref> must be used within <Nav.FTB>");
38
+ }
39
+ return null;
40
+ }
41
+ if (ctx.selectedLabel.toLowerCase() !== forLabel.toLowerCase()) return null;
42
+ // Each tab's content mounts fresh when it becomes active, so this replays
43
+ // its fade-from-bottom on every reveal. 300ms tuned snappy for a tab
44
+ // switch.
45
+ return (
46
+ <motion.div
47
+ initial={{ opacity: 0, y: rm ? 0 : 40 }}
48
+ animate={{ opacity: 1, y: 0 }}
49
+ transition={{ duration: rm ? 0 : 0.3, ease: easeInOut }}
50
+ style={{
51
+ display: "flex",
52
+ flexDirection: "column",
53
+ alignItems: "center",
54
+ width: "100%",
55
+ gap: 12,
56
+ }}
57
+ >
58
+ {children}
59
+ </motion.div>
60
+ );
61
+ }
62
+
63
+ const NavFTBInner = memo(function NavFTB({
64
+ tabs,
65
+ id,
66
+ onTabChange,
67
+ activeTabId,
68
+ inSection = false,
69
+ children,
70
+ }: NavFTBProps) {
71
+ const [selected, setSelected] = useState(() => {
72
+ if (activeTabId) {
73
+ const idx = tabs.findIndex(
74
+ (t) => t.label.toLowerCase() === activeTabId.toLowerCase(),
75
+ );
76
+ return idx >= 0 ? idx : 0;
77
+ }
78
+ const childArray = React.Children.toArray(children);
79
+ for (const child of childArray) {
80
+ if (
81
+ React.isValidElement(child) &&
82
+ (child.props as FTBRefProps).defaultTab
83
+ ) {
84
+ const label = (child.props as FTBRefProps).forLabel;
85
+ const idx = tabs.findIndex(
86
+ (t) => t.label.toLowerCase() === label.toLowerCase(),
87
+ );
88
+ if (idx >= 0) return idx;
89
+ }
90
+ }
91
+ return 0;
92
+ });
93
+
94
+ useEffect(() => {
95
+ if (process.env.NODE_ENV === "production") return;
96
+ const childArray = React.Children.toArray(children);
97
+ if (childArray.length === 0) return;
98
+ const hasDefault = childArray.some(
99
+ (child) =>
100
+ React.isValidElement(child) && (child.props as FTBRefProps).defaultTab,
101
+ );
102
+ if (!hasDefault) {
103
+ console.warn(
104
+ "<Nav.FTB>: No <FTB.Ref defaultTab> found. " +
105
+ "Add the defaultTab prop to the Ref that should be shown initially.",
106
+ );
107
+ }
108
+ // eslint-disable-next-line react-hooks/exhaustive-deps
109
+ }, []);
110
+
111
+ // Syncs `selected` to the externally-driven activeTabId (e.g. route
112
+ // changes) — a real external signal, not something derivable at render.
113
+ useEffect(() => {
114
+ if (!activeTabId) return;
115
+ const idx = tabs.findIndex(
116
+ (t) => t.label.toLowerCase() === activeTabId.toLowerCase(),
117
+ );
118
+ // eslint-disable-next-line react-hooks/set-state-in-effect
119
+ if (idx >= 0) setSelected(idx);
120
+ // eslint-disable-next-line react-hooks/exhaustive-deps
121
+ }, [activeTabId]);
122
+
123
+ const isHeader = useHasHeader();
124
+ // Sticky offset of the bar + the sentinel threshold that flips `elevated`.
125
+ // Mirror of `top` in .FTBRoot — keep the two in sync. Only Nav.Header
126
+ // reserves real space up top, so the threshold collapses to a small margin
127
+ // when there's no header to clear.
128
+ const marginHeader = isHeader ? 68 : 12;
129
+
130
+ const sentinelRef = useRef<HTMLDivElement>(null);
131
+ // Marks the bottom edge of the whole FTB block (bar + children). Lets
132
+ // `elevated` turn back off once the block has scrolled past the top of the
133
+ // viewport, instead of staying stuck for the rest of the page — the top
134
+ // sentinel alone never re-crosses back below marginHeader once you've
135
+ // scrolled past the entire section.
136
+ const endSentinelRef = useRef<HTMLDivElement>(null);
137
+ const [elevated, setElevated] = useState(false);
138
+ const programmaticRef = useRef(false);
139
+
140
+ // Mirrors .FTBRoot's height in NavFTB.module.css — keep the two in sync.
141
+ const FTB_HEIGHT = 72;
142
+
143
+ // Samples the sentinel every rAF during scroll to drive `elevated`. The
144
+ // programmatic guard freezes it while the tab-change scroll runs so the
145
+ // smooth scroll can't flap elevated across the threshold (which would mount/
146
+ // unmount the mobile mirror mid-scroll and judder).
147
+ useEffect(() => {
148
+ const el = sentinelRef.current;
149
+ if (!el) return;
150
+ let ticking = false;
151
+ const measure = () => {
152
+ ticking = false;
153
+ if (programmaticRef.current) return;
154
+ const endEl = endSentinelRef.current;
155
+ const stillOnScreen = endEl
156
+ ? endEl.getBoundingClientRect().top > marginHeader + FTB_HEIGHT
157
+ : true;
158
+ setElevated(
159
+ el.getBoundingClientRect().top < marginHeader && stillOnScreen,
160
+ );
161
+ };
162
+ const onScroll = () => {
163
+ if (ticking) return;
164
+ ticking = true;
165
+ requestAnimationFrame(measure);
166
+ };
167
+ measure();
168
+ document.addEventListener("scroll", onScroll, {
169
+ capture: true,
170
+ passive: true,
171
+ });
172
+ window.addEventListener("resize", onScroll, { passive: true });
173
+ return () => {
174
+ document.removeEventListener("scroll", onScroll, { capture: true });
175
+ window.removeEventListener("resize", onScroll);
176
+ };
177
+ }, [marginHeader]);
178
+
179
+ // On tab change, bring the new tab to the top. scrollIntoView + the
180
+ // sentinel's scroll-margin-top clears the bar/chrome natively; `elevated` is
181
+ // frozen for the duration so the mirror can't toggle mid-scroll.
182
+ const didMountRef = useRef(false);
183
+ useEffect(() => {
184
+ if (!didMountRef.current) {
185
+ didMountRef.current = true;
186
+ return;
187
+ }
188
+ const el = sentinelRef.current;
189
+ if (!el) return;
190
+
191
+ programmaticRef.current = true;
192
+ el.scrollIntoView({ behavior: "smooth", block: "start" });
193
+
194
+ let done = false;
195
+ const settle = () => {
196
+ if (done) return;
197
+ done = true;
198
+ programmaticRef.current = false;
199
+ const s = sentinelRef.current;
200
+ const endEl = endSentinelRef.current;
201
+ const stillOnScreen = endEl
202
+ ? endEl.getBoundingClientRect().top > marginHeader + FTB_HEIGHT
203
+ : true;
204
+ if (s)
205
+ setElevated(
206
+ s.getBoundingClientRect().top < marginHeader && stillOnScreen,
207
+ );
208
+ window.removeEventListener("scrollend", settle);
209
+ window.clearTimeout(fallback);
210
+ };
211
+ const fallback = window.setTimeout(settle, 700);
212
+ window.addEventListener("scrollend", settle);
213
+ return () => {
214
+ programmaticRef.current = false;
215
+ window.removeEventListener("scrollend", settle);
216
+ window.clearTimeout(fallback);
217
+ };
218
+ }, [selected, marginHeader]);
219
+
220
+ const reduceMotion = useReduceMotion();
221
+ const { isTablet } = useBreakpoints();
222
+ const isEmbedded = useContext(NavFTBEmbeddedContext);
223
+ const stickyCtx = useContext(NavFTBStickyContext);
224
+ const setFtbProps = stickyCtx?.setFtbProps;
225
+
226
+ // Mirror the bar into the fixed top bar when it elevates on mobile.
227
+ useEffect(() => {
228
+ if (isEmbedded || !setFtbProps) return;
229
+ if (elevated && isTablet) {
230
+ setFtbProps({
231
+ id,
232
+ tabs,
233
+ onTabChange: (index: number) => {
234
+ setSelected(index);
235
+ onTabChange?.(index);
236
+ },
237
+ activeTabId: tabs[selected]?.label,
238
+ });
239
+ } else {
240
+ setFtbProps(null);
241
+ }
242
+ return () => setFtbProps(null);
243
+ }, [
244
+ elevated,
245
+ isTablet,
246
+ isEmbedded,
247
+ setFtbProps,
248
+ id,
249
+ tabs,
250
+ onTabChange,
251
+ selected,
252
+ ]);
253
+
254
+ const {
255
+ containerRef,
256
+ indicatorRef,
257
+ registerTab,
258
+ remeasureAndSnap,
259
+ onTabPointerEnter,
260
+ onTabPointerLeave,
261
+ } = useTabIndicator({
262
+ selected,
263
+ setSelected,
264
+ tabs,
265
+ elevated,
266
+ isEmbedded,
267
+ reduceMotion,
268
+ onTabChange,
269
+ });
270
+
271
+ const handleClick = useCallback(
272
+ (index: number) => {
273
+ setSelected(index);
274
+ onTabChange?.(index);
275
+ },
276
+ [onTabChange],
277
+ );
278
+
279
+ const selectTab = useCallback(
280
+ (target: number | string) => {
281
+ const index =
282
+ typeof target === "number"
283
+ ? target
284
+ : tabs.findIndex(
285
+ (t) => t.label.toLowerCase() === target.toLowerCase(),
286
+ );
287
+ if (index < 0 || index >= tabs.length) return;
288
+ setSelected(index);
289
+ onTabChange?.(index);
290
+ },
291
+ [tabs, onTabChange],
292
+ );
293
+
294
+ const selectedLabel = tabs[selected]?.label ?? "";
295
+
296
+ const groupValue = useMemo<NavFTBGroupContextValue>(
297
+ () => ({ selectedLabel, selectedIndex: selected, tabs, selectTab }),
298
+ [selectedLabel, selected, tabs, selectTab],
299
+ );
300
+
301
+ return (
302
+ <NavFTBGroupContext.Provider value={groupValue}>
303
+ <div
304
+ ref={sentinelRef}
305
+ aria-hidden="true"
306
+ className={styles.FTBsentinel}
307
+ data-header={isHeader ? "" : undefined}
308
+ />
309
+
310
+ <motion.div
311
+ className={styles.FTBRoot}
312
+ data-elevated={elevated ? "" : undefined}
313
+ data-embedded={isEmbedded ? "" : undefined}
314
+ data-section={inSection ? "" : undefined}
315
+ data-mobile={isTablet ? "" : undefined}
316
+ data-header={isHeader ? "" : undefined}
317
+ layout={!isEmbedded}
318
+ whileHover={{ scale: !isTablet && elevated ? 1.02 : 1 }}
319
+ transition={{
320
+ ease: [0.01, 1.25, 0.23, 1.01],
321
+ duration: 0.4,
322
+ delay: 0,
323
+ scale: { ease: easeInOut, duration: 0.2 },
324
+ }}
325
+ onLayoutAnimationComplete={remeasureAndSnap}
326
+ >
327
+ <div
328
+ ref={containerRef}
329
+ role="tablist"
330
+ aria-label={id}
331
+ className={styles.FTBscroller}
332
+ >
333
+ <div
334
+ ref={indicatorRef}
335
+ aria-hidden="true"
336
+ className={styles.FTBindicator}
337
+ />
338
+ {tabs.map((tab, i) => (
339
+ <span
340
+ key={tab.label}
341
+ ref={registerTab(i)}
342
+ role="tab"
343
+ aria-selected={selected === i}
344
+ tabIndex={selected === i ? 0 : -1}
345
+ onClick={() => handleClick(i)}
346
+ onPointerEnter={() => onTabPointerEnter(i)}
347
+ onPointerLeave={onTabPointerLeave}
348
+ className={`${styles.tab} ${
349
+ selected !== i ? styles.tabInactive : ""
350
+ }`}
351
+ >
352
+ {tab.systemName && <Icon systemName={tab.systemName} />}
353
+ {tab.label ||
354
+ (tab.label && tab.systemName && (
355
+ <Label systemName={tab.systemName} label={tab.label} />
356
+ ))}
357
+ </span>
358
+ ))}
359
+ </div>
360
+ </motion.div>
361
+
362
+ <div
363
+ aria-hidden="true"
364
+ className={styles.FTBfade}
365
+ data-elevated={elevated ? "" : undefined}
366
+ data-mobile={isTablet ? "" : undefined}
367
+ data-header={isHeader ? "" : undefined}
368
+ />
369
+
370
+ {children}
371
+
372
+ <div
373
+ ref={endSentinelRef}
374
+ aria-hidden="true"
375
+ className={styles.FTBendSentinel}
376
+ />
377
+ </NavFTBGroupContext.Provider>
378
+ );
379
+ });
380
+
381
+ const DEFAULT_MIO_SHAPES: ShapeType[] = ["sunny", "bun", "gem", "flower"];
382
+
383
+ // Deterministic, NOT random — Math.random() here would pick a different
384
+ // shape on the server render vs. the client render (same component, two
385
+ // separate evaluations), which is exactly what caused the hydration
386
+ // mismatch on <ShapeMorph>'s `d` attribute. Hashing the label instead means
387
+ // the same tab always resolves to the same shape everywhere, while still
388
+ // varying shape-to-shape for visual variety.
389
+ function hashString(str: string): number {
390
+ let hash = 0;
391
+ for (let i = 0; i < str.length; i++) {
392
+ hash = (hash << 5) - hash + str.charCodeAt(i);
393
+ hash |= 0; // keep it a 32-bit int
394
+ }
395
+ return Math.abs(hash);
396
+ }
397
+
398
+ const pickShape = (pool: ShapeType[], seed: string) =>
399
+ pool[hashString(seed) % pool.length];
400
+
401
+ function FTBMio({ shapes = DEFAULT_MIO_SHAPES }: { shapes?: ShapeType[] }) {
402
+ const ctx = useContext(NavFTBGroupContext);
403
+ const prev = ctx ? ctx.tabs[ctx.selectedIndex - 1] : undefined;
404
+ const next = ctx ? ctx.tabs[ctx.selectedIndex + 1] : undefined;
405
+ // eslint-disable-next-line react-hooks/exhaustive-deps
406
+ const prevShape = useMemo(
407
+ () => pickShape(shapes, prev?.label ?? ""),
408
+ [prev?.label],
409
+ );
410
+ // eslint-disable-next-line react-hooks/exhaustive-deps
411
+ const nextShape = useMemo(
412
+ () => pickShape(shapes, next?.label ?? ""),
413
+ [next?.label],
414
+ );
415
+
416
+ if (!ctx || (!prev && !next)) return null;
417
+ const { selectedIndex, selectTab } = ctx;
418
+
419
+ return (
420
+ <Wrap>
421
+ {prev && (
422
+ <Card
423
+ navigate="previous"
424
+ withIcon={{ systemName: prev.systemName, shapePath: prevShape }}
425
+ onClick={() => selectTab(selectedIndex - 1)}
426
+ >
427
+ <Card.Header>
428
+ <h5>{prev.label}</h5>
429
+ </Card.Header>
430
+ </Card>
431
+ )}
432
+ {next && (
433
+ <Card
434
+ navigate="next"
435
+ withIcon={{ systemName: next.systemName, shapePath: nextShape }}
436
+ onClick={() => selectTab(selectedIndex + 1)}
437
+ >
438
+ <Card.Header>
439
+ <h5>{next.label}</h5>
440
+ </Card.Header>
441
+ </Card>
442
+ )}
443
+ </Wrap>
444
+ );
445
+ }
446
+
447
+ const NavFTB = Object.assign(NavFTBInner, { Ref: FTBRef, Mio: FTBMio });
448
+ export default NavFTB;