@molecule/app-top-nav-layout-react 1.0.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/LICENSE ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-08-04T00:41:25.677Z
7
+ -->
8
+
9
+ # @molecule/app-top-nav-layout-react
10
+
11
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
+ > It is written to be read by coding agents as much as by people, and is generated from this
13
+ > package's source — edit `src/index.ts` JSDoc, not this file.
14
+
15
+ Top-navigation app shell layout for routed React apps.
16
+
17
+ Exports `<TopNavLayout>` — sticky header with brand link + horizontal
18
+ NavLinks + a user-menu slot, plus `<main>` rendering React Router's
19
+ `<Outlet />` — and the `TopNavItem` / `TopNavLayoutProps` types.
20
+
21
+ ## Quick Start
22
+
23
+ ```tsx
24
+ import { TopNavLayout, type TopNavItem } from '@molecule/app-top-nav-layout-react'
25
+
26
+ const NAV: TopNavItem[] = [
27
+ { key: 'dashboard', to: '/dashboard', icon: 'dashboard', label: 'Dashboard' },
28
+ { key: 'reports', to: '/reports', icon: 'bar_chart', label: 'Reports' },
29
+ ]
30
+
31
+ const userMenu = <button type="button">Account</button>
32
+
33
+ <TopNavLayout appName="Acme" navItems={NAV} userMenu={userMenu} />
34
+ ```
35
+
36
+ ## Type
37
+
38
+ `feature`
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @molecule/app-top-nav-layout-react @molecule/app-react @molecule/app-ui react react-router
44
+ npm install -D @types/react
45
+ ```
46
+
47
+ ## API
48
+
49
+ ### Interfaces
50
+
51
+ #### `TopNavItem`
52
+
53
+ A single navigation item rendered in the top nav bar.
54
+
55
+ ```typescript
56
+ interface TopNavItem {
57
+ /** Route path the link goes to. */
58
+ to: string
59
+ /** Stable key — used for React keys and i18n key suffix. */
60
+ key: string
61
+ /** Material symbol icon name (or any glyph) shown next to the label. */
62
+ icon?: string
63
+ /** Visible label. Apps that route this through `t(...)` should pass the resolved string. */
64
+ label: string
65
+ }
66
+ ```
67
+
68
+ #### `TopNavLayoutProps`
69
+
70
+ Props for the {@link TopNavLayout} shell component.
71
+
72
+ ```typescript
73
+ interface TopNavLayoutProps {
74
+ /** Brand text shown in the top-left link (typically the app name). */
75
+ appName: string
76
+ /** Path the brand link navigates to. Defaults to `'/'`. */
77
+ logoTo?: string
78
+ /** Horizontal nav items rendered in the header. */
79
+ navItems: ReadonlyArray<TopNavItem>
80
+ /** Slot rendered at the right of the header (typically a `<UserMenu />`). */
81
+ userMenu?: ReactNode
82
+ /** Aria-label for the primary <nav>. */
83
+ navAriaLabel?: string
84
+ /** Extra classes on the outer wrapper. */
85
+ className?: string
86
+ /** `data-mol-id` for AI-agent selectors. */
87
+ dataMolId?: string
88
+ }
89
+ ```
90
+
91
+ ### Functions
92
+
93
+ #### `TopNavLayout(props)`
94
+
95
+ Sticky top-nav shell with brand + horizontal nav + user-menu slot.
96
+
97
+ ```typescript
98
+ function TopNavLayout({
99
+ appName,
100
+ logoTo = '/',
101
+ navItems,
102
+ userMenu,
103
+ navAriaLabel = 'Primary navigation',
104
+ className,
105
+ dataMolId,
106
+ }: TopNavLayoutProps): JSX.Element
107
+ ```
108
+
109
+ - `props` — Component props (see {@link TopNavLayoutProps}).
110
+
111
+ ## Injection Notes
112
+
113
+ ### Requirements
114
+
115
+ Peer dependencies:
116
+
117
+ - `@molecule/app-react` ^1.0.0
118
+ - `@molecule/app-ui` ^1.0.0
119
+ - `react` ^18.0.0 || ^19.0.0
120
+ - `react-router` ^7.0.0 || ^8.0.0
121
+
122
+ ### Runtime Dependencies
123
+
124
+ - `@molecule/app-react`
125
+ - `@molecule/app-ui`
126
+ - `react`
127
+ - `react-router`
128
+
129
+ Requires React Router: render it as a LAYOUT ROUTE element
130
+ (`<Route element={<TopNavLayout ... />}>` with child routes) — the page
131
+ body comes from the router `<Outlet />`, never from children. Nav labels
132
+ are hidden below the `md` breakpoint (icon-only mobile nav), so always
133
+ provide `icon` names; they render as Material Symbols ligatures and need
134
+ the Material Symbols font loaded by the host app. Styling mixes ClassMap
135
+ calls with raw Tailwind + Material-3 tokens (`bg-surface`,
136
+ `bg-primary-container`, `hidden md:inline`), so a Tailwind build that
137
+ source-scans this package's dist and a theme defining those tokens are
138
+ prerequisites — under a non-Tailwind ClassMap bond the header renders
139
+ unstyled. `label` is rendered as-is: pass an already-translated string.
@@ -0,0 +1,36 @@
1
+ import type { JSX, ReactNode } from 'react';
2
+ /** A single navigation item rendered in the top nav bar. */
3
+ export interface TopNavItem {
4
+ /** Route path the link goes to. */
5
+ to: string;
6
+ /** Stable key — used for React keys and i18n key suffix. */
7
+ key: string;
8
+ /** Material symbol icon name (or any glyph) shown next to the label. */
9
+ icon?: string;
10
+ /** Visible label. Apps that route this through `t(...)` should pass the resolved string. */
11
+ label: string;
12
+ }
13
+ /** Props for the {@link TopNavLayout} shell component. */
14
+ export interface TopNavLayoutProps {
15
+ /** Brand text shown in the top-left link (typically the app name). */
16
+ appName: string;
17
+ /** Path the brand link navigates to. Defaults to `'/'`. */
18
+ logoTo?: string;
19
+ /** Horizontal nav items rendered in the header. */
20
+ navItems: ReadonlyArray<TopNavItem>;
21
+ /** Slot rendered at the right of the header (typically a `<UserMenu />`). */
22
+ userMenu?: ReactNode;
23
+ /** Aria-label for the primary <nav>. */
24
+ navAriaLabel?: string;
25
+ /** Extra classes on the outer wrapper. */
26
+ className?: string;
27
+ /** `data-mol-id` for AI-agent selectors. */
28
+ dataMolId?: string;
29
+ }
30
+ /**
31
+ * Sticky top-nav shell with brand + horizontal nav + user-menu slot.
32
+ *
33
+ * @param props - Component props (see {@link TopNavLayoutProps}).
34
+ */
35
+ export declare function TopNavLayout({ appName, logoTo, navItems, userMenu, navAriaLabel, className, dataMolId, }: TopNavLayoutProps): JSX.Element;
36
+ //# sourceMappingURL=TopNavLayout.d.ts.map
@@ -0,0 +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;AAK3C,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,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,MAAY,EACZ,QAAQ,EACR,QAAQ,EACR,YAAmC,EACnC,SAAS,EACT,SAAS,GACV,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAwDjC"}
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Link, NavLink, Outlet } from 'react-router';
3
+ import { getClassMap } from '@molecule/app-ui';
4
+ /**
5
+ * Sticky top-nav shell with brand + horizontal nav + user-menu slot.
6
+ *
7
+ * @param props - Component props (see {@link TopNavLayoutProps}).
8
+ */
9
+ export function TopNavLayout({ appName, logoTo = '/', navItems, userMenu, navAriaLabel = 'Primary navigation', className, dataMolId, }) {
10
+ const cm = getClassMap();
11
+ return (_jsxs("div", { className: cm.cn(cm.minH('screen'), 'bg-background text-on-surface antialiased', className), "data-mol-id": dataMolId, children: [_jsx("header", { className: cm.cn('sticky top-0 z-40 bg-surface shadow-sm'), 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": navAriaLabel, children: navItems.map((item) => (_jsxs(NavLink, { to: item.to, className: ({ isActive }) => cm.cn(cm.flex({ align: 'center', gap: 'xs' }), cm.sp('px', 3), cm.sp('py', 2), cm.textSize('sm'), cm.fontWeight('medium'), 'rounded-md transition-colors', isActive
12
+ ? cm.cn('bg-primary-container', cm.textPrimary)
13
+ : cm.cn(cm.textMuted, 'hover:bg-surface-container hover:text-on-surface')), children: [item.icon ? (_jsx("span", { className: "material-symbols-outlined", "aria-hidden": "true", children: item.icon })) : null, _jsx("span", { className: "hidden md:inline", children: item.label })] }, item.key))) }), userMenu] }) }), _jsx("main", { children: _jsx(Outlet, {}) })] }));
14
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Top-navigation app shell layout for routed React apps.
3
+ *
4
+ * Exports `<TopNavLayout>` — sticky header with brand link + horizontal
5
+ * NavLinks + a user-menu slot, plus `<main>` rendering React Router's
6
+ * `<Outlet />` — and the `TopNavItem` / `TopNavLayoutProps` types.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { TopNavLayout, type TopNavItem } from '@molecule/app-top-nav-layout-react'
11
+ *
12
+ * const NAV: TopNavItem[] = [
13
+ * { key: 'dashboard', to: '/dashboard', icon: 'dashboard', label: 'Dashboard' },
14
+ * { key: 'reports', to: '/reports', icon: 'bar_chart', label: 'Reports' },
15
+ * ]
16
+ *
17
+ * const userMenu = <button type="button">Account</button>
18
+ *
19
+ * <TopNavLayout appName="Acme" navItems={NAV} userMenu={userMenu} />
20
+ * ```
21
+ *
22
+ * @remarks
23
+ * Requires React Router: render it as a LAYOUT ROUTE element
24
+ * (`<Route element={<TopNavLayout ... />}>` with child routes) — the page
25
+ * body comes from the router `<Outlet />`, never from children. Nav labels
26
+ * are hidden below the `md` breakpoint (icon-only mobile nav), so always
27
+ * provide `icon` names; they render as Material Symbols ligatures and need
28
+ * the Material Symbols font loaded by the host app. Styling mixes ClassMap
29
+ * calls with raw Tailwind + Material-3 tokens (`bg-surface`,
30
+ * `bg-primary-container`, `hidden md:inline`), so a Tailwind build that
31
+ * source-scans this package's dist and a theme defining those tokens are
32
+ * prerequisites — under a non-Tailwind ClassMap bond the header renders
33
+ * unstyled. `label` is rendered as-is: pass an already-translated string.
34
+ *
35
+ * @module
36
+ */
37
+ export * from './TopNavLayout.js';
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,cAAc,mBAAmB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Top-navigation app shell layout for routed React apps.
3
+ *
4
+ * Exports `<TopNavLayout>` — sticky header with brand link + horizontal
5
+ * NavLinks + a user-menu slot, plus `<main>` rendering React Router's
6
+ * `<Outlet />` — and the `TopNavItem` / `TopNavLayoutProps` types.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { TopNavLayout, type TopNavItem } from '@molecule/app-top-nav-layout-react'
11
+ *
12
+ * const NAV: TopNavItem[] = [
13
+ * { key: 'dashboard', to: '/dashboard', icon: 'dashboard', label: 'Dashboard' },
14
+ * { key: 'reports', to: '/reports', icon: 'bar_chart', label: 'Reports' },
15
+ * ]
16
+ *
17
+ * const userMenu = <button type="button">Account</button>
18
+ *
19
+ * <TopNavLayout appName="Acme" navItems={NAV} userMenu={userMenu} />
20
+ * ```
21
+ *
22
+ * @remarks
23
+ * Requires React Router: render it as a LAYOUT ROUTE element
24
+ * (`<Route element={<TopNavLayout ... />}>` with child routes) — the page
25
+ * body comes from the router `<Outlet />`, never from children. Nav labels
26
+ * are hidden below the `md` breakpoint (icon-only mobile nav), so always
27
+ * provide `icon` names; they render as Material Symbols ligatures and need
28
+ * the Material Symbols font loaded by the host app. Styling mixes ClassMap
29
+ * calls with raw Tailwind + Material-3 tokens (`bg-surface`,
30
+ * `bg-primary-container`, `hidden md:inline`), so a Tailwind build that
31
+ * source-scans this package's dist and a theme defining those tokens are
32
+ * prerequisites — under a non-Tailwind ClassMap bond the header renders
33
+ * unstyled. `label` is rendered as-is: pass an already-translated string.
34
+ *
35
+ * @module
36
+ */
37
+ export * from './TopNavLayout.js';
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@molecule/app-top-nav-layout-react",
3
+ "version": "1.0.0",
4
+ "description": "Top navigation app shell: brand link + horizontal NavLinks + UserMenu slot, with React Router Outlet for nested routes",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md"
22
+ ],
23
+ "keywords": [
24
+ "molecule",
25
+ "layout",
26
+ "top-nav",
27
+ "react"
28
+ ],
29
+ "license": "Apache-2.0",
30
+ "peerDependencies": {
31
+ "@molecule/app-react": "^1.0.0",
32
+ "@molecule/app-ui": "^1.0.0",
33
+ "react": "^18.0.0 || ^19.0.0",
34
+ "react-router": "^7.0.0 || ^8.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@molecule/app-react": "1.0.0",
38
+ "@molecule/app-ui": "1.0.0",
39
+ "@types/node": "26.1.2",
40
+ "@types/react": "19.2.17",
41
+ "@types/react-dom": "19.2.3",
42
+ "react": "19.2.8",
43
+ "react-dom": "19.2.8",
44
+ "react-router": "8.3.0",
45
+ "typescript": "6.0.3",
46
+ "vitest": "4.1.10"
47
+ }
48
+ }