@lukoweb/apitogo-module-user-panel 0.2.38 → 0.2.40

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo-module-user-panel",
3
- "version": "0.2.38",
3
+ "version": "0.2.40",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.tsx"
@@ -14,7 +14,7 @@
14
14
  "devDependencies": {
15
15
  "@types/react": "19.2.14",
16
16
  "@types/react-dom": "19.2.3",
17
- "@lukoweb/apitogo": "0.2.38",
17
+ "@lukoweb/apitogo": "0.2.40",
18
18
  "react": "19.2.4",
19
19
  "react-dom": "19.2.4",
20
20
  "react-router": "7.13.1",
@@ -1,119 +1,135 @@
1
- import { cn } from "@lukoweb/apitogo";
2
- import { useAuth } from "@lukoweb/apitogo/hooks";
3
- import {
4
- BookOpenIcon,
5
- CreditCardIcon,
6
- KeyRoundIcon,
7
- LayoutGridIcon,
8
- LogOutIcon,
9
- SettingsIcon,
10
- BarChart3Icon,
11
- } from "@lukoweb/apitogo/icons";
12
- import { Link, NavLink, Outlet } from "@lukoweb/apitogo/router";
13
- import type { ReactNode } from "react";
14
- import {
15
- buildAccountNavPaths,
16
- DEFAULT_ACCOUNT_BASE_PATH,
17
- } from "../account-paths.js";
18
-
19
- type AccountNavItem = {
20
- label: string;
21
- to: string;
22
- icon: typeof LayoutGridIcon;
23
- };
24
-
25
- export type AccountLayoutProps = {
26
- basePath?: string;
27
- docsPath?: string;
28
- children?: ReactNode;
29
- /** When true, show API keys / Usage / Billing (billing plugin routes). */
30
- includeBillingNav?: boolean;
31
- };
32
-
33
- export function AccountLayout({
34
- basePath = DEFAULT_ACCOUNT_BASE_PATH,
35
- docsPath = "/introduction",
36
- children,
37
- includeBillingNav = false,
38
- }: AccountLayoutProps) {
39
- const auth = useAuth();
40
- const paths = buildAccountNavPaths(basePath, docsPath);
41
-
42
- const navItems: AccountNavItem[] = [
43
- { label: "Overview", to: paths.overview, icon: LayoutGridIcon },
44
- ...(includeBillingNav
45
- ? [
46
- { label: "API keys", to: paths.apiKeys, icon: KeyRoundIcon },
47
- { label: "Usage", to: paths.usage, icon: BarChart3Icon },
48
- { label: "Billing", to: paths.billing, icon: CreditCardIcon },
49
- ]
50
- : []),
51
- { label: "Settings", to: paths.settings, icon: SettingsIcon },
52
- ];
53
-
54
- const renderNavLink = (item: AccountNavItem, compact = false) => (
55
- <NavLink
56
- key={item.to}
57
- to={item.to}
58
- end={item.to === paths.overview}
59
- className={({ isActive }) =>
60
- cn(
61
- compact
62
- ? "inline-flex shrink-0 items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors"
63
- : "flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors",
64
- isActive
65
- ? "bg-primary/14 font-semibold text-primary"
66
- : "text-muted-foreground hover:bg-muted/80 hover:text-foreground",
67
- )
68
- }
69
- >
70
- <item.icon
71
- size={compact ? 18 : 20}
72
- strokeWidth={1.8}
73
- className="shrink-0 opacity-80"
74
- />
75
- {item.label}
76
- </NavLink>
77
- );
78
-
79
- return (
80
- <div className="flex min-h-[calc(100dvh-var(--header-height))] flex-col bg-muted md:flex-row">
81
- <nav
82
- aria-label="Account"
83
- className="flex gap-1 overflow-x-auto border-b border-border bg-card px-3 py-2 md:hidden"
84
- >
85
- {navItems.map((item) => renderNavLink(item, true))}
86
- </nav>
87
-
88
- <aside className="hidden w-[236px] shrink-0 flex-col justify-between border-r border-border bg-card px-3 py-4 md:flex">
89
- <nav className="flex flex-col gap-1">
90
- {navItems.map((item) => renderNavLink(item))}
91
- </nav>
92
-
93
- <div className="flex flex-col gap-1 border-t border-border pt-3">
94
- <Link
95
- to={paths.docs}
96
- className="flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
97
- >
98
- <BookOpenIcon size={20} strokeWidth={1.8} className="shrink-0" />
99
- Documentation
100
- </Link>
101
- {auth.isAuthEnabled ? (
102
- <button
103
- type="button"
104
- className="flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
105
- onClick={() => {
106
- void auth.logout();
107
- }}
108
- >
109
- <LogOutIcon size={20} strokeWidth={1.8} className="shrink-0" />
110
- Log out
111
- </button>
112
- ) : null}
113
- </div>
114
- </aside>
115
-
116
- <main className="min-w-0 flex-1">{children ?? <Outlet />}</main>
117
- </div>
118
- );
119
- }
1
+ import { cn } from "@lukoweb/apitogo";
2
+ import { useAuth } from "@lukoweb/apitogo/hooks";
3
+ import {
4
+ BookOpenIcon,
5
+ CreditCardIcon,
6
+ KeyRoundIcon,
7
+ LayoutGridIcon,
8
+ LogOutIcon,
9
+ SettingsIcon,
10
+ BarChart3Icon,
11
+ } from "@lukoweb/apitogo/icons";
12
+ import { Link, NavLink, Outlet } from "@lukoweb/apitogo/router";
13
+ import type { ReactNode } from "react";
14
+ import {
15
+ buildAccountNavPaths,
16
+ DEFAULT_ACCOUNT_BASE_PATH,
17
+ } from "../account-paths.js";
18
+
19
+ type AccountNavItem = {
20
+ label: string;
21
+ to: string;
22
+ icon: typeof LayoutGridIcon;
23
+ };
24
+
25
+ export type AccountLayoutProps = {
26
+ basePath?: string;
27
+ /** Where the "Documentation" link goes: a path, an external address, or null for no link (the portal has no docs of its own). */
28
+ docsPath?: string | null;
29
+ /** The "Overview" entry; a portal that does not register the dashboard page leaves it out. */
30
+ includeOverview?: boolean;
31
+ children?: ReactNode;
32
+ /** When true, show API keys / Usage / Billing (billing plugin routes). */
33
+ includeBillingNav?: boolean;
34
+ };
35
+
36
+ export function AccountLayout({
37
+ basePath = DEFAULT_ACCOUNT_BASE_PATH,
38
+ docsPath = "/introduction",
39
+ includeOverview = true,
40
+ children,
41
+ includeBillingNav = false,
42
+ }: AccountLayoutProps) {
43
+ const auth = useAuth();
44
+ const paths = buildAccountNavPaths(basePath, docsPath ?? undefined);
45
+
46
+ const navItems: AccountNavItem[] = [
47
+ ...(includeOverview
48
+ ? [{ label: "Overview", to: paths.overview, icon: LayoutGridIcon }]
49
+ : []),
50
+ ...(includeBillingNav
51
+ ? [
52
+ { label: "API keys", to: paths.apiKeys, icon: KeyRoundIcon },
53
+ { label: "Usage", to: paths.usage, icon: BarChart3Icon },
54
+ { label: "Billing", to: paths.billing, icon: CreditCardIcon },
55
+ ]
56
+ : []),
57
+ { label: "Settings", to: paths.settings, icon: SettingsIcon },
58
+ ];
59
+
60
+ const renderNavLink = (item: AccountNavItem, compact = false) => (
61
+ <NavLink
62
+ key={item.to}
63
+ to={item.to}
64
+ end={item.to === paths.overview}
65
+ className={({ isActive }) =>
66
+ cn(
67
+ compact
68
+ ? "inline-flex shrink-0 items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors"
69
+ : "flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors",
70
+ isActive
71
+ ? "bg-primary/14 font-semibold text-primary"
72
+ : "text-muted-foreground hover:bg-muted/80 hover:text-foreground",
73
+ )
74
+ }
75
+ >
76
+ <item.icon
77
+ size={compact ? 18 : 20}
78
+ strokeWidth={1.8}
79
+ className="shrink-0 opacity-80"
80
+ />
81
+ {item.label}
82
+ </NavLink>
83
+ );
84
+
85
+ return (
86
+ <div className="flex min-h-[calc(100dvh-var(--header-height))] flex-col bg-muted md:flex-row">
87
+ <nav
88
+ aria-label="Account"
89
+ className="flex gap-1 overflow-x-auto border-b border-border bg-card px-3 py-2 md:hidden"
90
+ >
91
+ {navItems.map((item) => renderNavLink(item, true))}
92
+ </nav>
93
+
94
+ <aside className="hidden w-[236px] shrink-0 flex-col justify-between border-r border-border bg-card px-3 py-4 md:flex">
95
+ <nav className="flex flex-col gap-1">
96
+ {navItems.map((item) => renderNavLink(item))}
97
+ </nav>
98
+
99
+ <div className="flex flex-col gap-1 border-t border-border pt-3">
100
+ {docsPath === null ? null : /^https?:\/\//.test(paths.docs) ? (
101
+ <a
102
+ href={paths.docs}
103
+ className="flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
104
+ >
105
+ <BookOpenIcon size={20} strokeWidth={1.8} className="shrink-0" />
106
+ Documentation
107
+ </a>
108
+ ) : (
109
+ <Link
110
+ to={paths.docs}
111
+ className="flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
112
+ >
113
+ <BookOpenIcon size={20} strokeWidth={1.8} className="shrink-0" />
114
+ Documentation
115
+ </Link>
116
+ )}
117
+ {auth.isAuthEnabled ? (
118
+ <button
119
+ type="button"
120
+ className="flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
121
+ onClick={() => {
122
+ void auth.logout();
123
+ }}
124
+ >
125
+ <LogOutIcon size={20} strokeWidth={1.8} className="shrink-0" />
126
+ Log out
127
+ </button>
128
+ ) : null}
129
+ </div>
130
+ </aside>
131
+
132
+ <main className="min-w-0 flex-1">{children ?? <Outlet />}</main>
133
+ </div>
134
+ );
135
+ }