create-modoock-app 2.6.0 → 2.7.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.
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
 
3
+ import { useEffect, useRef, useState } from "react";
3
4
  import { usePathname, useRouter } from "next/navigation";
4
- import { ClickableButton, Icon } from "@modoock/components";
5
+ import { Avatar, ClickableButton, Icon, Modal } from "@modoock/components";
6
+ import type { IconName } from "@modoock/components";
5
7
 
6
8
  /**
7
9
  * Titre (et sous-titre optionnel) affiché dans le header pour chaque route.
@@ -16,6 +18,60 @@ const HEADER_META: Record<string, { title: string; description?: string }> = {
16
18
  },
17
19
  };
18
20
 
21
+ const ACCOUNT_USER = {
22
+ name: "Amine Berrada",
23
+ role: "Médecin",
24
+ email: "amine.berrada@modoock.com",
25
+ };
26
+
27
+ type NotificationItem = {
28
+ id: string;
29
+ title: string;
30
+ description: string;
31
+ time: string;
32
+ unread: boolean;
33
+ };
34
+
35
+ const DEMO_NOTIFICATIONS: NotificationItem[] = [
36
+ {
37
+ id: "1",
38
+ title: "Mise à jour disponible",
39
+ description: "La version 2.5.1 du design system est prête.",
40
+ time: "Il y a 10 min",
41
+ unread: true,
42
+ },
43
+ {
44
+ id: "2",
45
+ title: "Nouveau composant",
46
+ description: "Le composant Avatar est documenté dans le catalogue.",
47
+ time: "Il y a 1 h",
48
+ unread: true,
49
+ },
50
+ {
51
+ id: "3",
52
+ title: "Rappel",
53
+ description: "Pensez à synchroniser vos jetons locaux.",
54
+ time: "Hier",
55
+ unread: false,
56
+ },
57
+ ];
58
+
59
+ type AccountAction = {
60
+ label: string;
61
+ icon: IconName;
62
+ danger?: boolean;
63
+ href?: string;
64
+ };
65
+
66
+ const ACCOUNT_ACTIONS: AccountAction[] = [
67
+ { label: "Profil", icon: "User" },
68
+ { label: "Paramètres", icon: "Settings" },
69
+ { label: "Aide", icon: "CircleQuestionMark", href: "/documentation" },
70
+ { label: "Déconnexion", icon: "LogOut", danger: true },
71
+ ];
72
+
73
+ type OpenPanel = "notifications" | "account" | null;
74
+
19
75
  export default function Header({
20
76
  menuOpen,
21
77
  onOpenMenu,
@@ -25,6 +81,12 @@ export default function Header({
25
81
  }) {
26
82
  const pathname = usePathname();
27
83
  const router = useRouter();
84
+ const [openPanel, setOpenPanel] = useState<OpenPanel>(null);
85
+ const [logoutOpen, setLogoutOpen] = useState(false);
86
+ const [notifications, setNotifications] =
87
+ useState<NotificationItem[]>(DEMO_NOTIFICATIONS);
88
+ const notificationsRef = useRef<HTMLDivElement>(null);
89
+ const accountRef = useRef<HTMLDivElement>(null);
28
90
 
29
91
  const meta =
30
92
  HEADER_META[pathname] ??
@@ -32,6 +94,39 @@ export default function Header({
32
94
  ? { title: "Dossier patient" }
33
95
  : { title: "Modoock" });
34
96
 
97
+ const unreadCount = notifications.filter((item) => item.unread).length;
98
+
99
+ useEffect(() => {
100
+ if (!openPanel) return;
101
+
102
+ const onKeyDown = (event: KeyboardEvent) => {
103
+ if (event.key === "Escape") setOpenPanel(null);
104
+ };
105
+
106
+ // backdrop-filter on the sticky header traps fixed overlays — listen on the document instead.
107
+ const onPointerDown = (event: PointerEvent) => {
108
+ const target = event.target as Node;
109
+ const root =
110
+ openPanel === "notifications"
111
+ ? notificationsRef.current
112
+ : accountRef.current;
113
+ if (root && !root.contains(target)) setOpenPanel(null);
114
+ };
115
+
116
+ document.addEventListener("keydown", onKeyDown);
117
+ document.addEventListener("pointerdown", onPointerDown);
118
+ return () => {
119
+ document.removeEventListener("keydown", onKeyDown);
120
+ document.removeEventListener("pointerdown", onPointerDown);
121
+ };
122
+ }, [openPanel]);
123
+
124
+ const togglePanel = (panel: Exclude<OpenPanel, null>) => {
125
+ setOpenPanel((current) => (current === panel ? null : panel));
126
+ };
127
+
128
+ const closePanel = () => setOpenPanel(null);
129
+
35
130
  const handleRefresh = () => {
36
131
  router.refresh();
37
132
  };
@@ -40,8 +135,28 @@ export default function Header({
40
135
  router.back();
41
136
  };
42
137
 
138
+ const markAllRead = () => {
139
+ setNotifications((items) =>
140
+ items.map((item) => ({ ...item, unread: false })),
141
+ );
142
+ };
143
+
144
+ const handleAccountAction = (action: AccountAction) => {
145
+ closePanel();
146
+ if (action.danger) {
147
+ setLogoutOpen(true);
148
+ return;
149
+ }
150
+ if (action.href) router.push(action.href);
151
+ };
152
+
153
+ const confirmLogout = () => {
154
+ setLogoutOpen(false);
155
+ router.push("/auth/login");
156
+ };
157
+
43
158
  return (
44
- <header className="flex items-center justify-between gap-inline bg-background px-component pb-control pt-component">
159
+ <header className="sticky top-0 z-30 flex items-center justify-between gap-inline border-b border-border bg-background/95 px-component pb-control pt-component backdrop-blur-sm">
45
160
  <div className="flex min-w-0 items-center gap-inline">
46
161
  <ClickableButton
47
162
  type="button"
@@ -76,10 +191,226 @@ export default function Header({
76
191
  )}
77
192
  </div>
78
193
  </div>
79
- <ClickableButton type="button" onClick={handleRefresh} variant="secondary">
80
- <Icon name="RefreshCw" aria-hidden="true" />
81
- Actualiser
82
- </ClickableButton>
194
+
195
+ <div className="flex shrink-0 items-center gap-micro">
196
+ <ClickableButton
197
+ type="button"
198
+ onClick={handleRefresh}
199
+ variant="ghost"
200
+ size="icon"
201
+ aria-label="Actualiser la page"
202
+ title="Actualiser"
203
+ >
204
+ <Icon name="RefreshCw" aria-hidden="true" />
205
+ </ClickableButton>
206
+
207
+ {/* Notifications — un seul panneau ouvert à la fois (dropdowns.mdc). */}
208
+ <div className="relative" ref={notificationsRef}>
209
+ <ClickableButton
210
+ type="button"
211
+ variant="ghost"
212
+ size="icon"
213
+ aria-label={
214
+ unreadCount > 0
215
+ ? `Notifications, ${unreadCount} non lues`
216
+ : "Notifications"
217
+ }
218
+ aria-haspopup="menu"
219
+ aria-expanded={openPanel === "notifications"}
220
+ onClick={() => togglePanel("notifications")}
221
+ className="relative"
222
+ >
223
+ <Icon name="Bell" aria-hidden="true" />
224
+ {unreadCount > 0 && (
225
+ <span
226
+ className="absolute right-2 top-2 size-2 rounded-full bg-danger"
227
+ aria-hidden="true"
228
+ />
229
+ )}
230
+ </ClickableButton>
231
+
232
+ {openPanel === "notifications" && (
233
+ <div
234
+ role="menu"
235
+ aria-label="Notifications"
236
+ className="absolute right-0 z-50 mt-micro flex w-[min(22rem,calc(100vw-2rem))] flex-col overflow-hidden rounded-medium border border-border bg-surface shadow-lg"
237
+ >
238
+ <div className="flex items-center justify-between gap-inline border-b border-border px-component py-control">
239
+ <p className="text-component-title text-foreground">
240
+ Notifications
241
+ </p>
242
+ {unreadCount > 0 && (
243
+ <ClickableButton
244
+ type="button"
245
+ variant="bare"
246
+ size="sm"
247
+ onClick={markAllRead}
248
+ className="h-auto px-0 py-0 text-small text-primary hover:underline"
249
+ >
250
+ Tout marquer comme lu
251
+ </ClickableButton>
252
+ )}
253
+ </div>
254
+
255
+ {notifications.length === 0 ? (
256
+ <div className="px-component py-section text-center">
257
+ <Icon
258
+ name="BellOff"
259
+ variant="muted"
260
+ className="mx-auto"
261
+ aria-hidden="true"
262
+ />
263
+ <p className="mt-inline text-body-medium text-foreground">
264
+ Aucune notification
265
+ </p>
266
+ <p className="mt-micro text-small text-muted-foreground">
267
+ Les nouvelles alertes apparaîtront ici.
268
+ </p>
269
+ </div>
270
+ ) : (
271
+ <ul className="max-h-80 overflow-y-auto py-micro">
272
+ {notifications.map((item) => (
273
+ <li key={item.id}>
274
+ <button
275
+ type="button"
276
+ role="menuitem"
277
+ onClick={() => {
278
+ setNotifications((items) =>
279
+ items.map((n) =>
280
+ n.id === item.id ? { ...n, unread: false } : n,
281
+ ),
282
+ );
283
+ closePanel();
284
+ }}
285
+ className="flex w-full gap-inline px-component py-control text-left transition-colors duration-200 ease-out hover:bg-surface-muted focus-visible:bg-surface-muted focus-visible:outline-none motion-reduce:transition-none"
286
+ >
287
+ <span
288
+ className={`mt-2 size-2 shrink-0 rounded-full ${
289
+ item.unread ? "bg-primary" : "bg-transparent"
290
+ }`}
291
+ aria-hidden="true"
292
+ />
293
+ <span className="min-w-0 flex-1">
294
+ <span className="flex items-start justify-between gap-inline">
295
+ <span
296
+ className={`truncate text-body-medium ${
297
+ item.unread
298
+ ? "font-medium text-foreground"
299
+ : "text-foreground"
300
+ }`}
301
+ >
302
+ {item.title}
303
+ </span>
304
+ <span className="shrink-0 text-label text-muted-foreground">
305
+ {item.time}
306
+ </span>
307
+ </span>
308
+ <span className="mt-micro line-clamp-2 text-small text-muted-foreground">
309
+ {item.description}
310
+ </span>
311
+ </span>
312
+ </button>
313
+ </li>
314
+ ))}
315
+ </ul>
316
+ )}
317
+ </div>
318
+ )}
319
+ </div>
320
+
321
+ {/* Compte */}
322
+ <div className="relative" ref={accountRef}>
323
+ <ClickableButton
324
+ type="button"
325
+ variant="ghost"
326
+ aria-label="Menu du compte"
327
+ aria-haspopup="menu"
328
+ aria-expanded={openPanel === "account"}
329
+ onClick={() => togglePanel("account")}
330
+ className="h-auto gap-inline rounded-full py-micro pl-micro pr-control"
331
+ >
332
+ <Avatar
333
+ name={ACCOUNT_USER.name}
334
+ size="sm"
335
+ variant="primary"
336
+ status="online"
337
+ />
338
+ <span className="hidden min-w-0 text-left sm:block">
339
+ <span className="block max-w-36 truncate text-body-medium text-foreground">
340
+ {ACCOUNT_USER.name}
341
+ </span>
342
+ <span className="block max-w-36 truncate text-label text-muted-foreground">
343
+ {ACCOUNT_USER.role}
344
+ </span>
345
+ </span>
346
+ <Icon
347
+ name="ChevronDown"
348
+ size="small"
349
+ aria-hidden="true"
350
+ className={`hidden transition-transform duration-200 ease-out motion-reduce:transition-none sm:block ${
351
+ openPanel === "account" ? "rotate-180" : ""
352
+ }`}
353
+ />
354
+ </ClickableButton>
355
+
356
+ {openPanel === "account" && (
357
+ <div
358
+ role="menu"
359
+ aria-label="Compte"
360
+ className="absolute right-0 z-50 mt-micro flex min-w-56 max-w-[16rem] flex-col overflow-hidden rounded-medium border border-border bg-surface shadow-lg"
361
+ >
362
+ <div className="border-b border-border px-component py-control">
363
+ <p className="truncate text-body-medium text-foreground">
364
+ {ACCOUNT_USER.name}
365
+ </p>
366
+ <p className="truncate text-small text-muted-foreground">
367
+ {ACCOUNT_USER.email}
368
+ </p>
369
+ </div>
370
+ <div className="flex flex-col p-micro">
371
+ {ACCOUNT_ACTIONS.map((action, index) => (
372
+ <div key={action.label}>
373
+ {action.danger && index > 0 && (
374
+ <div className="mx-micro my-micro h-px bg-border" />
375
+ )}
376
+ <button
377
+ type="button"
378
+ role="menuitem"
379
+ onClick={() => handleAccountAction(action)}
380
+ className={`flex w-full items-center gap-inline rounded-small px-component py-control text-left text-body-medium transition-colors duration-200 ease-out hover:bg-surface-muted focus-visible:ring-primary motion-reduce:transition-none ${
381
+ action.danger ? "text-danger" : "text-foreground"
382
+ }`}
383
+ >
384
+ <Icon
385
+ name={action.icon}
386
+ size="small"
387
+ variant={action.danger ? "danger" : "muted"}
388
+ aria-hidden="true"
389
+ />
390
+ {action.label}
391
+ </button>
392
+ </div>
393
+ ))}
394
+ </div>
395
+ </div>
396
+ )}
397
+ </div>
398
+ </div>
399
+
400
+ <Modal
401
+ open={logoutOpen}
402
+ title="Déconnexion"
403
+ onClose={() => setLogoutOpen(false)}
404
+ primaryAction={{ label: "Se déconnecter", onClick: confirmLogout }}
405
+ secondaryAction={{
406
+ label: "Annuler",
407
+ onClick: () => setLogoutOpen(false),
408
+ }}
409
+ >
410
+ <p className="text-body text-muted-foreground">
411
+ Vous allez quitter votre session. Souhaitez-vous continuer ?
412
+ </p>
413
+ </Modal>
83
414
  </header>
84
415
  );
85
416
  }
@@ -1,3 +1,4 @@
1
1
  export { default as AppLayout } from "./app-layout";
2
2
  export { default as Header } from "./header";
3
3
  export { default as SideNav } from "./side-nav";
4
+ export { default as ToasterHost } from "./toaster-host";
@@ -69,6 +69,8 @@ const NAV_ITEMS: NavItem[] = [
69
69
  { label: "Catalogue", href: "/components" },
70
70
  { label: "Champs de saisie", href: "/components/champs" },
71
71
  { label: "Boutons", href: "/components/boutons" },
72
+ { label: "Interrupteur", href: "/components/interrupteur" },
73
+ { label: "Infobulle", href: "/components/infobulle" },
72
74
  { label: "Icônes", href: "/components/icones" },
73
75
  { label: "Loader", href: "/components/loader" },
74
76
  { label: "Badges", href: "/components/badges" },
@@ -78,7 +80,10 @@ const NAV_ITEMS: NavItem[] = [
78
80
  { label: "Agenda", href: "/components/agenda" },
79
81
  { label: "Onglets", href: "/components/onglets" },
80
82
  { label: "Modale", href: "/components/modale" },
83
+ { label: "Tiroir", href: "/components/tiroir" },
84
+ { label: "Toasts", href: "/components/toasts" },
81
85
  { label: "Barres de métrique", href: "/components/barres-de-metrique" },
86
+ { label: "Graphiques", href: "/components/graphiques" },
82
87
  { label: "Stepper", href: "/components/stepper" },
83
88
  { label: "Tableau", href: "/components/tableau" },
84
89
  ],
@@ -0,0 +1,8 @@
1
+ "use client";
2
+
3
+ import { Toaster } from "@modoock/components";
4
+
5
+ /** Monte le conteneur des toasts une seule fois au niveau racine. */
6
+ export default function ToasterHost() {
7
+ return <Toaster position="bottom-right" />;
8
+ }