Skip to content

Commit 211b8e7

Browse files
committed
fix: code block style conflict
1 parent e372dc8 commit 211b8e7

5 files changed

Lines changed: 54 additions & 142 deletions

File tree

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/docs/[...slug]/page.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ export default async function DocPage({ params }: Param) {
2323
return (
2424
<DocsPage toc={page.data.toc}>
2525
<DocsBody>
26-
<h1 className="hover-darken-text">{page.data.title}</h1>
27-
<div className="hover-darken">
28-
<Mdx components={getMDXComponents()} />
29-
</div>
26+
<h1>{page.data.title}</h1>
27+
<Mdx components={getMDXComponents()} />
3028
</DocsBody>
3129
</DocsPage>
3230
);

app/globals.css

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -277,66 +277,3 @@
277277
@apply bg-background text-foreground;
278278
}
279279
}
280-
281-
@layer utilities {
282-
/* 通用 hover 变深效果 */
283-
.hover-darken {
284-
transition: filter 0.2s ease-in-out;
285-
}
286-
287-
.hover-darken:hover {
288-
filter: brightness(0.8);
289-
}
290-
291-
/* 针对不同颜色类型的 hover 变深效果 */
292-
.hover-darken-bg {
293-
transition: all 0.2s ease-in-out;
294-
}
295-
296-
.hover-darken-bg:hover {
297-
background-color: #f0f0f0 !important;
298-
transform: scale(1.02);
299-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
300-
}
301-
302-
.hover-darken-text {
303-
transition: filter 0.2s ease-in-out;
304-
}
305-
306-
.hover-darken-text:hover {
307-
filter: brightness(0.8);
308-
}
309-
310-
/* 使用 CSS 变量实现更精确的颜色控制 */
311-
.hover-darken-custom {
312-
transition:
313-
background-color 0.2s ease-in-out,
314-
color 0.2s ease-in-out;
315-
}
316-
317-
.hover-darken-custom:hover {
318-
background-color: color-mix(in srgb, currentColor 15%, transparent);
319-
}
320-
321-
/* 针对链接的特殊 hover 效果 */
322-
.hover-link {
323-
transition: all 0.2s ease-in-out;
324-
position: relative;
325-
}
326-
327-
.hover-link:hover {
328-
filter: brightness(0.8);
329-
transform: translateY(-1px);
330-
}
331-
332-
/* 针对按钮的 hover 效果 */
333-
.hover-button {
334-
transition: all 0.2s ease-in-out;
335-
}
336-
337-
.hover-button:hover {
338-
filter: brightness(0.9);
339-
transform: translateY(-1px);
340-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
341-
}
342-
}

app/page.tsx

Lines changed: 22 additions & 25 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
@@ -11,32 +12,28 @@ export default function DocsIndex() {
1112
<h1 style={{ fontSize: 28, fontWeight: 700, marginBottom: 16 }}>Docs</h1>
1213
<ul style={{ display: "grid", gap: 12 }}>
1314
{pages.map((d) => (
14-
<li
15-
key={d.slugs.join("/")}
16-
className="hover-darken-bg"
17-
style={{
18-
border: "1px solid #eee",
19-
borderRadius: 8,
20-
padding: 16,
21-
cursor: "pointer",
22-
}}
23-
>
24-
<Link
25-
href={`/docs/${d.slugs.join("/")}`}
26-
className="hover-link block w-full h-full"
27-
style={{
28-
fontWeight: 600,
29-
textDecoration: "none",
30-
color: "inherit",
31-
}}
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"
3219
>
33-
{d.data.title}
34-
{d.data.description && (
35-
<p style={{ opacity: 0.8, marginTop: 8 }}>
36-
{d.data.description}
37-
</p>
38-
)}
39-
</Link>
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+
)}
35+
</Link>
36+
</HoverCard>
4037
</li>
4138
))}
4239
</ul>

mdx-components.tsx

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,6 @@ import type { MDXComponents } from "mdx/types";
44
export function getMDXComponents(components?: MDXComponents): MDXComponents {
55
return {
66
...defaultMdxComponents,
7-
a: ({ children, ...props }) => (
8-
<a className="hover-link" {...props}>
9-
{children}
10-
</a>
11-
),
12-
code: ({ children, ...props }) => (
13-
<code className="hover-darken-text" {...props}>
14-
{children}
15-
</code>
16-
),
17-
pre: ({ children, ...props }) => (
18-
<pre className="hover-darken-bg" {...props}>
19-
{children}
20-
</pre>
21-
),
22-
blockquote: ({ children, ...props }) => (
23-
<blockquote className="hover-darken-bg" {...props}>
24-
{children}
25-
</blockquote>
26-
),
27-
h1: ({ children, ...props }) => (
28-
<h1 className="hover-darken-text" {...props}>
29-
{children}
30-
</h1>
31-
),
32-
h2: ({ children, ...props }) => (
33-
<h2 className="hover-darken-text" {...props}>
34-
{children}
35-
</h2>
36-
),
37-
h3: ({ children, ...props }) => (
38-
<h3 className="hover-darken-text" {...props}>
39-
{children}
40-
</h3>
41-
),
42-
h4: ({ children, ...props }) => (
43-
<h4 className="hover-darken-text" {...props}>
44-
{children}
45-
</h4>
46-
),
47-
h5: ({ children, ...props }) => (
48-
<h5 className="hover-darken-text" {...props}>
49-
{children}
50-
</h5>
51-
),
52-
h6: ({ children, ...props }) => (
53-
<h6 className="hover-darken-text" {...props}>
54-
{children}
55-
</h6>
56-
),
577
...components,
588
};
599
}

0 commit comments

Comments
 (0)