Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
Display nav-link states
Browse files Browse the repository at this point in the history
  • Loading branch information
pudek357 committed Aug 17, 2024
1 parent ebe0733 commit aecafe7
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
---
title: Basic (Data Router)
toc: false
order: 1
---
https://pudek357.github.io/react-router-route-lazy

# Data Routers

Expand Down
17 changes: 16 additions & 1 deletion src/Bar.tsx

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/Foo.tsx

Large diffs are not rendered by default.

38 changes: 34 additions & 4 deletions src/RootLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
import { Link, Outlet, useLocation, useNavigation } from "react-router-dom";
import type { ComponentProps, ReactNode } from "react";
import {
NavLink as BaseNavLink,
Outlet,
useLocation,
useNavigation,
} from "react-router-dom";

const NavLink = ({
to,
children,
}: ComponentProps<typeof BaseNavLink> & { children: ReactNode }) => (
<BaseNavLink
to={to}
className="nav-link"
end={to === "/react-router-route-lazy/"}
unstable_viewTransition
>
{({ isActive, isPending, isTransitioning }) => (
<>
<span className="nav-link-route">{children}</span>

<span className="nav-link-state">
{isActive && <span className="nav-link-state-item">A</span>}
{isPending && <span className="nav-link-state-item">P</span>}
{isTransitioning && <span className="nav-link-state-item">T</span>}
</span>
</>
)}
</BaseNavLink>
);

export const RootLayout = () => {
const { pathname } = useLocation();
Expand All @@ -11,13 +41,13 @@ export const RootLayout = () => {
<div className="main-content">
<div className="sidebar">
<div>
<Link to="/react-router-route-lazy/">root</Link>
<NavLink to="/react-router-route-lazy/">root</NavLink>
</div>
<div>
<Link to="/react-router-route-lazy/foo">foo</Link>
<NavLink to="/react-router-route-lazy/foo">foo</NavLink>
</div>
<div>
<Link to="/react-router-route-lazy/bar">bar</Link>
<NavLink to="/react-router-route-lazy/bar">bar</NavLink>
</div>
</div>

Expand Down
22 changes: 22 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,25 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}

.nav-link {
display: flex;
height: 22px;
text-decoration: none;
}

.nav-link-route {
width: 40px;
}

.nav-link-state {
margin-left: 4px;
display: flex;
}

.nav-link-state-item {
width: 20px;
display: flex;
justify-content: center;
align-items: center;
}

0 comments on commit aecafe7

Please sign in to comment.