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
7 changes: 4 additions & 3 deletions web/src/components/home-edit-board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ const collisionDetection: CollisionDetection = (args) => {

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

type Order = Record<string, string[]>;
Expand Down
20 changes: 15 additions & 5 deletions web/src/components/link-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { cn } from "@/lib/utils";
* `columns`(1–12)是**成块列数**:桌面按这个数成块、整块居中,窄屏放不下
* 整块时一行自然少放几块(0/未配置回默认 8);
* - compact:小图标左、名称右(单行省略),透明无卡片底、不显示域名,桌面 5 列;
* - wide:玻璃底宽卡,图标左、右侧名称 + 域名两行,桌面 3 列 / 窄屏 1–2 列。
* - wide:玻璃底宽卡,图标(56px、垂直居中)左、右侧名称 + 域名两行;列模板
* `repeat(auto-fill, minmax(min(300px, 100%), 380px))` —— 卡宽封顶 300–380px,
* 桌面一行多张、整行居中,窄屏自然折行,卡不再把整行撑满。
*
* 每一条都包一层 `FadeIn`(错峰入场,与改动前一致);外链属性
* `target="_blank" rel="noopener noreferrer"` 三档一致。
Expand Down Expand Up @@ -59,12 +61,19 @@ import { cn } from "@/lib/utils";
* `max-width` 完成:满行正好填满行组宽度,`justify-start` 对满行没有影响;末行
* 也不会为了居中而整体右移。`w-full` 给 `column-gap` 的百分比一个确定基准;间距
* 与行组宽度来自 `linkGridLayout`(lib/grid-columns.ts 的 `classicGridMetrics`)。
*
* wide 用 CSS Grid 的 `auto-fill` 列模板(规格已定版):轨道在 300–380px 之间,
* 一行放得下几张就放几张,多出来的宽度被 `justify-center` 对称留在两侧 —— 卡不再
* 被拉成整行宽。用 `auto-fill`(不是 `auto-fit`):空轨道保留,末行的卡仍落在与
* 满行相同的列位上,不会为居中整体右移。轨道下限写 `min(300px, 100%)`:容器窄于
* 300px(如 320px 视口的内容区)时轨道跟着收缩,不会横向溢出;其余情况就等同于
* 规格里的 `minmax(300px, 380px)`。类名是源码里的字面量(Tailwind 只扫字面量)。
*/
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",
wide: "grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",
wide: "grid gap-3 justify-center grid-cols-[repeat(auto-fill,minmax(min(300px,100%),380px))]",
};

/**
Expand Down Expand Up @@ -101,12 +110,13 @@ export const CLASSIC_ICON_BOX: Record<TileSize, number> = {

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

Expand Down
41 changes: 29 additions & 12 deletions web/test/link-grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ function grid(container: HTMLElement) {
return el;
}

/**
* wide 档列模板(规格定版):轨道 300–380px、一行多张、整行居中。
* 下限取 `min(300px, 100%)`,容器窄于 300px 时轨道跟着收缩、不横向溢出。
*/
const WIDE_GRID_COLUMNS =
"grid-cols-[repeat(auto-fill,minmax(min(300px,100%),380px))]";

/** 某条链接里那个链接样式的图标盒(固定边长的方块)。 */
function iconBox(link: HTMLElement, linkStyle: LinkStyle): HTMLElement {
const box = link.querySelector<HTMLElement>(`[data-icon-box="${linkStyle}"]`);
Expand Down Expand Up @@ -125,11 +132,18 @@ describe("LinkGrid:三档样式", () => {
expect(link.querySelector("span.min-w-0")).toHaveClass("truncate");
});

it("wide:玻璃底宽卡,图标左、右侧名称 + 域名两行,桌面 3 列", () => {
it("wide:玻璃底宽卡,图标 56px 垂直居中、名称 + 域名两行,列模板 300–380px 封顶 + 整行居中", () => {
const { container } = render(<LinkGrid links={links} linkStyle="wide" />);

const wideGrid = grid(container);
expect(wideGrid).toHaveClass(
"grid",
"gap-3",
"justify-center",
WIDE_GRID_COLUMNS,
);
// 不再是固定列数梯度(那会把卡拉满整行)
expect(wideGrid).not.toHaveClass(
"grid-cols-1",
"sm:grid-cols-2",
"lg:grid-cols-3",
Expand All @@ -139,14 +153,19 @@ describe("LinkGrid:三档样式", () => {
const link = screen.getByRole("link", { name: /GitHub/ });
expect(link).toHaveClass("glass", "glass-hover", "items-center");
expect(link).toHaveTextContent("github.com");
expect(link.querySelector("img")).toHaveAttribute("width", "36");
// 卡宽由网格轨道给(300–380px):砖壳自己不写死宽高、手动加 min-height
expect(link).not.toHaveClass("w-full");
expect(link.className).not.toMatch(/(^|\s)w-\[/);
expect(link.className).not.toContain("min-h");
expect(link.querySelector("img")).toHaveAttribute("width", "56");
expect(iconBox(link, "wide")).toHaveStyle({
width: "36px",
height: "36px",
width: "56px",
height: "56px",
});
// 名称与域名各占一行
const title = screen.getByText("GitHub");
expect(title).toHaveClass("block", "truncate");
expect(link.querySelectorAll("span.block")).toHaveLength(2);
});

it("三档图标盒尺寸与 LINK_ICON_BOX 一致、同档内每条都相同(不随图标文件变化)", () => {
Expand Down Expand Up @@ -205,7 +224,7 @@ describe("CategorySection:把样式透传给网格,锚点偏移随顶栏移
<CategorySection category={category} linkStyle="wide" />,
);

expect(grid(container)).toHaveClass("lg:grid-cols-3");
expect(grid(container)).toHaveClass(WIDE_GRID_COLUMNS);
expect(screen.getByRole("link", { name: /GitHub/ })).toHaveClass("glass");
});
});
Expand Down Expand Up @@ -275,11 +294,7 @@ describe("LinkGrid:classic 成块列数(站点设置 columns)", () => {
const wide = render(
<LinkGrid links={links} linkStyle="wide" columns={12} />,
);
expect(grid(wide.container)).toHaveClass(
"grid-cols-1",
"sm:grid-cols-2",
"lg:grid-cols-3",
);
expect(grid(wide.container)).toHaveClass(WIDE_GRID_COLUMNS);
expect(grid(wide.container).className).not.toContain("xl:grid-cols-12");
expect(grid(wide.container).style.maxWidth).toBe("");
});
Expand Down Expand Up @@ -396,7 +411,7 @@ describe("LinkGrid:classic 砖块尺寸三档(tileSize)", () => {
const wide = render(
<LinkGrid links={links} linkStyle="wide" tileSize="medium" />,
);
expect(grid(wide.container)).toHaveClass("lg:grid-cols-3");
expect(grid(wide.container)).toHaveClass(WIDE_GRID_COLUMNS);
expect(screen.getByRole("link", { name: /GitHub/ })).not.toHaveClass(
"w-[113px]",
"h-[144px]",
Expand All @@ -413,13 +428,15 @@ describe("LinkGrid:显示网址开关(showUrl,缺省开)", () => {
expect(link).not.toHaveTextContent("github.com");
});

it("wide 档 showUrl=false:右侧只剩名称一行,不渲染域名", () => {
it("wide 档 showUrl=false:右侧只剩名称一行,域名行不渲染、不占位", () => {
render(<LinkGrid links={links} linkStyle="wide" showUrl={false} />);

const link = screen.getByRole("link", { name: /GitHub/ });
expect(link).toHaveClass("glass", "glass-hover");
expect(link).toHaveTextContent("GitHub");
expect(link).not.toHaveTextContent("github.com");
// 两行文字变一行:名称行的 span 还在,域名行整块不渲染(不是隐藏留白)
expect(link.querySelectorAll("span.block")).toHaveLength(1);
});

it("compact 档本来就不渲染域名:开关不改变它的形状", () => {
Expand Down
8 changes: 6 additions & 2 deletions web/test/public-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const baseSettings: SiteSettings = {
searchNewTab: true,
};

/** wide 档列模板:轨道 300–380px、一行多张、整行居中(与 link-grid.test 同口径) */
const WIDE_GRID_COLUMNS =
"grid-cols-[repeat(auto-fill,minmax(min(300px,100%),380px))]";

function seed(settings: SiteSettings) {
useNavStore.setState({
publicData: { categories: [], scenes: [], searchEngines: [], settings },
Expand Down Expand Up @@ -157,7 +161,7 @@ describe("PublicPage 头部:时钟块取代顶栏", () => {
const link = screen.getByRole("link", { name: /GitHub/ });
expect(link).toHaveClass("glass");
expect(link).toHaveTextContent("github.com");
expect(link.parentElement?.parentElement).toHaveClass("lg:grid-cols-3");
expect(link.parentElement?.parentElement).toHaveClass(WIDE_GRID_COLUMNS);
});

it("旧后端 / 旧缓存没有 linkStyle:回落 classic(玻璃瓦片 + 域名,与改动前一致)", () => {
Expand Down Expand Up @@ -253,7 +257,7 @@ describe("PublicPage 头部:时钟块取代顶栏", () => {
render(<PublicPage onOpenAdmin={vi.fn()} />);
expect(
screen.getByRole("link", { name: /GitHub/ }).parentElement?.parentElement,
).toHaveClass("lg:grid-cols-3");
).toHaveClass(WIDE_GRID_COLUMNS);
});

it("settings.showUrl=false:普通模式卡片不渲染域名,名称与跳转不变", () => {
Expand Down
Loading