remove next image

This commit is contained in:
Ichsan Kurniawan
2026-01-28 21:10:07 +07:00
parent e0e9f8651f
commit 5e439ea9f7
38 changed files with 216 additions and 113 deletions
+103
View File
@@ -0,0 +1,103 @@
import { FC } from 'react';
import Image from 'next/image';
import { Dialog, DialogContent, DialogHeader, DialogTrigger } from './ui/dialog';
import { cn } from '@/lib/utils';
import { DialogDescription, DialogTitle } from '@radix-ui/react-dialog';
type Props = {
avatar: string
className?: string,
isPresence?: boolean
sizes?: string;
quality?: number
};
const ViewAvatarNextImage: FC<Props> = ({ avatar, className, isPresence, quality = 65, sizes = "(max-width: 640px) 36px, 40px" }) => {
return (
<>
{avatar ?
<Dialog>
<DialogTrigger asChild>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} /> */}
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
fill
sizes={sizes}
quality={quality}
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
</DialogTrigger>
<DialogContent className={`overflow-hidden p-0 rounded-2xl ${isPresence ? 'h-auto w-full' : 'w-full h-[400px] sm:w-[500px] sm:h-[500px]'}`}>
<DialogHeader className='sr-only'>
<DialogTitle>Profile</DialogTitle>
<DialogDescription>Description of profile avatar</DialogDescription>
</DialogHeader>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className="w-full h-full shadow-sm rounded-2xl border border-border" /> */}
{/* 2. Logic Switch for Image Mode */}
{isPresence ? (
// MODE A: Presence (Natural Aspect Ratio)
// We use width=0 height=0 + sizes=100vw to emulate "width: 100%, height: auto"
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
width={0}
height={0}
sizes="100vw"
quality={90}
className="w-full h-auto object-contain" // h-auto lets it grow naturally
/>
) : (
// MODE B: Default Profile (Fixed Box with Crop)
// We use fill to cover the specific 500x500 box
<div className="relative w-full h-full">
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
fill
className="object-cover shadow-sm border border-border"
sizes="(max-width: 640px) 100vw, 500px"
quality={90}
/>
</div>
)}
</DialogContent>
</Dialog>
:
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
alt='avatar'
src='/assets/no-avatar.jpg'
fill
sizes={sizes}
className='shadow-sm rounded-full object-cover border border-border'
/>
</div>
}
</>
);
}
export const Avatar: FC<Props> = ({ avatar, className, sizes = "(max-width: 640px) 36px, 40px" }) => {
return (
<>
{avatar ?
// <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} />
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image src={`${process.env.BASE_URL_IMG}${avatar}`} alt="avatar"
fill // This replaces width/height
sizes={sizes} // Optimization (explained below)
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
:
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/no-avatar.jpg' className={cn('h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border', className)} />
}
</>
);
}
export default ViewAvatarNextImage;
+72 -69
View File
@@ -1,101 +1,104 @@
'use client'
import { FC } from 'react';
import Image from 'next/image';
import { Dialog, DialogContent, DialogHeader, DialogTrigger } from './ui/dialog';
import { LazyLoadImage } from 'react-lazy-load-image-component';
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from './ui/dialog';
import { cn } from '@/lib/utils';
import { DialogDescription, DialogTitle } from '@radix-ui/react-dialog';
type Props = {
avatar: string
className?: string,
isPresence?: boolean
sizes?: string;
quality?: number
avatar: string | null; // Allow null to handle fallback logic safely
className?: string;
isPresence?: boolean;
// sizes and quality are removed as they are specific to Next/Image server processing
};
const ViewAvatar: FC<Props> = ({ avatar, className, isPresence, quality = 65, sizes = "(max-width: 640px) 36px, 40px" }) => {
const ViewAvatar: FC<Props> = ({ avatar, className, isPresence }) => {
return (
<>
{avatar ?
{avatar ? (
<Dialog>
<DialogTrigger asChild>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} /> */}
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
src={`${process.env.BASE_URL_IMG}${avatar}`}
{/* 1. TRIGGER IMAGE
Removed the wrapper div. Applied classes directly to LazyLoadImage.
Added `block` to wrapperClassName to prevent extra inline spacing.
*/}
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt="avatar"
fill
sizes={sizes}
quality={quality}
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
src={`${process.env.BASE_URL_IMG}${avatar}`}
effect="blur"
wrapperClassName="w-full h-full"
className="w-full h-full rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
</span>
</DialogTrigger>
<DialogContent className={`overflow-hidden p-0 rounded-2xl ${isPresence ? 'h-auto w-full' : 'w-full h-[400px] sm:w-[500px] sm:h-[500px]'}`}>
<DialogContent className={cn(
"overflow-hidden p-0 rounded-2xl",
isPresence ? "w-full max-w-screen-3xl h-auto" : "w-full h-[400px] sm:w-[500px] sm:h-[500px]"
)}>
<DialogHeader className='sr-only'>
<DialogTitle>Profile</DialogTitle>
<DialogDescription>Description of profile avatar</DialogDescription>
</DialogHeader>
{/* <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className="w-full h-full shadow-sm rounded-2xl border border-border" /> */}
{/* 2. Logic Switch for Image Mode */}
{isPresence ? (
// MODE A: Presence (Natural Aspect Ratio)
// We use width=0 height=0 + sizes=100vw to emulate "width: 100%, height: auto"
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
width={0}
height={0}
sizes="100vw"
quality={90}
className="w-full h-auto object-contain" // h-auto lets it grow naturally
/>
) : (
// MODE B: Default Profile (Fixed Box with Crop)
// We use fill to cover the specific 500x500 box
<div className="relative w-full h-full">
<Image
src={process.env.BASE_URL_IMG + avatar}
alt="avatar"
fill
className="object-cover shadow-sm border border-border"
sizes="(max-width: 640px) 100vw, 500px"
quality={90}
/>
</div>
)}
{/* 2. DIALOG CONTENT IMAGE
Logic for Presence vs Standard is much simpler now.
Standard CSS handles the width/height.
*/}
<LazyLoadImage
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
effect="blur"
wrapperClassName="w-full h-full block" // Ensures the wrapper fills the dialog
className={cn(
"w-full", // Always full width of container
isPresence ? "h-auto object-contain" : "h-full object-cover shadow-sm border border-border"
)}
/>
</DialogContent>
</Dialog>
:
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image
) : (
// 3. FALLBACK IMAGE
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt='avatar'
src='/assets/no-avatar.jpg'
fill
sizes={sizes}
className='shadow-sm rounded-full object-cover border border-border'
effect="blur"
wrapperClassName="w-full h-full"
className='w-full h-full shadow-sm rounded-full object-cover border border-border'
/>
</div>
}
</span>
)}
</>
);
}
export const Avatar: FC<Props> = ({ avatar, className, sizes = "(max-width: 640px) 36px, 40px" }) => {
export const Avatar: FC<Props> = ({ avatar, className }) => {
return (
<>
{avatar ?
// <img loading='lazy' alt="avatar" src={process.env.BASE_URL_IMG + avatar} className={cn("h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border cursor-pointer hover:scale-110 duration-200", className)} />
<div className={cn("relative h-9 w-9 sm:h-10 sm:w-10", className)}>
<Image src={`${process.env.BASE_URL_IMG}${avatar}`} alt="avatar"
fill // This replaces width/height
sizes={sizes} // Optimization (explained below)
className="rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
{avatar ? (
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
src={`${process.env.BASE_URL_IMG}${avatar}`}
alt="avatar"
effect="blur"
wrapperClassName="w-full h-full"
className="w-full h-full rounded-full object-cover shadow-sm border border-border cursor-pointer hover:scale-110 duration-200"
/>
</div>
:
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/no-avatar.jpg' className={cn('h-9 w-9 sm:h-10 sm:w-10 shadow-sm rounded-full object-cover border border-border', className)} />
}
</span>
) : (
<span className={cn("inline-block h-9 w-9 sm:h-10 sm:w-10", className)}>
<LazyLoadImage
alt='avatar'
src='/assets/no-avatar.jpg'
effect="blur"
wrapperClassName="w-full h-full"
className='w-full h-full shadow-sm rounded-full object-cover border border-border'
/>
</span>
)}
</>
);
}