"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { Alert, AlertAction, AlertDescription, AlertTitle } from "@suphark/ui/components/ui/alert"; import { focusAfterDismiss } from "@suphark/ui/lib/focus-after-remove"; import { cn } from "@suphark/ui/lib/utils"; import { type ComponentProps, type ReactNode, useState } from "react"; import { ActionClose, StatusError, StatusInfo, StatusSuccess, StatusWarning, } from "./semantic-icons"; import type { Tone } from "./status-badge"; import { useUiText } from "./ui-text"; export type NoticeTone = Exclude; /** token โทนใน styles.css (สลับ dark ให้เอง) */ const TONE: Record = { info: "border-info-border bg-info-subtle text-info-subtle-foreground", success: "border-success-border bg-success-subtle text-success-subtle-foreground", warning: "border-warning-border bg-warning-subtle text-warning-subtle-foreground", danger: "border-destructive-border bg-destructive-subtle text-destructive-subtle-foreground", }; const TONE_ICON: Record = { info: , success: , warning: , danger: , }; /** * Alert ของ shadcn + สีตามความหมาย (info/success/warning/danger) * `icon` = true ใช้ไอคอนตามโทน หรือส่งไอคอนเอง · `dismissible` = มีปุ่ม X ซ่อนเองเมื่อกด (+ `onDismiss` เช่นจำไว้ใน cookie) * * ตรวจกล่องจดหมาย… */ export function Notice({ tone = "info", title, icon, dismissible = false, onDismiss, children, className, ...props }: Omit, "variant" | "title"> & { tone?: NoticeTone; title?: ReactNode; /** true = ไอคอนตามโทน, ReactNode = ไอคอนเอง */ icon?: ReactNode | boolean; /** แสดงปุ่มปิด (UiText.close) — กดแล้วซ่อนกล่องนี้ */ dismissible?: boolean; onDismiss?: () => void; }) { const closeLabel = useUiText().close ?? "ปิด"; const [hidden, setHidden] = useState(false); if (hidden) return null; const iconNode = icon === true ? TONE_ICON[tone] : icon || null; return ( {iconNode} {title && {title}} {children} {dismissible && ( )} ); }