نشان (Badge)
نمایش برچسب، وضعیت، یا دستهبندی.
نصب (Installation)
1npx @quark-lab/rad-ui add badgeنمونهها (Examples)
استفاده پایه (Basic Usage)
استفاده ساده از Badge برای نمایش برچسب.
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2
3export default function BasicExample() {
4 return (
5 <div className="flex items-center gap-3 flex-wrap">
6 <Badge>پیشفرض</Badge>
7 <Badge>فعال</Badge>
8 <Badge>جدید</Badge>
9 </div>
10 );
11}
12انواع (Variants)
انواع مختلف Badge برای موارد مختلف (Default, Secondary, Destructive, Outline).
پیشفرض (Default)
ثانویه (Secondary)
هشدار (Destructive)
حاشیهدار (Outline)
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2
3export default function VariantsExample() {
4 return (
5 <div className="flex flex-col gap-6">
6 <div className="flex flex-col gap-3">
7 <h3 className="text-sm font-medium">پیشفرض (Default)</h3>
8 <div className="flex items-center gap-3 flex-wrap">
9 <Badge variant="default">فعال</Badge>
10 <Badge variant="default">جدید</Badge>
11 <Badge variant="default">ویژه</Badge>
12 </div>
13 </div>
14
15 <div className="flex flex-col gap-3">
16 <h3 className="text-sm font-medium">ثانویه (Secondary)</h3>
17 <div className="flex items-center gap-3 flex-wrap">
18 <Badge variant="secondary">در انتظار</Badge>
19 <Badge variant="secondary">پیشنویس</Badge>
20 <Badge variant="secondary">آرشیو</Badge>
21 </div>
22 </div>
23
24 <div className="flex flex-col gap-3">
25 <h3 className="text-sm font-medium">هشدار (Destructive)</h3>
26 <div className="flex items-center gap-3 flex-wrap">
27 <Badge variant="destructive">خطا</Badge>
28 <Badge variant="destructive">حذف شده</Badge>
29 <Badge variant="destructive">رد شده</Badge>
30 </div>
31 </div>
32
33 <div className="flex flex-col gap-3">
34 <h3 className="text-sm font-medium">حاشیهدار (Outline)</h3>
35 <div className="flex items-center gap-3 flex-wrap">
36 <Badge variant="outline">برچسب</Badge>
37 <Badge variant="outline">دستهبندی</Badge>
38 <Badge variant="outline">تگ</Badge>
39 </div>
40 </div>
41 </div>
42 );
43}
44با آیکون (With Icons)
ترکیب Badge با آیکون برای نمایش وضعیت.
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2import { Check, X, Clock, Star, TrendingUp } from "lucide-react";
3
4export default function WithIconsExample() {
5 return (
6 <div className="flex items-center gap-3 flex-wrap">
7 <Badge variant="default" className="gap-1">
8 <Check className="h-3 w-3" />
9 تایید شده
10 </Badge>
11 <Badge variant="destructive" className="gap-1">
12 <X className="h-3 w-3" />
13 رد شده
14 </Badge>
15 <Badge variant="secondary" className="gap-1">
16 <Clock className="h-3 w-3" />
17 در انتظار
18 </Badge>
19 <Badge variant="outline" className="gap-1">
20 <Star className="h-3 w-3" />
21 ویژه
22 </Badge>
23 <Badge variant="default" className="gap-1">
24 <TrendingUp className="h-3 w-3" />
25 پرفروش
26 </Badge>
27 </div>
28 );
29}
30رنگهای سفارشی (Custom Colors)
استفاده از کلاسهای Tailwind برای تغییر رنگ Badge.
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2
3export default function CustomColorsExample() {
4 return (
5 <div className="flex items-center gap-3 flex-wrap">
6 <Badge className="bg-blue-500 text-white hover:bg-blue-600">
7 آبی
8 </Badge>
9 <Badge className="bg-green-500 text-white hover:bg-green-600">
10 سبز
11 </Badge>
12 <Badge className="bg-purple-500 text-white hover:bg-purple-600">
13 بنفش
14 </Badge>
15 <Badge className="bg-orange-500 text-white hover:bg-orange-600">
16 نارنجی
17 </Badge>
18 <Badge className="bg-pink-500 text-white hover:bg-pink-600">
19 صورتی
20 </Badge>
21 <Badge className="bg-yellow-500 text-gray-900 hover:bg-yellow-600">
22 زرد
23 </Badge>
24 </div>
25 );
26}
27مثالهای کاربردی (Practical Examples)
نشانهای وضعیت (Status Badges)
نمایش وضعیت سفارش با آیکونهای مرتبط.
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2import { Check, X, Clock, AlertCircle } from "lucide-react";
3
4export default function StatusExample() {
5 return (
6 <div className="space-y-4">
7 <div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
8 <span className="text-sm">سفارش #1234</span>
9 <Badge variant="default" className="gap-1">
10 <Check className="h-3 w-3" />
11 تحویل داده شده
12 </Badge>
13 </div>
14 <div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
15 <span className="text-sm">سفارش #1235</span>
16 <Badge variant="secondary" className="gap-1">
17 <Clock className="h-3 w-3" />
18 در حال پردازش
19 </Badge>
20 </div>
21 <div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
22 <span className="text-sm">سفارش #1236</span>
23 <Badge variant="destructive" className="gap-1">
24 <X className="h-3 w-3" />
25 لغو شده
26 </Badge>
27 </div>
28 <div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
29 <span className="text-sm">سفارش #1237</span>
30 <Badge
31 variant="outline"
32 className="gap-1 bg-yellow-50 dark:bg-yellow-950 border-yellow-300"
33 >
34 <AlertCircle className="h-3 w-3" />
35 نیاز به بررسی
36 </Badge>
37 </div>
38 </div>
39 );
40}
41نشانهای اعلان (Notification Badges)
استفاده از Badge برای نمایش تعداد اعلانها.
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2import { Mail, Bell } from "lucide-react";
3
4export default function NotificationExample() {
5 return (
6 <div className="flex flex-wrap gap-6">
7 <div className="relative">
8 <Mail className="h-6 w-6" />
9 <Badge className="absolute -top-2 -right-2 h-5 w-5 flex items-center justify-center p-0 text-[10px]">
10 5
11 </Badge>
12 </div>
13 <div className="relative">
14 <Bell className="h-6 w-6" />
15 <Badge className="absolute -top-2 -right-2 h-5 w-5 flex items-center justify-center p-0 text-[10px]">
16 12
17 </Badge>
18 </div>
19 <div className="relative inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-muted">
20 <span className="text-sm">پیامها</span>
21 <Badge variant="destructive">3</Badge>
22 </div>
23 </div>
24 );
25}
26برچسبهای محصول (Product Tags)
استفاده در کارت محصول برای نمایش ویژگیها.
هدفون بیسیم
کیفیت صدای عالی با نویز کنسلینگ
کفش ورزشی
راحتی بینظیر برای ورزش روزانه
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2import { Sparkles, Tag } from "lucide-react";
3
4export default function ProductCardExample() {
5 return (
6 <div className="grid md:grid-cols-2 gap-6">
7 <div className="p-4 rounded-lg border border-border">
8 <div className="flex items-start justify-between mb-3">
9 <h4 className="font-semibold">هدفون بیسیم</h4>
10 <Badge variant="default" className="gap-1">
11 <Sparkles className="h-3 w-3" />
12 جدید
13 </Badge>
14 </div>
15 <p className="text-sm text-muted-foreground mb-3">
16 کیفیت صدای عالی با نویز کنسلینگ
17 </p>
18 <div className="flex items-center gap-2">
19 <Badge variant="outline" className="gap-1">
20 <Tag className="h-3 w-3" />
21 الکترونیک
22 </Badge>
23 <Badge className="bg-green-500 text-white">موجود</Badge>
24 </div>
25 </div>
26
27 <div className="p-4 rounded-lg border border-border">
28 <div className="flex items-start justify-between mb-3">
29 <h4 className="font-semibold">کفش ورزشی</h4>
30 <Badge variant="destructive">50% تخفیف</Badge>
31 </div>
32 <p className="text-sm text-muted-foreground mb-3">
33 راحتی بینظیر برای ورزش روزانه
34 </p>
35 <div className="flex items-center gap-2">
36 <Badge variant="outline" className="gap-1">
37 <Tag className="h-3 w-3" />
38 پوشاک
39 </Badge>
40 <Badge
41 variant="secondary"
42 className="bg-orange-100 text-orange-800 dark:bg-orange-950 dark:text-orange-200"
43 >
44 تعداد محدود
45 </Badge>
46 </div>
47 </div>
48 </div>
49 );
50}
51نشانهای کاربری (User Badges)
نمایش نقش یا وضعیت کاربر در لیست.
توسعهدهنده فرانتاند
طراح UI/UX
مدیر محصول
مشاهده کد
1import { Badge } from "@/components/ui/badge";
2import { Check, Star, Sparkles } from "lucide-react";
3
4export default function UserListExample() {
5 return (
6 <div className="space-y-3">
7 <div className="flex items-center gap-3">
8 <div className="h-10 w-10 rounded-full bg-gradient-to-br from-purple-500 to-pink-500" />
9 <div className="flex-1">
10 <div className="flex items-center gap-2">
11 <span className="font-medium">علی محمدی</span>
12 <Badge variant="default" className="gap-1 bg-blue-500 text-white">
13 <Check className="h-3 w-3" />
14 تایید شده
15 </Badge>
16 </div>
17 <p className="text-sm text-muted-foreground">
18 توسعهدهنده فرانتاند
19 </p>
20 </div>
21 </div>
22
23 <div className="flex items-center gap-3">
24 <div className="h-10 w-10 rounded-full bg-gradient-to-br from-blue-500 to-cyan-500" />
25 <div className="flex-1">
26 <div className="flex items-center gap-2">
27 <span className="font-medium">سارا احمدی</span>
28 <Badge
29 variant="outline"
30 className="gap-1 bg-purple-50 dark:bg-purple-950 border-purple-300"
31 >
32 <Star className="h-3 w-3" />
33 Pro
34 </Badge>
35 </div>
36 <p className="text-sm text-muted-foreground">طراح UI/UX</p>
37 </div>
38 </div>
39
40 <div className="flex items-center gap-3">
41 <div className="h-10 w-10 rounded-full bg-gradient-to-br from-green-500 to-emerald-500" />
42 <div className="flex-1">
43 <div className="flex items-center gap-2">
44 <span className="font-medium">رضا کریمی</span>
45 <Badge
46 variant="secondary"
47 className="gap-1 bg-yellow-100 text-yellow-800 dark:bg-yellow-950 dark:text-yellow-200"
48 >
49 <Sparkles className="h-3 w-3" />
50 مدیر
51 </Badge>
52 </div>
53 <p className="text-sm text-muted-foreground">مدیر محصول</p>
54 </div>
55 </div>
56 </div>
57 );
58}
59مرجع API (API Reference)
Badge
پراپهای کامپوننت Badge.
| پراپ (Prop) | نوع (Type) | پیشفرض (Default) | توضیحات (Description) |
|---|---|---|---|
variant | "default" | "secondary" | "destructive" | "outline" | "default" | نوع نمایشی Badge |
className | string | undefined | کلاسهای CSS سفارشی |
children | ReactNode | undefined | محتوای Badge (متن یا آیکون) |
دسترسیپذیری (Accessibility)
محتوای واضح
متن داخل Badge باید واضح و قابل فهم باشد. از مخففهای نامفهوم خودداری کنید
کنتراست رنگ
مطمئن شوید که رنگ متن و پسزمینه کنتراست کافی دارند (نسبت حداقل 4.5:1)
معنای رنگی
فقط به رنگ برای انتقال اطلاعات تکیه نکنید. از متن یا آیکون نیز استفاده کنید
بهترین شیوهها (Best Practices)
متن کوتاه و مختصر
Badge برای متنهای کوتاه طراحی شده. از متنهای طولانی خودداری کنید
استفاده مناسب از variant
از destructive فقط برای خطا و هشدار استفاده کنید. از secondary برای اطلاعات کم اهمیتتر
آیکونهای کوچک
اگر از آیکون استفاده میکنید، اندازه آن را 3x3 یا 4x4 نگه دارید
رنگهای سفارشی
هنگام استفاده از رنگهای سفارشی، حتماً حالت hover را نیز تنظیم کنید
جایگذاری
Badge را در کنار عناصر مرتبط قرار دهید، نه به صورت مجزا