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 9ce6a5f commit 7c3df62
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 6 deletions.
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.

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

Check failure on line 1 in src/RootLayout.tsx

View workflow job for this annotation

GitHub Actions / deploy

This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.
import {
Link,
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 +42,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 7c3df62

Please sign in to comment.