To achieve the functionality where images can be swiped left and right on smaller screens, and to remove the buttons while maintaining a responsive design, you can implement a carousel library like Swiper. This library is widely used for creating responsive carousels that work well on both desktop and mobile devices.
Here's a modified version of your component that uses Swiper to allow swipe functionality for smaller screens:
First, install Swiper:
npm install swiper
Then, you can update your component to include the Swiper functionality:
import { IoIosArrowDroprightCircle } from "react-icons/io";
import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/swiper-bundle.css';
export default function Products() {
return (
<div className="bg-red-600 w-screen h-screen min-h-screen min-w-screen">
<div className="grid grid-cols-2 md:grid-cols-3 grid-rows-4 gap-0 h-full w-full">
<div className="flex w-full h-full row-span-4 bg-[url('/factory.webp')] bg-no-repeat bg-cover justify-center items-center text-center text-white flex-col gap-20">
<div>
<img src="/royal.webp"></img>
</div>
<div>
<span className="text-4xl font-bold">НАША ПРОДУКЦИЯ</span>
</div>
<div className="w-3/4">
<span>
Мы с нетерпением ждем установления хороших партнерских отношений с
вами и совместного развития для многообещающего будущего!
</span>
</div>
</div>
<Swiper
spaceBetween={0}
slidesPerView={1}
navigation={{
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev'
}}
pagination={{ clickable: true }}
className="row-span-4 md:hidden"
>
{[
{ src: '/metalformingeq.webp', title: 'Оборудование для формовки металла' },
{ src: '/powergen.webp', title: 'Генераторы энергии' },
{ src: '/coldChain.webp', title: 'Холодильные хранилища' },
{ src: '/waterpump.webp', title: 'Водяной насосы' }
].map((item, idx) => (
<SwiperSlide key={idx}>
<div className="relative w-full h-full">
<div className={`w-full h-full bg-[url('${item.src}')] bg-no-repeat bg-cover bg-center`}></div>
<div className="flex absolute bottom-0 w-full h-24 items-center justify-between">
<span className="ml-7 text-xl">{item.title}</span>
<IoIosArrowDroprightCircle size={"3rem"} className="mr-5" />
</div>
</div>
</SwiperSlide>
))}
</Swiper>
{/* Desktop Grid Elements */}
<div className="row-span-2 h-full object-cover hidden md:block">
<div className="relative w-full h-full">
<div className="w-full h-full bg-[url('/metalformingeq.webp')] bg-no-repeat bg-cover bg-center"></div>
<div className="flex absolute bottom-0 w-full h-24 items-center justify-between">
<span className="ml-7 text-xl">
Оборудование для формовки металла
</span>
<IoIosArrowDroprightCircle size={"3rem"} className="mr-5" />
</div>
</div>
</div>
<div className="row-span-2 col-start-1 md:col-start-2 row-start-3 hidden md:block">
<div className="relative w-full h-full">
<div className="w-full h-full bg-[url('/powergen.webp')] bg-no-repeat bg-cover bg-center"></div>
<div className="flex absolute bottom-0 w-full h-24 items-center justify-between">
<span className="ml-7 text-xl">Генераторы энергии</span>
<IoIosArrowDroprightCircle size={"3rem"} className="mr-5" />
</div>
</div>
</div>
<div className="row-span-2 col-start-2 md:col-start-3 row-start-1 hidden md:block">
<div className="relative w-full h-full">
<div className="w-full h-full bg-[url('/coldChain.webp')] bg-no-repeat bg-cover bg-center"></div>
<div className="flex absolute bottom-0 w-full h-24 items-center justify-between">
<span className="ml-7 text-xl">Холодильные хранилища</span>
<IoIosArrowDroprightCircle size={"3rem"} className="mr-5" />
</div>
</div>
</div>
<div className="row-span-2 col-start-2 md:col-start-3 row-start-3 hidden md:block">
<div className="relative w-full h-full">
<div className="w-full h-full bg-[url('/waterpump.webp')] bg-no-repeat bg-cover bg-center"></div>
<div className="flex absolute bottom-0 w-full h-24 items-center justify-between">
<span className="ml-7 text-xl">Водяной насосы</span>
<IoIosArrowDroprightCircle size={"3rem"} className="mr-5" />
</div>
</div>
</div>
</div>
</div>
);
}
In this implementation:
- Swiper: The Swiper component from the
swiper/react library is used to create a carousel.
- SwiperSlide: The SwiperSlide component is used to define each slide.
- Conditional Rendering: The carousel is only shown on small screens (hidden on md and larger) using Tailwind's
hidden and block classes to hide or show elements based on screen size.
- Desktop Grid: The original grid layout is kept for larger screens (hidden on small screens).
This setup ensures that on small screens, users can swipe through the images, while on larger screens, the grid layout is maintained.