Skip to content

Commit 5c87538

Browse files
committed
feat(site): redesign component overview page with SVG card grid
Replace flat button list with a responsive card grid. Each component gets a clickable card showing its SVG illustration with the name below.
1 parent f082455 commit 5c87538

2 files changed

Lines changed: 84 additions & 35 deletions

File tree

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
11
.component-overview {
2-
// &__btn {
3-
// border: 1px solid #f4f5f7;
4-
// margin: 0 20px 20px 0;
5-
// display: flex;
6-
// flex-direction: column;
7-
// cursor: pointer;
8-
// transition: all 350ms;
2+
&__grid {
3+
display: grid;
4+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
5+
gap: 20px;
6+
margin-bottom: 16px;
7+
}
8+
9+
&__grid > .ty-card + .ty-card {
10+
margin-top: 0;
11+
}
912

10-
// & + & {
11-
// margin-left: 0;
12-
// }
13+
&__card {
14+
cursor: pointer;
15+
border-radius: 12px;
16+
overflow: hidden;
17+
padding: 0;
18+
transition: all 0.3s;
1319

14-
// &:hover {
15-
// box-shadow: rgba(0, 0, 0, 0.08) 0px 6px 16px -8px, rgba(0, 0, 0, 0.05) 0px 9px 28px 0px,
16-
// rgba(0, 0, 0, 0.03) 0px 12px 48px 16px;
17-
// }
18-
// }
20+
&:hover {
21+
transform: translateY(-4px);
22+
}
23+
}
1924

20-
// &__btn-title {
21-
// padding: 10px 12px;
22-
// border-bottom: 1px solid #f4f5f7;
23-
// }
24-
&__btn {
25-
margin: 0 10px 10px 0;
25+
&__card-img {
26+
height: 140px;
27+
background: #f4f5f7;
28+
display: flex;
29+
align-items: center;
30+
justify-content: center;
31+
overflow: hidden;
2632

27-
& + & {
28-
margin-left: 0;
33+
img {
34+
width: 100%;
35+
height: 100%;
36+
object-fit: cover;
2937
}
3038
}
39+
40+
&__card-placeholder {
41+
width: 48px;
42+
height: 48px;
43+
border-radius: 8px;
44+
background: #e5e7eb;
45+
}
46+
47+
&__card-name {
48+
padding: 12px 16px;
49+
text-align: center;
50+
font-size: 14px;
51+
color: var(--ty-color-text, #1f2937);
52+
border-top: 1px solid var(--ty-color-border, #e5e7eb);
53+
}
3154
}

site/src/containers/components/overview.tsx

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import React, { useMemo } from 'react';
22
import './component-overview.scss';
33
import { useNavigate } from 'react-router-dom';
4-
import { Row, Tag, Button } from '../../../../components';
4+
import { Card, Tag } from '../../../../components';
55
import { getComponentMenu } from '../../routers';
66
import { useLocaleContext } from '../../context/locale-context';
77

8+
const svgCache: Record<string, string> = {};
9+
10+
function getSvgSrc(route: string): string | undefined {
11+
if (svgCache[route] !== undefined) return svgCache[route] || undefined;
12+
try {
13+
const src = require(`../../assets/icon/${route}.svg`);
14+
svgCache[route] = src;
15+
return src;
16+
} catch {
17+
svgCache[route] = '';
18+
return undefined;
19+
}
20+
}
21+
822
const ComponentOverview = () => {
923
const navigate = useNavigate();
1024
const { siteLocale: s } = useLocaleContext();
@@ -13,25 +27,37 @@ const ComponentOverview = () => {
1327
res += i.children!.length;
1428
return res;
1529
}, 0);
30+
1631
return (
1732
<div className="component-overview">
1833
<h1 className="markdown__heading-1">{s.overview.title}</h1>
1934
<p className="markdown__p">{s.overview.desc(numOfComps)}</p>
2035
{componentMenu.map((router) => (
21-
<div key={router.title}>
36+
<div key={router.title} className="component-overview__category">
2237
<h3 className="markdown__heading-3">
2338
{router.title} <Tag>{router.children?.length}</Tag>
2439
</h3>
25-
<Row gutter={24} gutterSide>
26-
{router.children!.map((item) => (
27-
<Button
28-
className="component-overview__btn"
29-
key={item.route}
30-
onClick={() => navigate(`/components/${item.route!}`)}>
31-
{item.title}
32-
</Button>
33-
))}
34-
</Row>
40+
<div className="component-overview__grid">
41+
{router.children!.map((item) => {
42+
const svgSrc = getSvgSrc(item.route!);
43+
return (
44+
<Card
45+
className="component-overview__card"
46+
key={item.route}
47+
hoverable
48+
onClick={() => navigate(`/components/${item.route!}`)}>
49+
<div className="component-overview__card-img">
50+
{svgSrc ? (
51+
<img src={svgSrc} alt={item.title} />
52+
) : (
53+
<div className="component-overview__card-placeholder" />
54+
)}
55+
</div>
56+
<div className="component-overview__card-name">{item.title}</div>
57+
</Card>
58+
);
59+
})}
60+
</div>
3561
</div>
3662
))}
3763
</div>

0 commit comments

Comments
 (0)