39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import type { ReactNode } from "react";
|
|
|
|
export type AdminStatusTone = "ok" | "warn" | "danger" | "muted" | "accent";
|
|
|
|
const toneClass: Record<AdminStatusTone, string> = {
|
|
ok: "is-ok",
|
|
warn: "is-warn",
|
|
danger: "is-danger",
|
|
muted: "is-muted",
|
|
accent: "is-accent",
|
|
};
|
|
|
|
/** 待审 / 已发布 / 已拒绝 / 草稿 / 已删除 等状态粒 */
|
|
export default function AdminStatusChip({
|
|
children,
|
|
tone = "muted",
|
|
className = "",
|
|
}: {
|
|
children: ReactNode;
|
|
tone?: AdminStatusTone;
|
|
className?: string;
|
|
}) {
|
|
return (
|
|
<span className={`admin-status ${toneClass[tone]} ${className}`.trim()}>{children}</span>
|
|
);
|
|
}
|
|
|
|
/** 内容状态 → 文案 + tone */
|
|
export function contentStatusChip(
|
|
status: string,
|
|
deleted: boolean
|
|
): { label: string; tone: AdminStatusTone } {
|
|
if (deleted) return { label: "已删除", tone: "danger" };
|
|
if (status === "pending") return { label: "待审", tone: "warn" };
|
|
if (status === "rejected") return { label: "已拒绝", tone: "danger" };
|
|
if (status === "published") return { label: "已发布", tone: "ok" };
|
|
return { label: status, tone: "muted" };
|
|
}
|