Files
omniai-ds-code-package/src/features/ecommerce/EcommerceProgressBar.tsx
T

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-06-10 14:06:16 +08:00
import { useSmoothedProgress } from "../../hooks/useSmoothedProgress";
import type { ReactNode } from "react";
2026-06-10 14:06:16 +08:00
interface EcommerceProgressBarProps {
status: "idle" | "generating" | "done" | "failed" | string;
label?: string;
onCancel?: () => void;
2026-06-10 14:06:16 +08:00
}
function mapStatus(status: string): "running" | "completed" | "failed" {
if (status === "done") return "completed";
if (status === "failed") return "failed";
if (status === "generating" || status === "modeling") return "running";
return "running";
}
export function EcommerceProgressBar({ status, label, onCancel }: EcommerceProgressBarProps) {
2026-06-10 14:06:16 +08:00
const progress = mapStatus(status) === "running" ? 50 : 100;
const smoothed = useSmoothedProgress(progress, mapStatus(status));
if (status === "idle") return null;
return (
<div className="ecommerce-progress-bar">
<span className="ecommerce-progress-bar__label">{label || "AI 正在生成"}</span>
{onCancel ? (
<button
type="button"
className="ecommerce-progress-bar__cancel"
onClick={(e) => { e.stopPropagation(); onCancel(); }}
title="取消生成"
aria-label="取消生成"
>
</button>
) : null}
2026-06-10 14:06:16 +08:00
<div className="ecommerce-progress-bar__track">
<div className="ecommerce-progress-bar__fill" style={{ width: `${smoothed}%` }} />
</div>
<span className="ecommerce-progress-bar__value">{smoothed}%</span>
</div>
);
}