@molecule/app-top-nav-layout-react 4.0.2 → 4.1.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.
- package/README.md +20 -7
- package/dist/TopNavLayout.d.ts +12 -2
- package/dist/TopNavLayout.d.ts.map +1 -1
- package/dist/TopNavLayout.js +14 -5
- package/dist/nav-item-active.d.ts +17 -0
- package/dist/nav-item-active.d.ts.map +1 -0
- package/dist/nav-item-active.js +21 -0
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-22T17:17:44.113Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-top-nav-layout-react
|
|
@@ -40,7 +40,7 @@ const userMenu = <button type="button">Account</button>
|
|
|
40
40
|
## Installation
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
-
npm install @molecule/app-top-nav-layout-react @molecule/app-react @molecule/app-ui react
|
|
43
|
+
npm install @molecule/app-top-nav-layout-react @molecule/app-react @molecule/app-ui react
|
|
44
44
|
npm install -D @types/react
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -79,12 +79,22 @@ interface TopNavLayoutProps {
|
|
|
79
79
|
navItems: ReadonlyArray<TopNavItem>
|
|
80
80
|
/** Slot rendered at the right of the header (typically a `<UserMenu />`). */
|
|
81
81
|
userMenu?: ReactNode
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Aria-label for the primary `<nav>`. Overrides the translated /
|
|
84
|
+
* `defaultValue` `'Primary navigation'` (prop > `t()` > default).
|
|
85
|
+
*/
|
|
83
86
|
navAriaLabel?: string
|
|
84
87
|
/** Extra classes on the outer wrapper. */
|
|
85
88
|
className?: string
|
|
86
89
|
/** `data-mol-id` for AI-agent selectors. */
|
|
87
90
|
dataMolId?: string
|
|
91
|
+
/**
|
|
92
|
+
* The page body, rendered in the `<main>`. Without it the layout renders
|
|
93
|
+
* `<RoutedView />`: the matched child route, through whichever routing bond
|
|
94
|
+
* the app wired. That throws when the routing bond has no routed view
|
|
95
|
+
* (Next.js gives a layout its page as `children`): pass the page then.
|
|
96
|
+
*/
|
|
97
|
+
children?: ReactNode
|
|
88
98
|
}
|
|
89
99
|
```
|
|
90
100
|
|
|
@@ -100,9 +110,10 @@ function TopNavLayout({
|
|
|
100
110
|
logoTo = '/',
|
|
101
111
|
navItems,
|
|
102
112
|
userMenu,
|
|
103
|
-
navAriaLabel
|
|
113
|
+
navAriaLabel,
|
|
104
114
|
className,
|
|
105
115
|
dataMolId,
|
|
116
|
+
children,
|
|
106
117
|
}: TopNavLayoutProps): JSX.Element
|
|
107
118
|
```
|
|
108
119
|
|
|
@@ -114,17 +125,15 @@ function TopNavLayout({
|
|
|
114
125
|
|
|
115
126
|
Peer dependencies:
|
|
116
127
|
|
|
117
|
-
- `@molecule/app-react` ^4.
|
|
128
|
+
- `@molecule/app-react` ^4.12.0
|
|
118
129
|
- `@molecule/app-ui` ^1.3.11
|
|
119
130
|
- `react` ^18.0.0 || ^19.0.0
|
|
120
|
-
- `react-router` ^7.0.0 || ^8.0.0
|
|
121
131
|
|
|
122
132
|
### Runtime Dependencies
|
|
123
133
|
|
|
124
134
|
- `@molecule/app-react`
|
|
125
135
|
- `@molecule/app-ui`
|
|
126
136
|
- `react`
|
|
127
|
-
- `react-router`
|
|
128
137
|
|
|
129
138
|
Requires React Router: render it as a LAYOUT ROUTE element
|
|
130
139
|
(`<Route element={<TopNavLayout ... />}>` with child routes) — the page
|
|
@@ -137,3 +146,7 @@ calls with raw Tailwind + Material-3 tokens (`bg-surface`,
|
|
|
137
146
|
source-scans this package's dist and a theme defining those tokens are
|
|
138
147
|
prerequisites — under a non-Tailwind ClassMap bond the header renders
|
|
139
148
|
unstyled. `label` is rendered as-is: pass an already-translated string.
|
|
149
|
+
|
|
150
|
+
## Translations
|
|
151
|
+
|
|
152
|
+
Translation strings are provided by `@molecule/app-locales-top-nav-layout`.
|
package/dist/TopNavLayout.d.ts
CHANGED
|
@@ -20,17 +20,27 @@ export interface TopNavLayoutProps {
|
|
|
20
20
|
navItems: ReadonlyArray<TopNavItem>;
|
|
21
21
|
/** Slot rendered at the right of the header (typically a `<UserMenu />`). */
|
|
22
22
|
userMenu?: ReactNode;
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Aria-label for the primary `<nav>`. Overrides the translated /
|
|
25
|
+
* `defaultValue` `'Primary navigation'` (prop > `t()` > default).
|
|
26
|
+
*/
|
|
24
27
|
navAriaLabel?: string;
|
|
25
28
|
/** Extra classes on the outer wrapper. */
|
|
26
29
|
className?: string;
|
|
27
30
|
/** `data-mol-id` for AI-agent selectors. */
|
|
28
31
|
dataMolId?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The page body, rendered in the `<main>`. Without it the layout renders
|
|
34
|
+
* `<RoutedView />`: the matched child route, through whichever routing bond
|
|
35
|
+
* the app wired. That throws when the routing bond has no routed view
|
|
36
|
+
* (Next.js gives a layout its page as `children`): pass the page then.
|
|
37
|
+
*/
|
|
38
|
+
children?: ReactNode;
|
|
29
39
|
}
|
|
30
40
|
/**
|
|
31
41
|
* Sticky top-nav shell with brand + horizontal nav + user-menu slot.
|
|
32
42
|
*
|
|
33
43
|
* @param props - Component props (see {@link TopNavLayoutProps}).
|
|
34
44
|
*/
|
|
35
|
-
export declare function TopNavLayout({ appName, logoTo, navItems, userMenu, navAriaLabel, className, dataMolId, }: TopNavLayoutProps): JSX.Element;
|
|
45
|
+
export declare function TopNavLayout({ appName, logoTo, navItems, userMenu, navAriaLabel, className, dataMolId, children, }: TopNavLayoutProps): JSX.Element;
|
|
36
46
|
//# sourceMappingURL=TopNavLayout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TopNavLayout.d.ts","sourceRoot":"","sources":["../src/TopNavLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"TopNavLayout.d.ts","sourceRoot":"","sources":["../src/TopNavLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAQ3C,4DAA4D;AAC5D,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,EAAE,EAAE,MAAM,CAAA;IACV,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAA;IACX,wEAAwE;IACxE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4FAA4F;IAC5F,KAAK,EAAE,MAAM,CAAA;CACd;AAED,0DAA0D;AAC1D,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,mDAAmD;IACnD,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;IACnC,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,MAAY,EACZ,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,SAAS,EACT,QAAQ,GACT,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAiEjC"}
|
package/dist/TopNavLayout.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { RoutedView, useLocation, useTranslation } from '@molecule/app-react';
|
|
3
|
+
import { Link } from '@molecule/app-react/link';
|
|
3
4
|
import { getClassMap } from '@molecule/app-ui';
|
|
5
|
+
import { navItemActive } from './nav-item-active.js';
|
|
4
6
|
/**
|
|
5
7
|
* Sticky top-nav shell with brand + horizontal nav + user-menu slot.
|
|
6
8
|
*
|
|
7
9
|
* @param props - Component props (see {@link TopNavLayoutProps}).
|
|
8
10
|
*/
|
|
9
|
-
export function TopNavLayout({ appName, logoTo = '/', navItems, userMenu, navAriaLabel
|
|
11
|
+
export function TopNavLayout({ appName, logoTo = '/', navItems, userMenu, navAriaLabel, className, dataMolId, children, }) {
|
|
12
|
+
const { t } = useTranslation();
|
|
13
|
+
const { pathname } = useLocation();
|
|
10
14
|
const cm = getClassMap();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
const navLabel = navAriaLabel ??
|
|
16
|
+
t('topNavLayout.aria.primaryNavigation', undefined, { defaultValue: 'Primary navigation' });
|
|
17
|
+
return (_jsxs("div", { className: cm.cn(cm.minH('screen'), cm.topNavLayoutRoot, className), "data-mol-id": dataMolId, children: [_jsx("header", { className: cm.cn(cm.topNavLayoutHeader), children: _jsxs("div", { className: cm.cn(cm.maxW('7xl'), cm.mxAuto, cm.sp('px', 6), cm.sp('py', 3), cm.flex({ align: 'center', justify: 'between', gap: 'lg' })), children: [_jsx(Link, { to: logoTo, className: cm.cn(cm.textSize('2xl'), cm.fontWeight('bold')), children: appName }), _jsx("nav", { className: cm.flex({ align: 'center', gap: 'md' }), "aria-label": navLabel, children: navItems.map((item) => {
|
|
18
|
+
const isActive = navItemActive(pathname, item.to);
|
|
19
|
+
return (_jsxs(Link, { to: item.to, "aria-label": item.label, "aria-current": isActive ? 'page' : undefined, className: cm.cn(cm.flex({ align: 'center', gap: 'xs' }), cm.sp('px', 3), cm.sp('py', 2), cm.textSize('sm'), cm.fontWeight('medium'), cm.topNavLayoutNavItem, isActive
|
|
20
|
+
? cm.cn(cm.bgPrimaryContainer, cm.textPrimary)
|
|
21
|
+
: cm.cn(cm.textMuted, cm.topNavLayoutNavItemIdle)), children: [item.icon ? (_jsx("span", { className: cm.iconGlyphFont, "aria-hidden": "true", children: item.icon })) : null, _jsx("span", { className: cm.topNavLayoutNavItemLabel, children: item.label })] }, item.key));
|
|
22
|
+
}) }), userMenu] }) }), _jsx("main", { children: children ?? _jsx(RoutedView, {}) })] }));
|
|
14
23
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The nav-item active rule of {@link TopNavLayout}, shared by every framework's top nav.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Whether a nav item linking to `to` shows as the current page at `pathname`: the pathnames are
|
|
8
|
+
* equal, or the location continues beyond `to` on a segment boundary (`/dashboard` is active at
|
|
9
|
+
* `/dashboard/settings`, but not at `/dashboard-archive`), compared case-insensitively. `/` is
|
|
10
|
+
* active only at `/`.
|
|
11
|
+
*
|
|
12
|
+
* @param pathname - The current location's pathname.
|
|
13
|
+
* @param to - The item's destination.
|
|
14
|
+
* @returns Whether the item renders in its active state.
|
|
15
|
+
*/
|
|
16
|
+
export declare const navItemActive: (pathname: string, to: string) => boolean;
|
|
17
|
+
//# sourceMappingURL=nav-item-active.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nav-item-active.d.ts","sourceRoot":"","sources":["../src/nav-item-active.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,EAAE,IAAI,MAAM,KAAG,OAK5D,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The nav-item active rule of {@link TopNavLayout}, shared by every framework's top nav.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Whether a nav item linking to `to` shows as the current page at `pathname`: the pathnames are
|
|
8
|
+
* equal, or the location continues beyond `to` on a segment boundary (`/dashboard` is active at
|
|
9
|
+
* `/dashboard/settings`, but not at `/dashboard-archive`), compared case-insensitively. `/` is
|
|
10
|
+
* active only at `/`.
|
|
11
|
+
*
|
|
12
|
+
* @param pathname - The current location's pathname.
|
|
13
|
+
* @param to - The item's destination.
|
|
14
|
+
* @returns Whether the item renders in its active state.
|
|
15
|
+
*/
|
|
16
|
+
export const navItemActive = (pathname, to) => {
|
|
17
|
+
const location = pathname.toLowerCase();
|
|
18
|
+
const target = to.toLowerCase();
|
|
19
|
+
const endSlash = target !== '/' && target.endsWith('/') ? target.length - 1 : target.length;
|
|
20
|
+
return location === target || (location.startsWith(target) && location.charAt(endSlash) === '/');
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-top-nav-layout-react",
|
|
3
|
-
"version": "4.0
|
|
4
|
-
"description": "Sticky top-nav app shell: brand link + horizontal NavLinks + user-menu slot, with
|
|
3
|
+
"version": "4.1.0",
|
|
4
|
+
"description": "Sticky top-nav app shell: brand link + horizontal NavLinks + user-menu slot, with a router outlet for nested routes",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/app-top-nav-layout-react",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -34,21 +34,20 @@
|
|
|
34
34
|
"directory": "packages/app/features/top-nav-layout-react"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@molecule/app-react": "^4.
|
|
37
|
+
"@molecule/app-react": "^4.12.0",
|
|
38
38
|
"@molecule/app-ui": "^1.3.11",
|
|
39
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
40
|
-
"react-router": "^7.0.0 || ^8.0.0"
|
|
39
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@molecule/app-react": "4.
|
|
44
|
-
"@molecule/app-ui": "1.
|
|
42
|
+
"@molecule/app-react": "4.12.0",
|
|
43
|
+
"@molecule/app-ui": "1.5.0",
|
|
45
44
|
"@types/node": "26.6.5",
|
|
46
45
|
"@types/react": "19.3.0",
|
|
47
46
|
"@types/react-dom": "19.3.0",
|
|
48
47
|
"react": "19.3.1",
|
|
49
48
|
"react-dom": "19.3.1",
|
|
50
|
-
"react-router": "8.5.0",
|
|
51
49
|
"typescript": "6.0.3",
|
|
52
|
-
"vitest": "4.1.12"
|
|
50
|
+
"vitest": "4.1.12",
|
|
51
|
+
"@molecule/app-routing": "1.5.2"
|
|
53
52
|
}
|
|
54
53
|
}
|