46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
|
|
import type { ReactNode } from "react";
|
||
|
|
import { CircleAlert, CircleCheck, TriangleAlert } from "lucide-react";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Genesis MessageBar ของ wordaddin — แทน MessageBar ของ Fluent UI v9 ต้นฉบับ
|
||
|
|
* intent error = ข้อความ/ไอคอนใช้เฉด -ink (contrast ≥5:1 ตาม DESIGN.md), พื้น tint จาง
|
||
|
|
* มี icon นำตามระดับ — แยกด้วยรูปทรง ไม่ใช่สีอย่างเดียว (WCAG 1.4.1) + role ให้ screen
|
||
|
|
* reader ประกาศ (error = alert, ที่เหลือ = status polite — WCAG 4.1.3) + w-full ให้ทุก
|
||
|
|
* แถบกว้างเท่ากันทั้งคอลัมน์
|
||
|
|
* prop action = ปุ่มเสริมในแถบ (เช่น "ลองใหม่" ของ bootError/history error)
|
||
|
|
*/
|
||
|
|
|
||
|
|
const ICONS = {
|
||
|
|
error: CircleAlert,
|
||
|
|
warning: TriangleAlert,
|
||
|
|
success: CircleCheck,
|
||
|
|
} as const;
|
||
|
|
|
||
|
|
export function MessageBar({
|
||
|
|
intent,
|
||
|
|
children,
|
||
|
|
action,
|
||
|
|
}: {
|
||
|
|
intent: "error" | "warning" | "success";
|
||
|
|
children: ReactNode;
|
||
|
|
action?: ReactNode;
|
||
|
|
}) {
|
||
|
|
const Icon = ICONS[intent];
|
||
|
|
const tone =
|
||
|
|
intent === "error"
|
||
|
|
? "border-error/30 bg-error/10 text-error-ink"
|
||
|
|
: intent === "warning"
|
||
|
|
? "border-warning/30 bg-warning/15 text-warning-ink"
|
||
|
|
: "border-success/30 bg-success/10 text-success-ink";
|
||
|
|
return (
|
||
|
|
<div
|
||
|
|
role={intent === "error" ? "alert" : "status"}
|
||
|
|
className={`flex w-full items-start gap-2 rounded-lg border px-3 py-2 text-sm ${tone}`}
|
||
|
|
>
|
||
|
|
<Icon className="mt-0.5 size-4 shrink-0" aria-hidden />
|
||
|
|
<div className="min-w-0 flex-1 break-words">{children}</div>
|
||
|
|
{action ? <div className="shrink-0">{action}</div> : null}
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|