-
Notifications
You must be signed in to change notification settings - Fork 3
86b1vx0v2: Add Card and Avatar Components with Conditional Rendering for Login Page #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from 22 commits
d7f3e6c
7667e5e
6cea914
4186b7c
d87a8ee
4f3a40b
59f46ce
5063490
dc2f06b
b8b8bb0
eabfa47
b248ef9
f7d0bf4
c172329
ae6ad1c
5df067f
f56a359
f1a0c25
4604ab2
c63bae5
0f92b49
f569066
d80bd87
9feb7d6
fefe3e2
9674436
eb4cfb0
a5bb525
7f0b682
2ae304c
57e513a
6a536cf
c3a828e
081a80d
12a473c
01f6928
fd76e9f
c58a27a
ba2f304
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 'use client'; | ||
|
||
|
|
||
| import { usePathname } from 'next/navigation'; // Import usePathname | ||
| import ProfileCard from "@/components/ProfileCard"; | ||
|
|
||
| const ConditionalLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
| const pathname = usePathname(); // Get the current pathname | ||
|
|
||
| const isLoginPage = pathname === '/login'; // Check if the current page is the login page | ||
|
|
||
| return ( | ||
| <> | ||
| {!isLoginPage && ( | ||
| <> | ||
| {/* Logo in the top-left corner */} | ||
| <div className="absolute top-4 left-4"> | ||
| <img | ||
| src="../t2t logo.png" // Ensure correct file path and name | ||
| alt="T2T Logo" | ||
| className="w-24 h-auto" // Adjust size as needed | ||
| /> | ||
| </div> | ||
|
|
||
| {/* ProfileCard component in the top-right corner */} | ||
| <div className="absolute top-4 right-4"> | ||
| <ProfileCard /> | ||
| </div> | ||
| </> | ||
| )} | ||
| <main className="p-4"> | ||
| {children} | ||
| </main> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default ConditionalLayout; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
| import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
| import { Card, CardContent, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; | ||
|
|
||
| export default function ProfileCard() { | ||
| const [isCardVisible, setIsCardVisible] = useState(false); | ||
|
|
||
| // Toggle the visibility of the card | ||
| const toggleCardVisibility = () => { | ||
| setIsCardVisible(!isCardVisible); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="relative"> | ||
| {/* Button to toggle the visibility of the profile card */} | ||
| <button onClick={toggleCardVisibility} className="absolute top-4 right-4"> | ||
| <Avatar> | ||
| <AvatarImage src="https://github.com/shadcn.png" /> | ||
| <AvatarFallback>CN</AvatarFallback> | ||
| </Avatar> | ||
| </button> | ||
|
|
||
| {/* Conditional rendering of the profile card */} | ||
| {isCardVisible && ( | ||
| <div className="absolute top-16 right-0 bg-gradient-to-b from-blue-100 to-blue-200 p-3 border border-gray-200 rounded shadow-lg"> | ||
| <Card className="w-56 rounded-lg overflow-hidden shadow-xl"> | ||
| {/* Card header with avatar and green background */} | ||
| <CardHeader className="relative flex flex-col items-center justify-center bg-green-400 h-28 p-3"> | ||
| <Avatar className="w-20 h-20 border-4 border-white absolute -bottom-10"> | ||
| <AvatarImage src="https://github.com/shadcn.png" /> | ||
| <AvatarFallback>CN</AvatarFallback> | ||
| </Avatar> | ||
| </CardHeader> | ||
|
|
||
| {/* Card content displaying the user's name and email */} | ||
| <CardContent className="mt-12 text-center p-2"> | ||
| <CardTitle className="text-md font-semibold">Mohamed Asfik</CardTitle> | ||
| <p className="text-xs text-gray-700">[email protected]</p> | ||
| </CardContent> | ||
|
|
||
| {/* Card footer with the logout button */} | ||
| <CardFooter className="flex justify-center p-2"> | ||
| {/* Remove the logout functionality */} | ||
| <button | ||
| className="bg-gray-500 text-white py-1 px-3 rounded-md hover:bg-gray-600" | ||
|
|
||
| > | ||
| Logout | ||
| </button> | ||
| </CardFooter> | ||
| </Card> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| "use client" | ||
|
|
||
| import * as React from "react" | ||
| import * as AvatarPrimitive from "@radix-ui/react-avatar" | ||
|
|
||
| import { cn } from "@/lib/utils" | ||
|
|
||
| const Avatar = React.forwardRef< | ||
| React.ElementRef<typeof AvatarPrimitive.Root>, | ||
| React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> | ||
| >(({ className, ...props }, ref) => ( | ||
| <AvatarPrimitive.Root | ||
| ref={ref} | ||
| className={cn( | ||
| "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| Avatar.displayName = AvatarPrimitive.Root.displayName | ||
|
|
||
| const AvatarImage = React.forwardRef< | ||
| React.ElementRef<typeof AvatarPrimitive.Image>, | ||
| React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> | ||
| >(({ className, ...props }, ref) => ( | ||
| <AvatarPrimitive.Image | ||
| ref={ref} | ||
| className={cn("aspect-square h-full w-full", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| AvatarImage.displayName = AvatarPrimitive.Image.displayName | ||
|
|
||
| const AvatarFallback = React.forwardRef< | ||
| React.ElementRef<typeof AvatarPrimitive.Fallback>, | ||
| React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> | ||
| >(({ className, ...props }, ref) => ( | ||
| <AvatarPrimitive.Fallback | ||
| ref={ref} | ||
| className={cn( | ||
| "flex h-full w-full items-center justify-center rounded-full bg-muted", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName | ||
|
|
||
| export { Avatar, AvatarImage, AvatarFallback } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import * as React from "react" | ||
|
|
||
| import { cn } from "@/lib/utils" | ||
|
|
||
| const Card = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn( | ||
| "rounded-lg border bg-card text-card-foreground shadow-sm", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| Card.displayName = "Card" | ||
|
|
||
| const CardHeader = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn("flex flex-col space-y-1.5 p-6", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardHeader.displayName = "CardHeader" | ||
|
|
||
| const CardTitle = React.forwardRef< | ||
| HTMLParagraphElement, | ||
| React.HTMLAttributes<HTMLHeadingElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <h3 | ||
| ref={ref} | ||
| className={cn( | ||
| "text-2xl font-semibold leading-none tracking-tight", | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardTitle.displayName = "CardTitle" | ||
|
|
||
| const CardDescription = React.forwardRef< | ||
| HTMLParagraphElement, | ||
| React.HTMLAttributes<HTMLParagraphElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <p | ||
| ref={ref} | ||
| className={cn("text-sm text-muted-foreground", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardDescription.displayName = "CardDescription" | ||
|
|
||
| const CardContent = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div ref={ref} className={cn("p-6 pt-0", className)} {...props} /> | ||
| )) | ||
| CardContent.displayName = "CardContent" | ||
|
|
||
| const CardFooter = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn("flex items-center p-6 pt-0", className)} | ||
| {...props} | ||
| /> | ||
| )) | ||
| CardFooter.displayName = "CardFooter" | ||
|
|
||
| export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this? Remove it, if it's unnecessary. Explain here if it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary, I will remove that.