Alert
จาก shadcnกล่องข้อความแจ้งสถานะหรือปัญหาภายในหน้า เช่น ผลการตรวจสอบคำขอกู้ ใส่ไอคอนและปุ่มการกระทำประกอบได้
อนุมัติสำเร็จ
คำขอกู้ของ น้ำใจ ได้รับการอนุมัติเรียบร้อย เงินจะโอนภายใน 2 วันทำการ
ตรวจไม่ผ่าน
ลายเซ็นผู้อนุมัติ (ปี่) ไม่ชัดเจน กรุณาอัปโหลดฉบับใหม่ก่อนส่งพิจารณา
ติดตั้ง
Terminal
pnpm dlx shadcn@latest add @whereui/alertต้องผูก registry และติดตั้ง @whereui/theme นำหน้าเสมอเมื่อติดตั้งครั้งแรก
การใช้งาน
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"import { CheckIcon } from "lucide-react"<Alert> <CheckIcon /> <AlertTitle>อนุมัติสำเร็จ</AlertTitle> <AlertDescription>คำขอกู้ถูกบันทึกเรียบร้อยแล้ว</AlertDescription></Alert>ข้อควรรู้
- ใส่ role=alert ไว้ให้แล้ว โปรแกรมอ่านหน้าจอจะประกาศทันทีเมื่อข้อความถูกแทรก
- ไอคอนที่วางเป็นตัวแรกของ Alert จะถูกจัดวางให้พอดีอัตโนมัติ
ซอร์สโค้ด
components/ui/alert.tsx
import * as React from "react"import { cva, type VariantProps } from "class-variance-authority"import { cn } from "cn"const alertVariants = cva( "group/alert relative grid w-full gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4", { variants: { variant: { default: "bg-card text-card-foreground", destructive: "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current", }, }, defaultVariants: { variant: "default", }, })function Alert({ className, variant, ...props}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) { return ( <div data-slot="alert" role="alert" className={cn(alertVariants({ variant }), className)} {...props} /> )}function AlertTitle({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-title" className={cn( "font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground", className )} {...props} /> )}function AlertDescription({ className, ...props}: React.ComponentProps<"div">) { return ( <div data-slot="alert-description" className={cn( "text-sm text-balance text-muted-foreground md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4", className )} {...props} /> )}function AlertAction({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-action" className={cn("absolute top-2 right-2", className)} {...props} /> )}export { Alert, AlertTitle, AlertDescription, AlertAction }