To create a popup component with animations based on your provided JSX, you'll need to make sure that your CSS and PopUpItem component are appropriately defined. Here's a step-by-step guide and the components you'll need:
- Ensure You Have the Required CSS Animations and Styles:
Create the necessary CSS animations (
slideInRight and slideOutLeft) and any other styles within your global CSS or a module CSS file.
@keyframes slideInRight {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}
@keyframes slideOutLeft {
from {
transform: translateX(0);
}
to {
transform: translateX(-100%);
}
}
.animate-slideInRight {
animation: slideInRight 0.5s forwards;
}
.animate-slideOutLeft {
animation: slideOutLeft 0.5s forwards;
}
- Create the
PopUpItem Component:
Define the PopUpItem component to be reused within the popup.
const PopUpItem = () => {
return (
<div className="p-4 border-b">
{/* Add your content here */}
PopUp Item Content
</div>
);
};
- Create the Main Popup Component:
Use the JSX you provided and make sure to pass the necessary props like
isScrolled and clickAnime.
import React, { useState, useEffect } from 'react';
import './styles.css'; // Make sure this contains your CSS for animations
const PopupComponent = ({ isScrolled, clickAnime }) => {
return (
<div
className={`fixed right-0 z-50 w-96 h-4/5 bg-white shadow-2xl border-l-4 border-[#0e7fdf] border-b-4 flex flex-col ${
isScrolled ? 'top-10 duration-500 ease-out' : 'inset-y-24 duration-500 ease-out'
} ${clickAnime === 'left' ? 'animate-slideOutLeft' : 'animate-slideInRight'}`}
>
<div className="h-5/6 flex flex-col">
<PopUpItem />
<PopUpItem />
<PopUpItem />
</div>
<div className="flex mt-auto w-full h-16 justify-center items-center">
<div className="flex bg-[#0e7fdf] w-3/4 h-14 justify-center items-center">
<a href="#" className="text-2xl text-white">
Оплатить
</a>
</div>
</div>
</div>
);
};
export default PopupComponent;
- Use the Popup Component:
Finally, use the
PopupComponent in your application, ensuring to pass the necessary state variables (isScrolled and clickAnime).
import React, { useState } from 'react';
import PopupComponent from './PopupComponent';
const App = () => {
const [isScrolled, setIsScrolled] = useState(false);
const [clickAnime, setClickAnime] = useState('right');
return (
<div>
{/* Button to toggle the popup for demonstration */}
<button onClick={() => setClickAnime(clickAnime === 'right' ? 'left' : 'right')}>
Toggle Popup Animation
</button>
<PopupComponent isScrolled={isScrolled} clickAnime={clickAnime} />
</div>
);
};
export default App;
Remember to adjust any class names and styles to fit your design requirements. This setup provides a good starting point for creating an animated popup component in React with Tailwind CSS.