@molecule/app-top-nav-layout-react 4.0.3 → 4.1.1
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 +11 -5
- package/dist/TopNavLayout.d.ts +8 -1
- package/dist/TopNavLayout.d.ts.map +1 -1
- package/dist/TopNavLayout.js +13 -6
- 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 +7 -8
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-24T09:00:04.321Z
|
|
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
|
|
|
@@ -88,6 +88,13 @@ interface TopNavLayoutProps {
|
|
|
88
88
|
className?: string
|
|
89
89
|
/** `data-mol-id` for AI-agent selectors. */
|
|
90
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
|
|
91
98
|
}
|
|
92
99
|
```
|
|
93
100
|
|
|
@@ -106,6 +113,7 @@ function TopNavLayout({
|
|
|
106
113
|
navAriaLabel,
|
|
107
114
|
className,
|
|
108
115
|
dataMolId,
|
|
116
|
+
children: childrenProp,
|
|
109
117
|
}: TopNavLayoutProps): JSX.Element
|
|
110
118
|
```
|
|
111
119
|
|
|
@@ -117,17 +125,15 @@ function TopNavLayout({
|
|
|
117
125
|
|
|
118
126
|
Peer dependencies:
|
|
119
127
|
|
|
120
|
-
- `@molecule/app-react` ^4.
|
|
128
|
+
- `@molecule/app-react` ^4.13.0
|
|
121
129
|
- `@molecule/app-ui` ^1.3.11
|
|
122
130
|
- `react` ^18.0.0 || ^19.0.0
|
|
123
|
-
- `react-router` ^7.0.0 || ^8.0.0
|
|
124
131
|
|
|
125
132
|
### Runtime Dependencies
|
|
126
133
|
|
|
127
134
|
- `@molecule/app-react`
|
|
128
135
|
- `@molecule/app-ui`
|
|
129
136
|
- `react`
|
|
130
|
-
- `react-router`
|
|
131
137
|
|
|
132
138
|
Requires React Router: render it as a LAYOUT ROUTE element
|
|
133
139
|
(`<Route element={<TopNavLayout ... />}>` with child routes) — the page
|
package/dist/TopNavLayout.d.ts
CHANGED
|
@@ -29,11 +29,18 @@ export interface TopNavLayoutProps {
|
|
|
29
29
|
className?: string;
|
|
30
30
|
/** `data-mol-id` for AI-agent selectors. */
|
|
31
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;
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* Sticky top-nav shell with brand + horizontal nav + user-menu slot.
|
|
35
42
|
*
|
|
36
43
|
* @param props - Component props (see {@link TopNavLayoutProps}).
|
|
37
44
|
*/
|
|
38
|
-
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: childrenProp, }: TopNavLayoutProps): JSX.Element;
|
|
39
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;AAS3C,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,EAAE,YAAY,GACvB,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAkEjC"}
|
package/dist/TopNavLayout.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { RoutedView, useLocation, useTranslation } from '@molecule/app-react';
|
|
3
|
+
import { Link } from '@molecule/app-react/link';
|
|
4
|
+
import { slot } from '@molecule/app-react/render';
|
|
4
5
|
import { getClassMap } from '@molecule/app-ui';
|
|
6
|
+
import { navItemActive } from './nav-item-active.js';
|
|
5
7
|
/**
|
|
6
8
|
* Sticky top-nav shell with brand + horizontal nav + user-menu slot.
|
|
7
9
|
*
|
|
8
10
|
* @param props - Component props (see {@link TopNavLayoutProps}).
|
|
9
11
|
*/
|
|
10
|
-
export function TopNavLayout({ appName, logoTo = '/', navItems, userMenu, navAriaLabel, className, dataMolId, }) {
|
|
12
|
+
export function TopNavLayout({ appName, logoTo = '/', navItems, userMenu, navAriaLabel, className, dataMolId, children: childrenProp, }) {
|
|
13
|
+
const children = slot(childrenProp);
|
|
11
14
|
const { t } = useTranslation();
|
|
15
|
+
const { pathname } = useLocation();
|
|
12
16
|
const cm = getClassMap();
|
|
13
17
|
const navLabel = navAriaLabel ??
|
|
14
18
|
t('topNavLayout.aria.primaryNavigation', undefined, { defaultValue: 'Primary navigation' });
|
|
15
|
-
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) =>
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
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) => {
|
|
20
|
+
const isActive = navItemActive(pathname, item.to);
|
|
21
|
+
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
|
|
22
|
+
? cm.cn(cm.bgPrimaryContainer, cm.textPrimary)
|
|
23
|
+
: 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));
|
|
24
|
+
}) }), userMenu] }) }), _jsx("main", { children: children ?? _jsx(RoutedView, {}) })] }));
|
|
18
25
|
}
|
|
@@ -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.
|
|
4
|
-
"description": "Sticky top-nav app shell: brand link + horizontal NavLinks + user-menu slot, with
|
|
3
|
+
"version": "4.1.1",
|
|
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.13.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.
|
|
42
|
+
"@molecule/app-react": "4.13.0",
|
|
44
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.3"
|
|
53
52
|
}
|
|
54
53
|
}
|