Skip to content

Commit 2b8ef80

Browse files
committed
Move flow shield to the top of the list, add new tag, improve menu
1 parent 2090b13 commit 2b8ef80

4 files changed

Lines changed: 47 additions & 13 deletions

File tree

apps/website/components/Nav.tsx

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ export default function Nav({
5757
firstRef.current = false;
5858
}, [demoname, demos]);
5959

60+
const navRef = useRef<HTMLDivElement>(null);
61+
62+
useEffect(() => {
63+
if (!collapsed) {
64+
navRef.current?.removeAttribute("data-near");
65+
return;
66+
}
67+
const onMove = (e: MouseEvent) => {
68+
if (e.clientX < 120) navRef.current?.setAttribute("data-near", "");
69+
else navRef.current?.removeAttribute("data-near");
70+
};
71+
window.addEventListener("mousemove", onMove);
72+
return () => window.removeEventListener("mousemove", onMove);
73+
}, [collapsed]);
74+
6075
useEffect(() => {
6176
const handler = (e: KeyboardEvent) => {
6277
if (e.key === "[" && e.metaKey) toggle();
@@ -66,7 +81,11 @@ export default function Nav({
6681
}, [toggle]);
6782

6883
return (
69-
<div className="Nav" data-collapsed={collapsed || undefined}>
84+
<div
85+
ref={navRef}
86+
className="Nav"
87+
data-collapsed={collapsed || undefined}
88+
>
7089
<Style
7190
css={`
7291
@scope {
@@ -150,18 +169,11 @@ export default function Nav({
150169
}
151170
152171
:scope[data-collapsed] .toggle {
153-
translate: 15% -50%;
154-
}
155-
156-
:scope[data-collapsed] .toggle::before {
157-
content: "";
158-
position: absolute;
159-
inset: -1rem;
160-
inset-inline-end: -3rem;
172+
translate: 25% -50%;
161173
}
162174
163-
:scope[data-collapsed] .toggle:hover {
164-
translate: 65% -50%;
175+
:scope[data-collapsed][data-near] .toggle {
176+
translate: 75% -50%;
165177
}
166178
167179
:scope[data-collapsed] .toggle svg {
@@ -213,6 +225,22 @@ export default function Nav({
213225
overflow: hidden;
214226
}
215227
228+
.pill {
229+
position: absolute;
230+
top: 6px;
231+
right: 6px;
232+
padding: 2px 7px;
233+
font-size: 0.55rem;
234+
font-weight: 700;
235+
letter-spacing: 0.06em;
236+
text-transform: uppercase;
237+
line-height: 1.5;
238+
color: white;
239+
background: #e8756a;
240+
border-radius: 999px;
241+
z-index: 1;
242+
}
243+
216244
a img {
217245
object-fit: cover;
218246
width: 100%;
@@ -249,13 +277,14 @@ export default function Nav({
249277

250278
<nav {...props}>
251279
<ul ref={ulRef}>
252-
{demos.map(({ name, thumb }, i) => (
280+
{demos.map(({ name, thumb, isNew }, i) => (
253281
<li key={thumb} ref={lisRef.current[i]}>
254282
<Link
255283
href={`/demos/${name}`}
256284
className={clsx({ active: demoname === name })}
257285
>
258286
<div className="thumb">
287+
{isNew && <span className="pill">New</span>}
259288
<Image src={thumb} fill sizes="227px" alt={name} />
260289
</div>
261290
</Link>

apps/website/const/new.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
export const NEW_DEMOS = new Set(["flow-shield"]);

apps/website/lib/helper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Importing JSON directly
2+
import { NEW_DEMOS } from "@/const/new";
23
import pkg from "@/package.json";
34

45
import { generatePort } from "@examples/e2e";
@@ -11,6 +12,7 @@ const host =
1112
? (port: number) => `http://localhost:${port}`
1213
: () => (BASE_URL ? new URL(BASE_URL).origin : "");
1314

15+
1416
export function getDemos() {
1517
return Object.keys(pkg.dependencies)
1618
.filter((dep) => dep.startsWith("@demo/"))
@@ -27,6 +29,7 @@ export function getDemos() {
2729
thumb: `${embed_url}/thumbnail.webp`,
2830
embed_url,
2931
website_url,
32+
isNew: NEW_DEMOS.has(demoname),
3033
};
3134
});
3235
}

apps/website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"lint": "next lint"
1212
},
1313
"dependencies": {
14+
"@demo/flow-shield": "workspace:*",
1415
"@demo/aquarium": "workspace:*",
1516
"@demo/arkanoid": "workspace:*",
1617
"@demo/arkanoid-under-60-loc": "workspace:*",
@@ -55,7 +56,6 @@
5556
"@demo/flexbox-yoga-in-webgl": "workspace:*",
5657
"@demo/floating-diamonds": "workspace:*",
5758
"@demo/floating-instanced-shoes": "workspace:*",
58-
"@demo/flow-shield": "workspace:*",
5959
"@demo/floating-laptop": "workspace:*",
6060
"@demo/flying-bananas": "workspace:*",
6161
"@demo/frosted-glass": "workspace:*",

0 commit comments

Comments
 (0)