Okay, let's break down how to implement this animation in your Next.js project using a Figma design. Since you haven't provided the Figma design itself, I'll describe the steps and considerations based on the provided CSS and animation details.
Understanding the Animation
The provided code defines a circular loading animation with the following characteristics:
Shape: A circle.
Color: A gradient transitioning between a light blue/purple and a darker blue.
Rotation: It spins continuously.
Duration: One full rotation takes 1 second.
Delay: There's a 1ms delay before the animation starts (though this is often negligible).
Implementation Steps in Next.js
Here's how you can integrate this into your Next.js project:
1. Create the Loader.tsx Component:
Create a file named Loader.tsx (or any other name you prefer) in your components directory (or wherever you organize your components). Paste the following code into it:
We create a functional React component called Loader.
The div element is styled with:
w-[22px] h-[22px]: Sets the width and height of the loader.
rounded-full: Makes it a perfect circle.
animate-spin-custom: Applies the custom spin animation.
style: We directly apply the background, clipPath, and WebkitMask styles to achieve the conic gradient and radial gradient effect.
2. Define the spin-custom Keyframes:
You've already provided the @keyframes spin-custom definition. This is correctly placed within the Loader.tsx component:
tsx
@keyframes spin-custom {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
3. Define the animate-spin-custom Class:
Similarly, the animate-spin-custom class is defined within the Loader.tsx component:
tsx
.animate-spin-custom {
animation: spin-custom 1s linear infinite;
}
4. Using the Loader Component in Your Next.js Pages/Components:
Now you can import and use the Loader component in any of your Next.js pages or other components where you want to display the loading animation.
Example in a Page (pages/index.tsx):
tsx
import React from "react";
import Loader from "@/components/Loader"; // Adjust the path if needed
const HomePage: React.FC = () => {
return (
<div>
<h1>My Awesome Page</h1>
<Loader /> {/* Render the loading animation */}
{/* Your page content goes here */}
</div>
);
};
export default HomePage;
Integrating with Figma Design
To ensure the animation matches your Figma design, you need to consider the following:
Shape: The rounded-full class in the CSS ensures a circular shape. If your Figma design has a different shape, you'll need to adjust the CSS accordingly (e.g., using border-radius).
Color: The conic-gradient and radial-gradient in the CSS define the color transition. Make sure these colors match your Figma design.
Size: The w-[22px] h-[22px] class controls the size. Adjust these values to match the size in your Figma design.
Animation Duration and Timing: The animation-duration: 1s and animation-timing-function: linear in the CSS control the speed and smoothness of the rotation. If your Figma design has a different animation speed, adjust these values.
Delay: The animation-delay: 1ms is a small delay. If your Figma design has a noticeable delay, you can adjust this value.
Important Considerations for Next.js:
CSS Modules/Global Styles: You can choose to use CSS Modules or global styles in your Next.js project. The provided code uses standard CSS within the component's style attribute. You could also extract the styles into a separate CSS file and import it into your component.
Tailwind CSS: If you're using Tailwind CSS, you can leverage its utility classes for styling. You could potentially achieve a similar effect using Tailwind's rounded-full, w-, h-, and animate-spin classes, although the specific conic and radial gradients might require custom CSS.
Performance: For very complex animations, consider using CSS transforms for better performance. However, for this relatively simple animation, the current approach should be fine.
To get a more precise implementation, please share your Figma design. I can then provide more tailored CSS and guidance.