@sfdc-webapps/feature-navigation-menu 1.0.2

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/feature.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { Feature } from '../cli/src/types.js';
2
+
3
+ const feature: Feature = {};
4
+
5
+ export default feature;
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@sfdc-webapps/feature-navigation-menu",
3
+ "version": "1.0.2",
4
+ "description": "Navigation menu feature for web applications",
5
+ "license": "ISC",
6
+ "author": "",
7
+ "type": "module",
8
+ "main": "index.js",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "scripts": {
13
+ "dev": "cd dist/digitalExperiences/webApplications/feature-navigation-menu && yarn && yarn dev",
14
+ "build": "node ../cli/dist/index.js apply-patches packages/feature-navigation-menu packages/base-react-app packages/feature-navigation-menu/dist --clean",
15
+ "watch": "node ../cli/dist/index.js watch-patches packages/feature-navigation-menu packages/base-react-app packages/feature-navigation-menu/dist --clean"
16
+ },
17
+ "devDependencies": {
18
+ "@types/react": "^19.2.7",
19
+ "@types/react-dom": "^19.2.3",
20
+ "react-dom": "^19.2.1",
21
+ "react-router": "^7.10.1"
22
+ }
23
+ }
@@ -0,0 +1,10 @@
1
+ export default function About() {
2
+ return (
3
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
4
+ <div className="text-center">
5
+ <h1 className="text-4xl font-bold text-gray-900 mb-4">About</h1>
6
+ <p className="text-lg text-gray-600">This is the about page.</p>
7
+ </div>
8
+ </div>
9
+ );
10
+ }
@@ -0,0 +1,11 @@
1
+ import { Outlet } from "react-router";
2
+ import NavigationMenu from "./navigationMenu";
3
+
4
+ export default function AppLayout() {
5
+ return (
6
+ <>
7
+ <NavigationMenu />
8
+ <Outlet />
9
+ </>
10
+ );
11
+ }
@@ -0,0 +1,75 @@
1
+ import { Link, useLocation } from 'react-router';
2
+ import { getAllRoutes } from './router-utils';
3
+ import { useState } from 'react';
4
+
5
+ export default function NavigationMenu() {
6
+ const [isOpen, setIsOpen] = useState(false);
7
+ const location = useLocation();
8
+
9
+ const isActive = (path: string) => location.pathname === path;
10
+
11
+ const toggleMenu = () => setIsOpen(!isOpen);
12
+
13
+ // Get all route configs and filter by showInNavigation
14
+ const navigationRoutes: { path: string; label: string }[] = getAllRoutes()
15
+ .filter(route => route.handle?.showInNavigation === true && route.fullPath !== undefined && route.handle?.label !== undefined)
16
+ .map(route => ({
17
+ path: route.fullPath,
18
+ label: route.handle?.label
19
+ } as { path: string; label: string }));
20
+
21
+ return (
22
+ <nav className="bg-white border-b border-gray-200">
23
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
24
+ <div className="flex justify-between items-center h-16">
25
+ <Link to="/" className="text-xl font-semibold text-gray-900">
26
+ React App
27
+ </Link>
28
+ <button
29
+ onClick={toggleMenu}
30
+ className="p-2 rounded-md text-gray-700 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
31
+ aria-label="Toggle menu"
32
+ >
33
+ <div className="w-6 h-6 flex flex-col justify-center space-y-1.5">
34
+ <span
35
+ className={`block h-0.5 w-6 bg-current transition-all ${
36
+ isOpen ? 'rotate-45 translate-y-2' : ''
37
+ }`}
38
+ />
39
+ <span
40
+ className={`block h-0.5 w-6 bg-current transition-all ${
41
+ isOpen ? 'opacity-0' : ''
42
+ }`}
43
+ />
44
+ <span
45
+ className={`block h-0.5 w-6 bg-current transition-all ${
46
+ isOpen ? '-rotate-45 -translate-y-2' : ''
47
+ }`}
48
+ />
49
+ </div>
50
+ </button>
51
+ </div>
52
+ {isOpen && (
53
+ <div className="pb-4">
54
+ <div className="flex flex-col space-y-2">
55
+ {navigationRoutes.map(item => (
56
+ <Link
57
+ key={item.path}
58
+ to={item.path}
59
+ onClick={() => setIsOpen(false)}
60
+ className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
61
+ isActive(item.path)
62
+ ? 'bg-blue-100 text-blue-700'
63
+ : 'text-gray-700 hover:bg-gray-100'
64
+ }`}
65
+ >
66
+ {item.label}
67
+ </Link>
68
+ ))}
69
+ </div>
70
+ </div>
71
+ )}
72
+ </div>
73
+ </nav>
74
+ );
75
+ }
@@ -0,0 +1,10 @@
1
+ export default function New() {
2
+ return (
3
+ <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
4
+ <div className="text-center">
5
+ <h1 className="text-4xl font-bold text-gray-900 mb-4">New</h1>
6
+ <p className="text-lg text-gray-600">This is the new page.</p>
7
+ </div>
8
+ </div>
9
+ );
10
+ }
@@ -0,0 +1,36 @@
1
+ import type { RouteObject } from "react-router";
2
+ import { routes } from "./routes";
3
+
4
+ export type RouteWithFullPath = RouteObject & { fullPath: string };
5
+
6
+ const flatMapRoutes = (route: RouteObject, parentPath: string = ''): RouteWithFullPath[] => {
7
+ // Construct the full path for this route
8
+ let fullPath: string;
9
+
10
+ if (route.index) {
11
+ // Index routes use the parent path
12
+ fullPath = parentPath || '/';
13
+ } else if (route.path) {
14
+ // Combine parent path with current path
15
+ if (route.path.startsWith('/')) {
16
+ fullPath = route.path;
17
+ } else {
18
+ fullPath = parentPath === '/'
19
+ ? `/${route.path}`
20
+ : `${parentPath}/${route.path}`;
21
+ }
22
+ } else {
23
+ fullPath = parentPath;
24
+ }
25
+
26
+ const routeWithPath = { ...route, fullPath };
27
+
28
+ // Recursively process children
29
+ const childRoutes = route.children?.flatMap(child => flatMapRoutes(child, fullPath)) || [];
30
+
31
+ return [routeWithPath, ...childRoutes];
32
+ }
33
+
34
+ export const getAllRoutes = (): RouteWithFullPath[] => {
35
+ return routes.flatMap(route => flatMapRoutes(route));
36
+ }
@@ -0,0 +1,28 @@
1
+ import type { RouteObject } from "react-router";
2
+ import AppLayout from "./appLayout";
3
+ import About from './about'
4
+ import New from './new'
5
+
6
+ export const routes: RouteObject[] = [
7
+ {
8
+ path: '/',
9
+ element: <AppLayout />,
10
+ children: [
11
+ {
12
+ path: 'about',
13
+ element: <About />,
14
+ handle: { showInNavigation: true, label: 'About' }
15
+ },
16
+ {
17
+ path: 'contact',
18
+ element: <h1>Hello World from Contact Page</h1>,
19
+ handle: { showInNavigation: false }
20
+ },
21
+ {
22
+ path: 'new',
23
+ element: <New />,
24
+ handle: { showInNavigation: true, label: 'New Page' }
25
+ },
26
+ ]
27
+ }
28
+ ]
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
4
+ "target": "ES2022",
5
+ "useDefineForClassFields": true,
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "module": "ESNext",
8
+ "types": ["vite/client"],
9
+ "skipLibCheck": true,
10
+
11
+ /* Bundler mode */
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "moduleDetection": "force",
16
+ "noEmit": true,
17
+ "jsx": "react-jsx",
18
+
19
+ /* Linting */
20
+ "strict": true,
21
+ "noUnusedLocals": true,
22
+ "noUnusedParameters": true,
23
+ "erasableSyntaxOnly": true,
24
+ "noFallthroughCasesInSwitch": true,
25
+ "noUncheckedSideEffectImports": true
26
+ },
27
+ "include": ["template/webApp"]
28
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./tsconfig.app.json" },
5
+ { "path": "./tsconfig.node.json" }
6
+ ]
7
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
+ "target": "ES2023",
5
+ "lib": ["ES2023"],
6
+ "module": "ESNext",
7
+ "types": ["node"],
8
+ "skipLibCheck": true,
9
+
10
+ /* Bundler mode */
11
+ "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
13
+ "verbatimModuleSyntax": true,
14
+ "moduleDetection": "force",
15
+ "noEmit": true,
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "erasableSyntaxOnly": true,
22
+ "noFallthroughCasesInSwitch": true,
23
+ "noUncheckedSideEffectImports": true
24
+ },
25
+ "include": ["vite.config.ts"]
26
+ }