Skip to content

Commit 549e5d5

Browse files
authored
Merge pull request #12 from DismalMango/feat/hover-highlight
Feat: Add hover highlight
2 parents b140715 + 426d2ca commit 549e5d5

File tree

3 files changed

+54
-15
lines changed

3 files changed

+54
-15
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,3 @@ pnpm start # 启动生产服务器
9797
# 导出
9898
pnpm export # 导出静态站点到 /out 目录
9999
```
100-

app/components/HoverCard.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from "react";
2+
3+
interface HoverCardProps {
4+
children: React.ReactNode;
5+
className?: string;
6+
hoverType?: "darken" | "scale" | "lift" | "glow";
7+
}
8+
9+
export default function HoverCard({
10+
children,
11+
className = "",
12+
hoverType = "scale",
13+
}: HoverCardProps) {
14+
const getHoverStyles = () => {
15+
switch (hoverType) {
16+
case "darken":
17+
return "hover:brightness-90 transition-all duration-200 ease-in-out";
18+
case "scale":
19+
return "hover:scale-105 hover:shadow-lg transition-all duration-200 ease-in-out";
20+
case "lift":
21+
return "hover:-translate-y-1 hover:shadow-lg transition-all duration-200 ease-in-out";
22+
case "glow":
23+
return "hover:shadow-xl hover:shadow-primary/20 transition-all duration-200 ease-in-out";
24+
default:
25+
return "hover:scale-105 hover:shadow-lg transition-all duration-200 ease-in-out";
26+
}
27+
};
28+
29+
return <div className={`${getHoverStyles()} ${className}`}>{children}</div>;
30+
}

app/page.tsx

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Link from "next/link";
22
import { source } from "@/lib/source";
3+
import HoverCard from "@/app/components/HoverCard";
34

45
export default function DocsIndex() {
56
const pages = source
@@ -10,22 +11,31 @@ export default function DocsIndex() {
1011
<main style={{ maxWidth: 800, margin: "40px auto", padding: 16 }}>
1112
<h1 style={{ fontSize: 28, fontWeight: 700, marginBottom: 16 }}>Docs</h1>
1213
<ul style={{ display: "grid", gap: 12 }}>
13-
{pages.map((p) => {
14-
const href = `/docs/${p.slugs.join("/")}`;
15-
return (
16-
<li
17-
key={href}
18-
style={{ border: "1px solid #eee", borderRadius: 8, padding: 16 }}
14+
{pages.map((d) => (
15+
<li key={d.slugs.join("/")}>
16+
<HoverCard
17+
hoverType="scale"
18+
className="border border-gray-200 rounded-lg p-4 cursor-pointer bg-white dark:bg-gray-800 dark:border-gray-700"
1919
>
20-
<Link href={href} style={{ fontWeight: 600 }}>
21-
{p.data.title}
20+
<Link
21+
href={`/docs/${d.slugs.join("/")}`}
22+
className="block w-full h-full"
23+
style={{
24+
fontWeight: 600,
25+
textDecoration: "none",
26+
color: "inherit",
27+
}}
28+
>
29+
{d.data.title}
30+
{d.data.description && (
31+
<p style={{ opacity: 0.8, marginTop: 8 }}>
32+
{d.data.description}
33+
</p>
34+
)}
2235
</Link>
23-
{p.data.description && (
24-
<p style={{ opacity: 0.8 }}>{p.data.description}</p>
25-
)}
26-
</li>
27-
);
28-
})}
36+
</HoverCard>
37+
</li>
38+
))}
2939
</ul>
3040
</main>
3141
);

0 commit comments

Comments
 (0)