Animated Testimonials

Ananya Gupta
Sophia Allen
Ethan Rodriguez
Priya Sharma

Ananya Gupta

Frontend Engineer, NovaTech

Spectrum UI is a game-changer! Its components are so well-designed and customizable that it made our app look polished and professional in no time. 

Installation

Create a new file called ImagePreview.tsx in the components

1

Install the package if you do not have it.

npm i lucide-react framer-motion 
2

Copy and paste the following code into your project.

"use client";

import  React, { useState } from "react";
import Image from "next/image";
import { X } from "lucide-react";

import * as DialogPrimitive from "@radix-ui/react-dialog";

interface ImagePreviewProps {
  src: string;
  alt?: string;
  width: number;
  height: number;
  className?: string;
}

export default function ImagePreview({
  src = "https://images.pexels.com/photos/1054218/pexels-photo-1054218.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
  alt = "Preview image",
  width = 400,
  height = 400,
  className = "cursor-pointer rounded-lg hover:opacity-90 transition-opacity",
}: ImagePreviewProps) {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <>
      <Image
        src={src}
        alt={alt}
        width={width}
        height={height}
        className={className}
        onClick={() => setIsOpen(true)}
      />

      <DialogPrimitive.Root open={isOpen} onOpenChange={setIsOpen}>
        <DialogPrimitive.Portal>
          <DialogPrimitive.Overlay className="fixed inset-0 bg-black/50 backdrop-blur-sm" />
          <DialogPrimitive.Content className="fixed left-[50%] top-[50%] translate-x-[-50%] translate-y-[-50%] max-w-[90vw] max-h-[90vh] w-auto h-auto p-0 bg-transparent border-0">
            <button
              onClick={() => setIsOpen(false)}
              className="absolute right-4 top-4 z-10 rounded-full bg-black/50 p-2 text-white hover:bg-black/75 focus:outline-none"
            >
              <X className="h-6 w-6" />
              <span className="sr-only">Close</span>
            </button>
            <div className="relative w-full h-full">
              <Image
                src={src}
                alt={alt}
                width={width * 2}
                height={height * 2}
                className="object-contain"
              />
            </div>
          </DialogPrimitive.Content>
        </DialogPrimitive.Portal>
      </DialogPrimitive.Root>
    </>
  );
}
3

Create feedback component & paste the code

Credits

This component is inspired by Aceternity UI ❤️