Initial import of 1407 block sources under blocks/
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
"use client";
|
||||
|
||||
import { Camera, X } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
|
||||
import {
|
||||
FileUpload,
|
||||
FileUploadItem,
|
||||
FileUploadItemDelete,
|
||||
FileUploadList,
|
||||
FileUploadTrigger,
|
||||
} from "@/components/diceui/file-upload";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface ProfileFormData {
|
||||
name: string;
|
||||
email: string;
|
||||
username: string;
|
||||
avatar?: string;
|
||||
bio?: string;
|
||||
}
|
||||
|
||||
interface SettingsProfile1Props {
|
||||
defaultValues?: Partial<ProfileFormData>;
|
||||
onSave?: (data: ProfileFormData) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const SettingsProfile1 = ({
|
||||
defaultValues = {
|
||||
name: "الهام میرزایی",
|
||||
email: "alex.morgan@email.com",
|
||||
username: "alexmorgan",
|
||||
avatar:
|
||||
"/block-media/shadcnblocks/block/avatar/avatar8.jpg",
|
||||
bio: "طراح محصول با بیش از ۸ سال تجربه در خلق تجربههای دیجیتال کاربرپسند. در حال حاضر روی سیستمهای طراحی و دسترسپذیری تمرکز دارم.",
|
||||
},
|
||||
className,
|
||||
}: SettingsProfile1Props) => {
|
||||
const [avatarFiles, setAvatarFiles] = useState<File[]>([]);
|
||||
|
||||
const initials = defaultValues.name
|
||||
?.split(" ")
|
||||
.map((n) => n[0])
|
||||
.join("")
|
||||
.toUpperCase();
|
||||
|
||||
// Get preview URL from uploaded file or use default avatar
|
||||
const avatarPreview =
|
||||
avatarFiles.length > 0
|
||||
? URL.createObjectURL(avatarFiles[0])
|
||||
: defaultValues.avatar;
|
||||
|
||||
return (
|
||||
<Card className={cn("w-full max-w-lg", className)}>
|
||||
<CardHeader>
|
||||
<CardTitle>پروفایل</CardTitle>
|
||||
<CardDescription>
|
||||
اطلاعات شخصی و تصویر پروفایل خود را بهروزرسانی کنید.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
{/* Avatar Upload */}
|
||||
<FileUpload
|
||||
value={avatarFiles}
|
||||
onValueChange={setAvatarFiles}
|
||||
accept="image/*"
|
||||
maxFiles={1}
|
||||
maxSize={2 * 1024 * 1024}
|
||||
>
|
||||
<div className="flex items-center gap-4">
|
||||
<FileUploadTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="group relative size-20 shrink-0 cursor-pointer rounded-full focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-none"
|
||||
>
|
||||
<Avatar className="size-20">
|
||||
<AvatarImage
|
||||
src={avatarPreview}
|
||||
alt={`تصویر ${defaultValues.name}`}
|
||||
className="object-cover"
|
||||
/>
|
||||
<AvatarFallback className="text-xl font-semibold">
|
||||
{initials}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="absolute inset-0 flex items-center justify-center rounded-full bg-black/50 opacity-0 transition-opacity group-hover:opacity-100">
|
||||
<Camera className="size-6 text-white" />
|
||||
</div>
|
||||
</button>
|
||||
</FileUploadTrigger>
|
||||
|
||||
<div className="space-y-1">
|
||||
<p className="text-sm font-medium">تصویر پروفایل</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
برای بارگذاری تصویر جدید روی آواتار کلیک کنید
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
تصویر، تصویر یا تصویر. حداکثر ۲ مگابایت.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{avatarFiles.length > 0 && (
|
||||
<FileUploadList className="mt-3">
|
||||
{avatarFiles.map((file, index) => (
|
||||
<FileUploadItem
|
||||
key={index}
|
||||
value={file}
|
||||
className="rounded-lg border bg-muted/30 p-2"
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-medium">{file.name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{(file.size / 1024).toLocaleString("fa-IR", {
|
||||
maximumFractionDigits: 1,
|
||||
})}{" "}
|
||||
کیلوبایت
|
||||
</p>
|
||||
</div>
|
||||
<FileUploadItemDelete asChild>
|
||||
<Button variant="ghost" size="icon" className="size-8">
|
||||
<X className="size-4" />
|
||||
</Button>
|
||||
</FileUploadItemDelete>
|
||||
</FileUploadItem>
|
||||
))}
|
||||
</FileUploadList>
|
||||
)}
|
||||
</FileUpload>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="name">نام کامل</Label>
|
||||
<Input
|
||||
id="name"
|
||||
placeholder="نام خود را وارد کنید"
|
||||
defaultValue={defaultValues.name}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="username">نام کاربری</Label>
|
||||
<Input
|
||||
id="username"
|
||||
placeholder="نام کاربری را وارد کنید"
|
||||
defaultValue={defaultValues.username}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">ایمیل</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="ایمیل خود را وارد کنید"
|
||||
defaultValue={defaultValues.email}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="bio">درباره من</Label>
|
||||
<Textarea
|
||||
id="bio"
|
||||
placeholder="درباره خودتان بنویسید"
|
||||
rows={4}
|
||||
defaultValue={defaultValues.bio}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
توضیح کوتاه برای پروفایل. حداکثر ۱۶۰ کاراکتر.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
<CardFooter className="flex justify-end gap-2">
|
||||
<Button variant="outline">انصراف</Button>
|
||||
<Button>ذخیره تغییرات</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export { SettingsProfile1 };
|
||||
Reference in New Issue
Block a user