Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 75e7cb0

Browse files
committed
feat: No Sidebar Demo
1 parent 0bdef06 commit 75e7cb0

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

Diff for: .nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10.22.1

Diff for: src/__mocks__/@topcoder/micro-frontends-navbar-app.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ module.exports = {
44
setAppMenu: () => {},
55
getAuthUserTokens: () => new Promise(() => {}),
66
getAuthUserProfile: () => new Promise(() => {}),
7+
disableSidebarForRoute: () => {},
8+
enableSidebarForRoute: () => {},
79
};

Diff for: src/components/NoSidebarDemo/index.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* This component demonstrates how we can disable sidebar for some subroutes.
3+
*
4+
* For example this component disables sidebar for routes "/micro-frontends-react-route/no-sidebar/*".
5+
*/
6+
import React, { useLayoutEffect } from "react";
7+
import {
8+
disableSidebarForRoute,
9+
enableSidebarForRoute,
10+
} from "@topcoder/micro-frontends-navbar-app";
11+
12+
const COMPONENT_ROUTE = "/micro-frontends-react-route/no-sidebar/*";
13+
14+
const NoSidebarDemo = () => {
15+
// use "useLayoutEffect" to remove the sidebar as early as possible
16+
// without waiting the component to be rendered
17+
useLayoutEffect(() => {
18+
disableSidebarForRoute(COMPONENT_ROUTE);
19+
}, []);
20+
21+
return (
22+
<>
23+
<h2>Sidebar</h2>
24+
<div>Enable/disable sidebar for routes that match:</div>
25+
<pre>{COMPONENT_ROUTE}</pre>
26+
<div>
27+
<button onClick={() => enableSidebarForRoute(COMPONENT_ROUTE)}>
28+
Enable
29+
</button>
30+
<button onClick={() => disableSidebarForRoute(COMPONENT_ROUTE)}>
31+
Disable
32+
</button>
33+
</div>
34+
</>
35+
);
36+
};
37+
38+
export default NoSidebarDemo;

Diff for: src/constants/appMenu.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ const appMenu = [
1414
activeIcon: reactActiveIcon,
1515
},
1616
{
17-
title: "Home",
18-
path: "/micro-frontends-react-route/home",
17+
title: "Auth Demo",
18+
path: "/micro-frontends-react-route/auth",
19+
icon: homeIcon,
20+
activeIcon: homeActiveIcon,
21+
},
22+
{
23+
title: "No Sidebar Demo",
24+
path: "/micro-frontends-react-route/no-sidebar",
1925
icon: homeIcon,
2026
activeIcon: homeActiveIcon,
2127
},

Diff for: src/root.component.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { useEffect } from "react";
2-
import { Link } from "@reach/router";
2+
import { Link, Router } from "@reach/router";
33
import { setAppMenu } from "@topcoder/micro-frontends-navbar-app";
44
import appMenu from "./constants/appMenu";
55
import AuthDemo from "./components/AuthDemo";
6+
import NoSidebarDemo from "./components/NoSidebarDemo";
67

78
export default function Root() {
89
useEffect(() => {
@@ -32,7 +33,10 @@ export default function Root() {
3233
</Link>
3334
</div>
3435

35-
<AuthDemo />
36+
<Router>
37+
<AuthDemo path="/micro-frontends-react-route/auth" />
38+
<NoSidebarDemo path="/micro-frontends-react-route/no-sidebar" />
39+
</Router>
3640
</div>
3741
);
3842
}

0 commit comments

Comments
 (0)