refactor(inbox): 侧边栏素材列表改为轻量 Flex 布局 — Card→Flex, 新增状态 Tag, hover 切换删除按钮, 左侧竖线选中态
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { DeleteOutlined } from "@ant-design/icons";
|
||||
import { Button, Card, Flex, Popconfirm, Typography } from "antd";
|
||||
import { Button, Flex, Popconfirm, Tag, Typography } from "antd";
|
||||
|
||||
import type { Material } from "../types";
|
||||
import type { Material, MaterialStatus } from "../types";
|
||||
|
||||
interface MaterialCardProps {
|
||||
material: Material;
|
||||
@@ -10,34 +10,55 @@ interface MaterialCardProps {
|
||||
selected: boolean;
|
||||
}
|
||||
|
||||
export function MaterialCard({ material, onDelete, onSelect }: MaterialCardProps) {
|
||||
const STATUS_MAP: Record<MaterialStatus, { color: string; label: string }> = {
|
||||
approved: { color: "green", label: "已通过" },
|
||||
discarded: { color: "red", label: "已放弃" },
|
||||
pending: { color: "gold", label: "待审核" },
|
||||
};
|
||||
|
||||
export function MaterialCard({ material, onDelete, onSelect, selected }: MaterialCardProps) {
|
||||
const statusInfo = STATUS_MAP[material.status];
|
||||
const className = selected ? "material-list-item material-list-item--selected" : "material-list-item";
|
||||
|
||||
return (
|
||||
<Card hoverable={false} onClick={onSelect} size="small">
|
||||
<Typography.Paragraph ellipsis={{ rows: 3 }}>{material.description}</Typography.Paragraph>
|
||||
<Flex align="center" justify="space-between">
|
||||
<Typography.Text type="secondary">{formatMaterialTime(material.createdAt)}</Typography.Text>
|
||||
<Popconfirm
|
||||
description="删除后不可恢复"
|
||||
okButtonProps={{ danger: true }}
|
||||
okText="删除"
|
||||
onCancel={(e) => e?.stopPropagation()}
|
||||
onConfirm={(e) => {
|
||||
e?.stopPropagation();
|
||||
onDelete();
|
||||
}}
|
||||
title="确认删除该素材?"
|
||||
>
|
||||
<Button
|
||||
aria-label="删除"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
size="small"
|
||||
type="text"
|
||||
/>
|
||||
</Popconfirm>
|
||||
</Flex>
|
||||
</Card>
|
||||
<Flex align="center" className={className} gap="small" justify="space-between" onClick={onSelect}>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<Typography.Text ellipsis strong={selected}>
|
||||
{material.description}
|
||||
</Typography.Text>
|
||||
<br />
|
||||
<Typography.Text className="material-item-time" type="secondary">
|
||||
{formatMaterialTime(material.createdAt)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
<div className="material-item-right">
|
||||
<span className="material-item-tag">
|
||||
{statusInfo && <Tag color={statusInfo.color}>{statusInfo.label}</Tag>}
|
||||
</span>
|
||||
<span className="material-item-actions">
|
||||
<Popconfirm
|
||||
description="删除后不可恢复"
|
||||
okButtonProps={{ danger: true }}
|
||||
okText="删除"
|
||||
onCancel={(e) => e?.stopPropagation()}
|
||||
onConfirm={(e) => {
|
||||
e?.stopPropagation();
|
||||
onDelete();
|
||||
}}
|
||||
title="确认删除该素材?"
|
||||
>
|
||||
<Button
|
||||
aria-label="删除"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
size="small"
|
||||
type="text"
|
||||
/>
|
||||
</Popconfirm>
|
||||
</span>
|
||||
</div>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,6 @@ body {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
gap: var(--ant-margin-xs);
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
@@ -304,3 +303,65 @@ body {
|
||||
.app-inbox-datepicker {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Inbox material list items */
|
||||
.material-list-item {
|
||||
border-left: 3px solid transparent;
|
||||
border-bottom: 1px solid var(--ant-color-border-secondary);
|
||||
padding: var(--ant-padding-xs) 0;
|
||||
padding-left: var(--ant-padding-sm);
|
||||
cursor: pointer;
|
||||
transition: border-color 0.15s ease, background 0.15s ease;
|
||||
}
|
||||
|
||||
.material-list-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.material-list-item:hover {
|
||||
background: var(--ant-color-fill-tertiary);
|
||||
}
|
||||
|
||||
.material-list-item--selected {
|
||||
border-left-color: var(--ant-color-primary);
|
||||
}
|
||||
|
||||
.material-list-item--selected:hover {
|
||||
background: var(--ant-color-fill-tertiary);
|
||||
}
|
||||
|
||||
.material-item-right {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.material-item-tag,
|
||||
.material-item-actions {
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
|
||||
.material-item-tag {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.material-item-actions {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.material-list-item:hover .material-item-tag {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.material-list-item:hover .material-item-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.material-item-time {
|
||||
font-size: var(--ant-font-size-sm);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const MOCK_MATERIAL: Material = {
|
||||
};
|
||||
|
||||
describe("MaterialCard", () => {
|
||||
test("渲染素材描述和创建时间", () => {
|
||||
test("渲染素材描述、时间和状态标签", () => {
|
||||
renderWithProviders(
|
||||
createElement(MaterialCard, {
|
||||
material: MOCK_MATERIAL,
|
||||
@@ -29,6 +29,7 @@ describe("MaterialCard", () => {
|
||||
);
|
||||
expect(screen.getByText("测试素材描述")).not.toBeNull();
|
||||
expect(screen.getByText("今天")).not.toBeNull();
|
||||
expect(screen.getByText("待审核")).not.toBeNull();
|
||||
});
|
||||
|
||||
test("点击卡片触发 onSelect", () => {
|
||||
@@ -41,8 +42,8 @@ describe("MaterialCard", () => {
|
||||
selected: false,
|
||||
}),
|
||||
);
|
||||
const card = screen.getByText("测试素材描述").closest(".ant-card")!;
|
||||
fireEvent.click(card);
|
||||
const item = screen.getByText("测试素材描述").closest(".material-list-item")!;
|
||||
fireEvent.click(item);
|
||||
expect(onSelect).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -71,7 +72,7 @@ describe("MaterialCard", () => {
|
||||
expect(onSelect).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("选中状态不再使用 app-inbox-card-selected 类", () => {
|
||||
test("选中时包含 material-list-item--selected 类名", () => {
|
||||
renderWithProviders(
|
||||
createElement(MaterialCard, {
|
||||
material: MOCK_MATERIAL,
|
||||
@@ -80,7 +81,20 @@ describe("MaterialCard", () => {
|
||||
selected: true,
|
||||
}),
|
||||
);
|
||||
const card = screen.getByText("测试素材描述").closest(".app-inbox-card-selected");
|
||||
expect(card).toBeNull();
|
||||
const item = screen.getByText("测试素材描述").closest(".material-list-item--selected");
|
||||
expect(item).not.toBeNull();
|
||||
});
|
||||
|
||||
test("未选中时不包含 material-list-item--selected 类名", () => {
|
||||
renderWithProviders(
|
||||
createElement(MaterialCard, {
|
||||
material: MOCK_MATERIAL,
|
||||
onDelete: vi.fn(),
|
||||
onSelect: vi.fn(),
|
||||
selected: false,
|
||||
}),
|
||||
);
|
||||
const item = screen.getByText("测试素材描述").closest(".material-list-item--selected");
|
||||
expect(item).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user