Components
Loading preview...
Here is Dialog component
npx shadcn@latest add https://21st.dev/r/anubra266/dialog-2"use client";
import { Dialog } from "@ark-ui/react/dialog";
import { Portal } from "@ark-ui/react/portal";
import { X, Edit3, Check } from "lucide-react";
import { useState } from "react";
export default function EditProfileDialog() {
const [profileData, setProfileData] = useState({
firstName: "Jordan",
lastName: "Smith",
username: "jordan-smith",
website: "www.jordansmith.dev",
biography:
"Software engineer who enjoys building clean, efficient applications. Passionate about user experience and modern web technologies.",
});
const maxBioLength = 160;
const remainingChars = maxBioLength - profileData.biography.length;
const handleInputChange = (field: string, value: string) => {
if (field === "biography" && value.length > maxBioLength) return;
setProfileData((prev) => ({ ...prev, [field]: value }));
};
return (
<Dialog.Root>
<Dialog.Trigger asChild>
<button className="rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-4 py-2 text-sm text-gray-900 dark:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors cursor-pointer inline-flex items-center justify-center">
Edit Profile
</button>
</Dialog.Trigger>
<Portal>
<Dialog.Backdrop className="data-[state=open]:animate-backdrop-in data-[state=closed]:animate-backdrop-out fixed inset-0 z-50 bg-black/50 backdrop-blur-xs" />
<Dialog.Positioner className="fixed inset-0 z-50 flex items-center justify-center p-4">
<Dialog.Content className="data-[state=open]:animate-dialog-in data-[state=closed]:animate-dialog-out relative w-full max-w-lg rounded-lg bg-white dark:bg-gray-900 shadow-lg overflow-hidden">
<Dialog.CloseTrigger asChild>
<button className="absolute right-4 top-4 z-10 p-2 bg-black/20 rounded-full text-white hover:bg-black/30 transition-colors cursor-pointer">
<X className="h-4 w-4" />
</button>
</Dialog.CloseTrigger>
<div>
{/* Cover Photo */}
<div className="relative h-32">
<img
src="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&h=300&fit=crop&crop=center"
alt="Cover"
className="w-full h-full object-cover"
/>
<button className="absolute top-4 right-16 p-2 bg-black/20 rounded-full text-white hover:bg-black/30 transition-colors">
<Edit3 className="h-4 w-4" />
</button>
</div>
{/* Profile Section */}
<div className="px-6 pb-6">
{/* Profile Photo */}
<div className="relative -mt-12 mb-6">
<div className="relative w-24 h-24">
<img
src="https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=150&h=150&fit=crop&crop=face"
alt="Profile"
className="w-24 h-24 rounded-full border-4 border-white dark:border-gray-900 object-cover"
/>
<button className="absolute bottom-0 right-0 p-1.5 bg-gray-900 dark:bg-white rounded-full text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 transition-colors">
<Edit3 className="h-3 w-3" />
</button>
</div>
</div>
<Dialog.Title className="text-xl font-semibold text-gray-900 dark:text-white mb-6">
Edit profile
</Dialog.Title>
{/* Form Fields */}
<div className="space-y-4">
<div className="grid grid-cols-2 gap-3">
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-700 dark:text-gray-300">
First name
</label>
<input
type="text"
value={profileData.firstName}
onChange={(e) =>
handleInputChange("firstName", e.target.value)
}
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:outline-hidden focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 transition-colors"
/>
</div>
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-700 dark:text-gray-300">
Last name
</label>
<input
type="text"
value={profileData.lastName}
onChange={(e) =>
handleInputChange("lastName", e.target.value)
}
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:outline-hidden focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 transition-colors"
/>
</div>
</div>
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-700 dark:text-gray-300">
Username
</label>
<div className="relative">
<input
type="text"
value={profileData.username}
onChange={(e) =>
handleInputChange("username", e.target.value)
}
className="w-full px-3 py-2 pr-10 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:outline-hidden focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 transition-colors"
/>
<Check className="absolute right-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-green-600 dark:text-green-400" />
</div>
</div>
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-700 dark:text-gray-300">
Website
</label>
<div className="flex">
<span className="inline-flex items-center px-3 py-2 border border-r-0 border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-700 text-gray-500 dark:text-gray-400 text-sm rounded-l-md">
https://
</span>
<input
type="text"
value={profileData.website}
onChange={(e) =>
handleInputChange("website", e.target.value)
}
className="flex-1 px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-r-md bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:outline-hidden focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 transition-colors"
/>
</div>
</div>
<div className="space-y-1">
<label className="block text-xs font-medium text-gray-700 dark:text-gray-300">
Biography
</label>
<textarea
value={profileData.biography}
onChange={(e) =>
handleInputChange("biography", e.target.value)
}
rows={3}
className="w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-white focus:outline-hidden focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 transition-colors resize-none"
/>
<div className="text-right">
<span className="text-xs text-gray-500 dark:text-gray-400">
{remainingChars} characters left
</span>
</div>
</div>
</div>
{/* Action Buttons */}
<div className="flex justify-end space-x-3 mt-6">
<Dialog.CloseTrigger asChild>
<button className="px-4 py-2 text-sm border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-gray-900 dark:text-white hover:bg-gray-50 dark:hover:bg-gray-700 rounded-md transition-colors cursor-pointer inline-flex items-center justify-center">
Cancel
</button>
</Dialog.CloseTrigger>
<Dialog.CloseTrigger asChild>
<button className="px-4 py-2 text-sm bg-gray-900 dark:bg-white text-white dark:text-gray-900 hover:bg-gray-800 dark:hover:bg-gray-100 rounded-md transition-colors cursor-pointer inline-flex items-center justify-center font-medium">
Save changes
</button>
</Dialog.CloseTrigger>
</div>
</div>
</div>
</Dialog.Content>
</Dialog.Positioner>
</Portal>
</Dialog.Root>
);
}