create-modoock-app 2.3.0 → 2.4.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.
@@ -21,7 +21,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) {
21
21
  return (
22
22
  <html lang="fr" className={`${montserrat.className} antialiased`}>
23
23
  <body className="flex h-screen overflow-hidden bg-background">
24
- {children}
24
+ {children}
25
25
  </body>
26
26
  </html>
27
27
  );
@@ -1,9 +1,11 @@
1
1
  "use client";
2
2
 
3
3
  import { useEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent } from "react";
4
+ import Image from "next/image";
4
5
  import { usePathname, useRouter } from "next/navigation";
5
6
  import { Icon } from "@modoock/components";
6
7
  import type { IconName } from "@modoock/components";
8
+ import { scrollAppMainToIdWhenReady } from "@/lib/scroll-to-section";
7
9
 
8
10
  const MD_NAV = "(min-width: 56rem)";
9
11
  const DESKTOP_NAV = "(min-width: 1024px)";
@@ -24,10 +26,61 @@ interface NavItem {
24
26
 
25
27
  const NAV_ITEMS: NavItem[] = [
26
28
  { label: "Accueil", href: "/", icon: "Flame" },
27
- { label: "Design System", href: "/design-system", icon: "Palette" },
28
- { label: "Components", href: "/components", icon: "Puzzle" },
29
+ {
30
+ label: "Documentation",
31
+ href: "/documentation",
32
+ icon: "BookOpen",
33
+ children: [
34
+ { label: "Fondations", href: "/documentation#fondations" },
35
+ { label: "Approche", href: "/documentation#approche" },
36
+ { label: "Parcours", href: "/documentation#parcours" },
37
+ { label: "Principes", href: "/documentation#principes" },
38
+ { label: "Suite", href: "/documentation#suite" },
39
+ ],
40
+ },
41
+ { label: "Design System", href: "/design-system", icon: "Palette",
42
+ children: [
43
+ { label: "Couleurs", href: "/design-system#colors" },
44
+ { label: "Typographie", href: "/design-system#typography" },
45
+ { label: "Espacements", href: "/design-system#spacing" },
46
+ { label: "Rayons", href: "/design-system#border-radius" },
47
+ { label: "Iconographie", href: "/design-system#iconography" },
48
+ { label: "Mise en page", href: "/design-system#layout-rules" },
49
+ { label: "Tailles", href: "/design-system#sizing-principle" },
50
+ { label: "Hiérarchie", href: "/design-system#visual-hierarchy" },
51
+ { label: "États sémantiques", href: "/design-system#semantic-states" },
52
+ { label: "Exemple complet", href: "/design-system#complete-example" },
53
+ ],
54
+ },
55
+ {
56
+ label: "Composants",
57
+ href: "/components",
58
+ icon: "Puzzle",
59
+ children: [
60
+ { label: "Champs de saisie", href: "/components/champs" },
61
+ { label: "Boutons", href: "/components/boutons" },
62
+ { label: "Icônes", href: "/components/icones" },
63
+ { label: "Loader", href: "/components/loader" },
64
+ { label: "Badges", href: "/components/badges" },
65
+ { label: "Sélecteurs", href: "/components/selecteurs" },
66
+ { label: "Onglets", href: "/components/onglets" },
67
+ { label: "Modale", href: "/components/modale" },
68
+ { label: "Barres de métrique", href: "/components/barres-de-metrique" },
69
+ { label: "Stepper", href: "/components/stepper" },
70
+ { label: "Tableau", href: "/components/tableau" },
71
+ ],
72
+ },
29
73
  ];
30
74
 
75
+ function pathOf(href: string) {
76
+ return href.split("#")[0] || href;
77
+ }
78
+
79
+ function hashOf(href: string) {
80
+ const i = href.indexOf("#");
81
+ return i === -1 ? "" : href.slice(i);
82
+ }
83
+
31
84
  interface SideNavProps {
32
85
  collapsed: boolean;
33
86
  onCollapsedChange: (collapsed: boolean) => void;
@@ -38,6 +91,7 @@ export default function SideNav({
38
91
  onCollapsedChange,
39
92
  }: SideNavProps) {
40
93
  const [expanded, setExpanded] = useState<Record<string, boolean>>({});
94
+ const [hash, setHash] = useState("");
41
95
  const [isMdUp, setIsMdUp] = useState(true);
42
96
  const navRef = useRef<HTMLElement>(null);
43
97
  const previousFocusRef = useRef<HTMLElement | null>(null);
@@ -46,6 +100,13 @@ export default function SideNav({
46
100
  const drawerOpen = !collapsed && !isMdUp;
47
101
  const showLabels = !collapsed || !isMdUp;
48
102
 
103
+ useEffect(() => {
104
+ const syncHash = () => setHash(window.location.hash);
105
+ syncHash();
106
+ window.addEventListener("hashchange", syncHash);
107
+ return () => window.removeEventListener("hashchange", syncHash);
108
+ }, []);
109
+
49
110
  useEffect(() => {
50
111
  const desktop = window.matchMedia(DESKTOP_NAV);
51
112
  const md = window.matchMedia(MD_NAV);
@@ -102,6 +163,11 @@ export default function SideNav({
102
163
 
103
164
  const handleNavigate = (href: string) => {
104
165
  router.push(href);
166
+ const sectionHash = hashOf(href);
167
+ if (sectionHash) {
168
+ setHash(sectionHash);
169
+ scrollAppMainToIdWhenReady(sectionHash.slice(1));
170
+ }
105
171
  if (!window.matchMedia(DESKTOP_NAV).matches) {
106
172
  onCollapsedChange(true);
107
173
  }
@@ -111,19 +177,6 @@ export default function SideNav({
111
177
  setExpanded((prev) => ({ ...prev, [href]: !prev[href] }));
112
178
  };
113
179
 
114
- useEffect(() => {
115
- const parent = NAV_ITEMS.find(
116
- (item) =>
117
- !!item.children?.length &&
118
- (item.href === pathname ||
119
- item.children.some((child) => child.href === pathname)),
120
- );
121
- if (!parent) return;
122
- setExpanded((prev) =>
123
- prev[parent.href] ? prev : { ...prev, [parent.href]: true },
124
- );
125
- }, [pathname]);
126
-
127
180
  return (
128
181
  <>
129
182
  <div
@@ -154,9 +207,14 @@ export default function SideNav({
154
207
  }`}
155
208
  >
156
209
  {showLabels ? (
157
- <span className="text-component-title font-semibold text-white">
158
- Modoock
159
- </span>
210
+ <Image
211
+ src="/identity/full_logo_white.svg"
212
+ alt="Modoock"
213
+ width={168}
214
+ height={46}
215
+ className="h-9 w-auto"
216
+ priority
217
+ />
160
218
  ) : null}
161
219
  <button
162
220
  type="button"
@@ -165,9 +223,9 @@ export default function SideNav({
165
223
  className="grid size-8 place-items-center rounded-small text-white/80 transition-colors hover:bg-white/10 hover:text-white focus-visible:ring-2 focus-visible:ring-white [&_svg]:shrink-0 [&_svg]:text-current"
166
224
  >
167
225
  {collapsed ? (
168
- <Icon name="PanelLeftOpen" variant="white" aria-hidden="true" />
226
+ <Icon name="PanelLeftOpen" aria-hidden="true" />
169
227
  ) : (
170
- <Icon name="PanelLeftClose" variant="white" aria-hidden="true" />
228
+ <Icon name="PanelLeftClose" aria-hidden="true" />
171
229
  )}
172
230
  </button>
173
231
  </div>
@@ -176,57 +234,54 @@ export default function SideNav({
176
234
  <div className="nav-scrollbar flex flex-1 flex-col gap-1 overflow-y-auto overscroll-contain px-2 py-2">
177
235
  {NAV_ITEMS.map((item) => {
178
236
  const hasChildren = !!item.children?.length;
179
- const isOpen = expanded[item.href];
180
- const isActive =
237
+ const isRouteActive =
181
238
  pathname === item.href ||
182
- (item.children ?? []).some((child) => child.href === pathname);
239
+ (item.href !== "/" && pathname.startsWith(`${item.href}/`)) ||
240
+ (item.children ?? []).some(
241
+ (child) => pathOf(child.href) === pathname,
242
+ );
243
+ const isOpen = expanded[item.href] ?? isRouteActive;
244
+ const isActive = isRouteActive;
183
245
 
184
246
  return (
185
247
  <div key={item.href} className="flex flex-col gap-1">
186
- <div
187
- className={`flex items-center rounded-small ${
188
- isActive ? "bg-white/15 text-white" : "text-white/80"
189
- }`}
248
+ <button
249
+ type="button"
250
+ onClick={() => {
251
+ if (hasChildren && showLabels) {
252
+ toggleGroup(item.href);
253
+ }
254
+ handleNavigate(item.href);
255
+ }}
256
+ title={item.label}
257
+ aria-label={showLabels ? undefined : item.label}
258
+ aria-expanded={hasChildren && showLabels ? isOpen : undefined}
259
+ className={`flex items-center gap-3 rounded-small px-3 py-2 text-left text-body-medium transition-colors focus-visible:ring-2 focus-visible:ring-white [&_svg]:shrink-0 [&_svg]:text-current ${
260
+ isActive
261
+ ? "bg-white/15 text-white"
262
+ : "text-white/80 hover:bg-white/10 hover:text-white"
263
+ } ${showLabels ? "" : "justify-center"}`}
190
264
  >
191
- <button
192
- type="button"
193
- onClick={() => {
194
- if (hasChildren) {
195
- setExpanded((prev) => ({ ...prev, [item.href]: true }));
196
- }
197
- handleNavigate(item.href);
198
- }}
199
- title={item.label}
200
- aria-label={showLabels ? undefined : item.label}
201
- className={`flex min-w-0 flex-1 items-center gap-3 rounded-small px-3 py-2 text-left text-body-medium transition-colors hover:bg-white/10 hover:text-white focus-visible:ring-2 focus-visible:ring-white [&_svg]:shrink-0 [&_svg]:text-current ${
202
- showLabels ? "" : "justify-center"
203
- }`}
204
- >
205
- <Icon name={item.icon} variant="white" aria-hidden="true" />
206
- {showLabels ? <span className="truncate">{item.label}</span> : null}
207
- </button>
265
+ <Icon name={item.icon} aria-hidden="true" />
266
+ {showLabels ? <span className="truncate">{item.label}</span> : null}
208
267
  {hasChildren && showLabels ? (
209
- <button
210
- type="button"
211
- onClick={() => toggleGroup(item.href)}
212
- aria-expanded={isOpen}
213
- aria-label={isOpen ? `Replier ${item.label}` : `Déplier ${item.label}`}
214
- className="mr-1 grid size-8 shrink-0 place-items-center rounded-small transition-colors hover:bg-white/10 hover:text-white focus-visible:ring-2 focus-visible:ring-white"
215
- >
216
- <Icon
217
- name="ChevronDown"
218
- variant="white"
219
- aria-hidden="true"
220
- className={`transition-transform ${isOpen ? "rotate-180" : ""}`}
221
- />
222
- </button>
268
+ <Icon
269
+ name="ChevronDown"
270
+ aria-hidden="true"
271
+ className={`ml-auto transition-transform ${
272
+ isOpen ? "rotate-180" : ""
273
+ }`}
274
+ />
223
275
  ) : null}
224
- </div>
276
+ </button>
225
277
 
226
278
  {hasChildren && showLabels && isOpen ? (
227
279
  <div className="ml-5 flex flex-col gap-1 border-l border-white/20 pl-2">
228
280
  {item.children!.map((child) => {
229
- const isChildActive = pathname === child.href;
281
+ const childHash = hashOf(child.href);
282
+ const isChildActive = childHash
283
+ ? pathname === pathOf(child.href) && hash === childHash
284
+ : pathname === child.href;
230
285
  return (
231
286
  <button
232
287
  key={child.href}
@@ -252,7 +307,7 @@ export default function SideNav({
252
307
 
253
308
  {/* Footer placeholder */}
254
309
  <div className="p-4 text-small text-white/60">
255
- {showLabels ? <span>v1.0.0</span> : null}
310
+ {showLabels ? <span>v2.4.0</span> : null}
256
311
  </div>
257
312
  </nav>
258
313
  </>
@@ -0,0 +1,38 @@
1
+ /** Scroll `#app-main` to an element id with an eased animation. */
2
+ export function scrollAppMainToId(id: string, durationMs = 700) {
3
+ const main = document.getElementById("app-main");
4
+ const el = document.getElementById(id);
5
+ if (!main || !el) return false;
6
+
7
+ const target =
8
+ el.getBoundingClientRect().top -
9
+ main.getBoundingClientRect().top +
10
+ main.scrollTop -
11
+ 12;
12
+ const start = main.scrollTop;
13
+ const delta = Math.max(0, target) - start;
14
+ if (Math.abs(delta) < 1) return true;
15
+
16
+ const startTime = performance.now();
17
+ const easeInOutCubic = (t: number) =>
18
+ t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
19
+
20
+ const step = (now: number) => {
21
+ const t = Math.min(1, (now - startTime) / durationMs);
22
+ main.scrollTop = start + delta * easeInOutCubic(t);
23
+ if (t < 1) requestAnimationFrame(step);
24
+ };
25
+ requestAnimationFrame(step);
26
+ return true;
27
+ }
28
+
29
+ /** Retry until the section exists (e.g. after a route change). */
30
+ export function scrollAppMainToIdWhenReady(id: string, durationMs = 700) {
31
+ if (scrollAppMainToId(id, durationMs)) return;
32
+ let tries = 0;
33
+ const tick = () => {
34
+ if (scrollAppMainToId(id, durationMs) || ++tries > 20) return;
35
+ requestAnimationFrame(tick);
36
+ };
37
+ requestAnimationFrame(tick);
38
+ }
@@ -1,5 +1,4 @@
1
1
  import type { NextConfig } from "next";
2
- import path from "node:path";
3
2
  import { networkInterfaces } from "node:os";
4
3
 
5
4
  function lanHostnames(): string[] {
@@ -15,24 +14,8 @@ function lanHostnames(): string[] {
15
14
  return [...hosts];
16
15
  }
17
16
 
18
- const monorepoRoot = path.join(__dirname, "..", "..");
19
-
20
17
  const nextConfig: NextConfig = {
21
18
  allowedDevOrigins: lanHostnames(),
22
- experimental: {
23
- externalDir: true,
24
- },
25
- turbopack: {
26
- root: monorepoRoot,
27
- resolveAlias: {
28
- "@/components/ui": "../../components/components/ui",
29
- react: "./node_modules/react",
30
- "react/jsx-runtime": "./node_modules/react/jsx-runtime.js",
31
- "react/jsx-dev-runtime": "./node_modules/react/jsx-dev-runtime.js",
32
- "react-dom": "./node_modules/react-dom",
33
- "lucide-react": "./node_modules/lucide-react",
34
- },
35
- },
36
19
  };
37
20
 
38
21
  export default nextConfig;