@yamatozhen/design_system 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +101 -0
  3. package/package.json +49 -0
  4. package/scripts/postinstall.js +105 -0
  5. package/template/app/ClientNav.tsx +310 -0
  6. package/template/app/globals.css +167 -0
  7. package/template/app/layout.tsx +128 -0
  8. package/template/app/themes/dark-mc.css +51 -0
  9. package/template/app/themes/dark.css +51 -0
  10. package/template/app/themes/light-mc.css +51 -0
  11. package/template/app/themes/light.css +51 -0
  12. package/template/app/themes/theme.css +82 -0
  13. package/template/components/layout/Lightbox/LightboxCard.tsx +100 -0
  14. package/template/components/layout/Lightbox/LightboxGallery.module.css +249 -0
  15. package/template/components/layout/Lightbox/LightboxGallery.tsx +72 -0
  16. package/template/components/layout/Lightbox/LightboxGrid.tsx +186 -0
  17. package/template/components/layout/Lightbox/LightboxModal.module.css +395 -0
  18. package/template/components/layout/Lightbox/LightboxModal.tsx +500 -0
  19. package/template/components/layout/Lightbox/demo.tsx +412 -0
  20. package/template/components/layout/Lightbox/index.ts +30 -0
  21. package/template/components/layout/Lightbox/types.ts +113 -0
  22. package/template/components/layout/Lightbox/useLightboxFilters.ts +140 -0
  23. package/template/components/layout/accordion/Accordion.module.css +149 -0
  24. package/template/components/layout/accordion/Accordion.tsx +114 -0
  25. package/template/components/layout/button/Button.module.css +305 -0
  26. package/template/components/layout/button/ButtonGroup.tsx +503 -0
  27. package/template/components/layout/button/FAB.tsx +118 -0
  28. package/template/components/layout/button/button.tsx +128 -0
  29. package/template/components/layout/button/drop.module.css +229 -0
  30. package/template/components/layout/button/drop.tsx +516 -0
  31. package/template/components/layout/hero/v1/heroSlideshow.module.css +107 -0
  32. package/template/components/layout/hero/v1/heroSlideshow.tsx +233 -0
  33. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +126 -0
  34. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +290 -0
  35. package/template/components/layout/modals/alert/Alert.tsx +188 -0
  36. package/template/components/layout/navigation/MioCard.module.css +88 -0
  37. package/template/components/layout/navigation/MioCard.tsx +266 -0
  38. package/template/components/layout/navigation/Wrap.tsx +41 -0
  39. package/template/components/layout/navigation/nav/Nav.module.css +508 -0
  40. package/template/components/layout/navigation/nav/Nav.tsx +167 -0
  41. package/template/components/layout/navigation/nav/NavBar.tsx +419 -0
  42. package/template/components/layout/navigation/nav/NavContext.tsx +259 -0
  43. package/template/components/layout/navigation/nav/NavItem.tsx +173 -0
  44. package/template/components/layout/navigation/nav/NavNew.module.css +373 -0
  45. package/template/components/layout/navigation/nav/NavRail.tsx +315 -0
  46. package/template/components/layout/navigation/nav/NavSection.tsx +102 -0
  47. package/template/components/layout/navigation/nav/NavTab.tsx +25 -0
  48. package/template/components/layout/navigation/nav/navftb/NavFTB.module.css +252 -0
  49. package/template/components/layout/navigation/nav/navftb/NavFTB.tsx +399 -0
  50. package/template/components/layout/navigation/nav/navftb/useTabIndicator.ts +484 -0
  51. package/template/components/layout/navigation/nav/navheader/NavHeader.module.css +59 -0
  52. package/template/components/layout/navigation/nav/navheader/NavHeader.tsx +478 -0
  53. package/template/components/layout/pages/loadingScreen.tsx +102 -0
  54. package/template/components/layout/pages/maintenance/Maintenance.tsx +53 -0
  55. package/template/components/layout/pages/maintenance/maintenance.module.css +163 -0
  56. package/template/components/layout/switch/Switch.module.css +102 -0
  57. package/template/components/layout/switch/Switch.tsx +48 -0
  58. package/template/components/tools/Divider.tsx +11 -0
  59. package/template/components/tools/ProgressiveBlur.tsx +73 -0
  60. package/template/components/tools/ReduceMotionContext.tsx +5 -0
  61. package/template/components/tools/Sinewave.tsx +199 -0
  62. package/template/components/tools/SinewaveProgress.tsx +135 -0
  63. package/template/components/tools/badge/Badge.tsx +28 -0
  64. package/template/components/tools/flubber.d.ts +7 -0
  65. package/template/components/tools/icon/SocialIcons.tsx +88 -0
  66. package/template/components/tools/icon/icon.module.css +0 -0
  67. package/template/components/tools/icon/icon.tsx +125 -0
  68. package/template/components/tools/mobileViewProvider.tsx +58 -0
  69. package/template/components/tools/react-bits/ClickSpark.tsx +177 -0
  70. package/template/components/tools/react-bits/FadeContent.tsx +90 -0
  71. package/template/components/tools/react-bits/GlareHover.tsx +73 -0
  72. package/template/components/tools/react-bits/GradientText/GradientText.css +70 -0
  73. package/template/components/tools/react-bits/GradientText/GradientText.tsx +44 -0
  74. package/template/components/tools/react-bits/Magnet.tsx +118 -0
  75. package/template/components/tools/react-bits/Stepper/Stepper.css +134 -0
  76. package/template/components/tools/react-bits/Stepper/Stepper.tsx +412 -0
  77. package/template/components/tools/ripple/ripple.css +41 -0
  78. package/template/components/tools/ripple/ripple.tsx +53 -0
  79. package/template/components/tools/shape/ShapeLoader.tsx +101 -0
  80. package/template/components/tools/shape/ShapeMorph.tsx +190 -0
  81. package/template/components/tools/shape/ShapePaths.ts +116 -0
  82. package/template/components/tools/switch/Switch.module.css +102 -0
  83. package/template/components/tools/switch/Switch.tsx +48 -0
  84. package/template/components/tools/useBodyScrollLock.tsx +27 -0
  85. package/template/components/tools/useImageColor.ts +47 -0
  86. package/template/components/tools/useNavSheetDrag.tsx +196 -0
  87. package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght.woff2 +0 -0
@@ -0,0 +1,399 @@
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;