Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions web/src/components/home-edit-board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ const collisionDetection: CollisionDetection = (args) => {
};

/**
* compact / wide 的「+」砖高度(框内只有一个图标):与同档一块砖一致 ——
* compact 图标 20 单行、wide 图标 56 + 一行名称 + 一行域名(卡高 ≈ 56 + 上下内距
* 12×2 + 1px 边框 ×2 = 82px,文字两行 36px 还矮于图标,所以按图标算)。classic
* 不列在这里:它直接拿砖壳的定宽定高类(`w-[…] h-[…]`),无须估算高度。
* wide 的「+」砖高度:图标 56 + 一行名称 + 一行域名(卡高 ≈ 56 + 上下内距 12×2 +
* 1px 边框 ×2 = 82px,文字两行 36px 还矮于图标,所以按图标算),固定
* `min-h-[82px]`。compact 不列在这里:它的「+」砖高度由 24px 图标 + 砖壳内距
* 自然决定(与普通砖同尺寸),不必再估。classic 也不列:它直接拿砖壳的定宽定高
* 类(`w-[…] h-[…]`)。
*/
const PLACEHOLDER_CLASS: Partial<Record<LinkStyle, string>> = {
compact: "min-h-9",
wide: "min-h-[82px]",
};

Expand Down Expand Up @@ -315,17 +315,11 @@ function AddLinkTile({
PLACEHOLDER_CLASS[linkStyle],
// 同上一块砖:compact / wide 撑满格子,classic 保持砖宽固定
linkStyle !== "classic" && "w-full min-w-0",
"items-center justify-center border border-dashed border-white/40 bg-transparent text-white/80 hover:bg-white/10 hover:text-white",
"items-center justify-center border border-dashed border-white/40 bg-transparent text-white/80 hover:bg-white/5 hover:text-white",
isOver && "bg-white/10",
)}
>
<Plus
className={cn(
"shrink-0",
linkStyle === "compact" ? "size-4" : "size-6",
)}
aria-hidden="true"
/>
<Plus className="size-6 shrink-0" aria-hidden="true" />
</button>
);
}
Expand Down
38 changes: 29 additions & 9 deletions web/src/components/link-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { cn } from "@/lib/utils";
* 成块、高按同档图标盒与文字行数反推),图标盒固定占砖宽 60%;站点设置
* `columns`(1–12)是**成块列数**:桌面按这个数成块、整块居中,窄屏放不下
* 整块时一行自然少放几块(0/未配置回默认 8);
* - compact:小图标左、名称右(单行省略),透明无卡片底、不显示域名,桌面 5 列;
* - compact:24px 小图标左、15px 名称右(单行省略),透明无卡片底(只在悬停时
* 给一层 5% 白底表示可点)、不显示域名;条目固定 240px,按 #35 的成块模型
* 排布(整块居中、末行左对齐到满行列位);
* - wide:玻璃底宽卡,图标(56px、垂直居中)左、右侧名称 + 域名两行;列模板
* `repeat(auto-fill, minmax(min(300px, 100%), 380px))` —— 卡宽封顶 300–380px,
* 桌面一行多张、整行居中,窄屏自然折行,卡不再把整行撑满。
Expand All @@ -41,6 +43,13 @@ import { cn } from "@/lib/utils";
* (classic 是定宽定高的砖、compact / wide 撑满格子;单击打开编辑弹窗,不跳转),并传
* `singleLine` 让名称与网址各占一行、超长截断省略号(悬停 `title` 看全称)。
*
* compact 的排布模型(规格已定版):条目固定 240px,容器是 **CSS 网格** ——
* `repeat(auto-fill, 240px)` 的轨道数就是「成块列数」(floor((容宽 + gap) /
* (240 + gap)),gap 天然算进去),`justify-center` 让整块水平居中、末行从第 1
* 列起排。这与 classic 的 `maxWidth = columns*砖宽 + (columns-1)*gap` + `mx-auto`
* 是同一几何结果,但 compact 的列数不来自站点设置,用 CSS 自动排即可,无需
* 测量容器宽度(也就没有首帧闪动与 jsdom 量不到的测试难题)。
*
* classic 的排布模型(规格已定版):定宽定高的砖(宽度按站点设置 `tileSize`
* 从 `CLASSIC_TILE_WIDTH_CLASS` 取、高度从 `CLASSIC_TILE_HEIGHT_CLASS` 取,都是静态类)
* + flex 换行 + **整块居中 + 末行左对齐**。
Expand All @@ -62,6 +71,12 @@ import { cn } from "@/lib/utils";
* 也不会为了居中而整体右移。`w-full` 给 `column-gap` 的百分比一个确定基准;间距
* 与行组宽度来自 `linkGridLayout`(lib/grid-columns.ts 的 `classicGridMetrics`)。
*
* compact 是定宽轨道的网格:`repeat(auto-fill, 240px)` 先按容器宽度定下「成块
* 列数」,`justify-center` 把整组轨道居中(满行块宽 = 列数×240 + 间隔×gap),末行
* 因此仍从第 1 列起排、与满行同列对齐;`content-start` 让行不被拉伸。240 与
* `gap-x-3` 都是字面量(Tailwind 只扫字面量,改任一值须同步这里),条目宽度由
* 轨道给定,砖壳无须再写 `w-[240px]`。
*
* wide 用 CSS Grid 的 `auto-fill` 列模板(规格已定版):轨道在 300–380px 之间,
* 一行放得下几张就放几张,多出来的宽度被 `justify-center` 对称留在两侧 —— 卡不再
* 被拉成整行宽。用 `auto-fill`(不是 `auto-fit`):空轨道保留,末行的卡仍落在与
Expand All @@ -72,7 +87,7 @@ import { cn } from "@/lib/utils";
export const LINK_GRID_CLASS: Record<LinkStyle, string> = {
classic: "mx-auto flex w-full flex-wrap content-start justify-start gap-y-3",
compact:
"grid grid-cols-2 gap-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5",
"grid grid-cols-[repeat(auto-fill,240px)] content-start justify-center gap-x-3 gap-y-2",
wide: "grid gap-3 justify-center grid-cols-[repeat(auto-fill,minmax(min(300px,100%),380px))]",
};

Expand Down Expand Up @@ -110,14 +125,14 @@ export const CLASSIC_ICON_BOX: Record<TileSize, number> = {

/**
* 图标盒边长(px,按链接样式分档):同一档内所有链接共用一个定值,图标盒因此
* 全站同档同尺寸。compact 20(与改动前一致)、wide 56(图标在宽卡里垂直居中,
* 卡高 ≈ 56 + 上下内距 + 边框 ≈ 82px)、classic 取大档的 60% 图标盒边长(逐档值
* 见 `CLASSIC_ICON_BOX`),不改图标本身的圆角与背景。
* 全站同档同尺寸。compact 24(条目放大到 240px 宽后的点选口径)、wide 56(图标在
* 宽卡里垂直居中,卡高 ≈ 56 + 上下内距 + 边框 ≈ 82px);classic 取大档的 60%
* 图标盒边长(逐档值见 `CLASSIC_ICON_BOX`),不改图标本身的圆角与背景。
*/
export const LINK_ICON_BOX: Record<LinkStyle, number> = {
classic: CLASSIC_ICON_BOX.large,
wide: 56,
compact: 20,
compact: 24,
};

/**
Expand Down Expand Up @@ -163,7 +178,9 @@ export function linkTileClassName(
tileSize: TileSize = "large",
): string {
if (linkStyle === "compact") {
return "flex h-full items-center gap-2 rounded-xl px-2 py-2 text-start text-white/90 transition-colors hover:bg-white/10 hover:text-white";
// 24px 图标 + py-2.5 上下内距 = 44px 高的点选区;悬停只给一层极淡的白底,
// 不动文字与图标颜色(规格 3)。
return "flex h-full items-center gap-2.5 rounded-xl px-3 py-2.5 text-start text-white/90 transition-colors hover:bg-white/5";
}
if (linkStyle === "wide") {
return "glass glass-hover flex h-full items-center gap-3 rounded-2xl px-4 py-3 text-start";
Expand Down Expand Up @@ -248,7 +265,10 @@ export function LinkTileContent({
return (
<>
<LinkIcon link={link} linkStyle="compact" />
<span title={titleAttr} className="min-w-0 flex-1 truncate text-sm">
<span
title={titleAttr}
className="min-w-0 flex-1 truncate text-[15px] leading-5"
>
{link.title}
</span>
</>
Expand Down Expand Up @@ -334,7 +354,7 @@ function LinkTile({
);
}

/** 紧凑:小图标左、名称右;无卡片底、不显示域名 */
/** 紧凑:24px 图标左、15px 名称右(截断省略号);无卡片底、不显示域名 */
function CompactLinkTile({
link,
index,
Expand Down
49 changes: 32 additions & 17 deletions web/test/link-grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,22 @@ describe("LinkGrid:三档样式", () => {
expect(box.querySelector("img")).toHaveClass("object-contain", "size-full");
});

it("compact:透明无卡片底、单行名称、不显示域名,桌面 5 列", () => {
it("compact:透明无卡片底、单行名称、不显示域名,条目固定 240px、整块居中", () => {
const { container } = render(
<LinkGrid links={links} linkStyle="compact" />,
);

const compactGrid = grid(container);
// 定宽轨道 + 自动列数:轨道数就是成块列数,justify-center 把整块居中(末行仍从第 1 列起)
expect(compactGrid).toHaveClass(
"grid-cols-2",
"sm:grid-cols-3",
"md:grid-cols-4",
"lg:grid-cols-5",
"grid",
"grid-cols-[repeat(auto-fill,240px)]",
"content-start",
"justify-center",
"gap-x-3",
"gap-y-2",
);
expect(compactGrid).not.toHaveClass("grid-cols-4");
expect(compactGrid).not.toHaveClass("lg:grid-cols-5");
// compact 不吃 classic 的排布参数
expect(compactGrid.style.maxWidth).toBe("");

Expand All @@ -122,14 +125,26 @@ describe("LinkGrid:三档样式", () => {
expect(link).not.toHaveClass("glass-hover");
// 不显示域名
expect(link).not.toHaveTextContent("github.com");
// 小图标在左、名称单行省略
// 24px 图标在左、名称单行省略
expect(link).toHaveClass("items-center");
expect(link.querySelector("img")).toHaveAttribute("width", "20");
expect(link.querySelector("img")).toHaveAttribute(
"width",
String(LINK_ICON_BOX.compact),
);
expect(LINK_ICON_BOX.compact).toBe(24);
expect(iconBox(link, "compact")).toHaveStyle({
width: "20px",
height: "20px",
width: `${LINK_ICON_BOX.compact}px`,
height: `${LINK_ICON_BOX.compact}px`,
});
expect(link.querySelector("span.min-w-0")).toHaveClass("truncate");
// 名称 15px
expect(link.querySelector("span.min-w-0")).toHaveClass(
"truncate",
"text-[15px]",
"leading-5",
);
// 悬停只加极淡底色,不改文字/图标颜色
expect(link).toHaveClass("hover:bg-white/5");
expect(link).not.toHaveClass("hover:text-white");
});

it("wide:玻璃底宽卡,图标 56px 垂直居中、名称 + 域名两行,列模板 300–380px 封顶 + 整行居中", () => {
Expand Down Expand Up @@ -283,10 +298,8 @@ describe("LinkGrid:classic 成块列数(站点设置 columns)", () => {
<LinkGrid links={links} linkStyle="compact" columns={5} />,
);
expect(grid(compact.container)).toHaveClass(
"grid-cols-2",
"sm:grid-cols-3",
"md:grid-cols-4",
"lg:grid-cols-5",
"grid-cols-[repeat(auto-fill,240px)]",
"justify-center",
);
expect(grid(compact.container).style.maxWidth).toBe("");
compact.unmount();
Expand Down Expand Up @@ -401,7 +414,9 @@ describe("LinkGrid:classic 砖块尺寸三档(tileSize)", () => {
const compact = render(
<LinkGrid links={links} linkStyle="compact" tileSize="small" />,
);
expect(grid(compact.container)).toHaveClass("lg:grid-cols-5");
expect(grid(compact.container)).toHaveClass(
"grid-cols-[repeat(auto-fill,240px)]",
);
expect(screen.getByRole("link", { name: /GitHub/ })).not.toHaveClass(
"w-[92px]",
"h-[119px]",
Expand Down Expand Up @@ -447,7 +462,7 @@ describe("LinkGrid:显示网址开关(showUrl,缺省开)", () => {
const link = screen.getByRole("link", { name: /GitHub/ });
expect(link).not.toHaveTextContent("github.com");
expect(link).toHaveClass("items-center");
expect(grid(container)).toHaveClass("lg:grid-cols-5");
expect(grid(container)).toHaveClass("grid-cols-[repeat(auto-fill,240px)]");
});

it("不传 showUrl(编辑模式口径):classic / wide 仍显示域名", () => {
Expand Down
7 changes: 5 additions & 2 deletions web/test/public-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ describe("PublicPage 头部:时钟块取代顶栏", () => {
const link = screen.getByRole("link", { name: /GitHub/ });
expect(link).not.toHaveClass("glass");
expect(link).not.toHaveTextContent("github.com");
expect(link.parentElement?.parentElement).toHaveClass("lg:grid-cols-5");
expect(link.parentElement?.parentElement).toHaveClass(
"grid-cols-[repeat(auto-fill,240px)]",
"justify-center",
);
});

it("settings.linkStyle=wide:宽卡片(玻璃底 + 名称与域名两行)", () => {
Expand Down Expand Up @@ -250,7 +253,7 @@ describe("PublicPage 头部:时钟块取代顶栏", () => {
const compact = render(<PublicPage onOpenAdmin={vi.fn()} />);
expect(
screen.getByRole("link", { name: /GitHub/ }).parentElement?.parentElement,
).toHaveClass("lg:grid-cols-5");
).toHaveClass("grid-cols-[repeat(auto-fill,240px)]");
compact.unmount();

seedSite({ ...baseSettings, columns: 12, linkStyle: "wide" });
Expand Down
Loading