|
1 |
| -import { GridTileImage } from 'components/grid/tile'; |
2 |
| -import { getCollectionProducts } from 'lib/shopify'; |
3 |
| -import type { Product } from 'lib/shopify/types'; |
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { ArrowLongLeftIcon, ArrowLongRightIcon, ArrowRightIcon } from '@heroicons/react/24/outline'; |
| 4 | +import UnderlineLink from 'components/ctas/underline'; |
| 5 | +import Price from 'components/price'; |
| 6 | +import { Product } from 'lib/shopify/types'; |
| 7 | +import Image from 'next/image'; |
4 | 8 | import Link from 'next/link';
|
| 9 | +import 'swiper/css'; |
| 10 | +import 'swiper/css/a11y'; |
| 11 | +import 'swiper/css/navigation'; |
| 12 | +import { A11y, Navigation } from 'swiper/modules'; |
| 13 | +import { Swiper, SwiperSlide } from 'swiper/react'; |
5 | 14 |
|
6 |
| -function Item({ |
7 |
| - item, |
8 |
| - size, |
9 |
| - priority |
10 |
| -}: { |
11 |
| - item: Product; |
12 |
| - size: 'full' | 'half'; |
13 |
| - priority?: boolean; |
14 |
| -}) { |
| 15 | +export default function FeaturedItems({ products }: { products: Product[] }) { |
15 | 16 | return (
|
16 |
| - <div |
17 |
| - className={size === 'full' ? 'md:col-span-4 md:row-span-2' : 'md:col-span-2 md:row-span-1'} |
18 |
| - > |
19 |
| - <Link |
20 |
| - className="relative block aspect-square h-full w-full" |
21 |
| - href={`/product/${item.handle}`} |
22 |
| - prefetch={true} |
23 |
| - > |
24 |
| - <GridTileImage |
25 |
| - src={item.featuredImage.url} |
26 |
| - fill |
27 |
| - sizes={ |
28 |
| - size === 'full' ? '(min-width: 768px) 66vw, 100vw' : '(min-width: 768px) 33vw, 100vw' |
| 17 | + <> |
| 18 | + <div className="flex flex-col items-center justify-between pb-4 md:flex-row md:pb-8"> |
| 19 | + <h2 className="font-oswald text-3xl font-semibold uppercase text-452-blue-light md:text-5xl"> |
| 20 | + Lo más vendido |
| 21 | + </h2> |
| 22 | + <UnderlineLink href="search/" className="text-xl uppercase text-452-blue-light"> |
| 23 | + Ver Todo <ArrowRightIcon className="relative -top-[2px] ml-2 inline-block w-6" /> |
| 24 | + </UnderlineLink> |
| 25 | + </div> |
| 26 | + <Swiper |
| 27 | + className="swiper-container-borders" |
| 28 | + modules={[Navigation, A11y]} |
| 29 | + spaceBetween={20} |
| 30 | + watchSlidesProgress |
| 31 | + slidesPerView={1.25} |
| 32 | + breakpoints={{ |
| 33 | + 640: { |
| 34 | + slidesPerView: 2.25 |
| 35 | + }, |
| 36 | + 768: { |
| 37 | + slidesPerView: 3.35 |
| 38 | + }, |
| 39 | + 1024: { |
| 40 | + slidesPerView: 4 |
29 | 41 | }
|
30 |
| - priority={priority} |
31 |
| - alt={item.title} |
32 |
| - label={{ |
33 |
| - position: size === 'full' ? 'center' : 'bottom', |
34 |
| - title: item.title as string, |
35 |
| - amount: item.priceRange.maxVariantPrice.amount, |
36 |
| - currencyCode: item.priceRange.maxVariantPrice.currencyCode |
37 |
| - }} |
38 |
| - /> |
39 |
| - </Link> |
40 |
| - </div> |
41 |
| - ); |
42 |
| -} |
43 |
| - |
44 |
| -const FeaturedItems = async () => { |
45 |
| - const homepageItems = await getCollectionProducts({ |
46 |
| - collection: 'hidden-homepage-featured-items' |
47 |
| - }); |
48 |
| - |
49 |
| - if (!homepageItems[0] || !homepageItems[1] || !homepageItems[2]) return null; |
50 |
| - |
51 |
| - const [firstProduct, secondProduct, thirdProduct] = homepageItems; |
52 |
| - |
53 |
| - const menu = Array.from({ length: 3 }, (_, index) => ({ |
54 |
| - id: index + 1, |
55 |
| - name: `Linea ${index + 1}`, |
56 |
| - link: `linea/${index + 1}` |
57 |
| - })); |
58 |
| - return ( |
59 |
| - <section className="container flex flex-col gap-4 py-4 md:gap-6 md:py-9"> |
60 |
| - <div className="menu-container mb-6 flex flex-row flex-wrap items-center justify-center gap-4 md:gap-8"> |
61 |
| - {menu.map((item) => ( |
62 |
| - <Link |
63 |
| - key={item.id} |
64 |
| - href={item.link} |
65 |
| - className="text-base text-f-orange hover:text-f-orange/80" |
66 |
| - > |
67 |
| - {item.name} |
68 |
| - </Link> |
| 42 | + }} |
| 43 | + navigation={{ |
| 44 | + nextEl: '.custom-button-next', |
| 45 | + prevEl: '.custom-button-prev' |
| 46 | + }} |
| 47 | + > |
| 48 | + {products.map((product) => ( |
| 49 | + <SwiperSlide className="border-x-2 border-452-blue-light" key={product.handle}> |
| 50 | + <Link className="block" href={`/product/${product.handle}`} prefetch={true}> |
| 51 | + <div className="relative aspect-square"> |
| 52 | + <Image |
| 53 | + className="object-cover" |
| 54 | + src={product.featuredImage.url} |
| 55 | + fill |
| 56 | + sizes={ |
| 57 | + '(min-width: 1024px) 25vw, (min-width: 768px) 33.333vw, (min-width: 640px) 50vw, 100vw' |
| 58 | + } |
| 59 | + priority={true} |
| 60 | + alt={product.title} |
| 61 | + /> |
| 62 | + </div> |
| 63 | + <div className="flex min-h-[10rem] flex-col gap-4 p-4 font-oswald text-base text-452-blue-light md:min-h-[15rem] md:gap-6 lg:text-2xl"> |
| 64 | + <h3 className="truncate leading-none tracking-wide">{product.title}</h3> |
| 65 | + <Price |
| 66 | + className="flex-none font-chakra" |
| 67 | + amount={product.priceRange.maxVariantPrice.amount} |
| 68 | + currencyCode={product.priceRange.maxVariantPrice.currencyCode} |
| 69 | + currencyCodeClassName="hidden @[275px]/label:inline" |
| 70 | + /> |
| 71 | + </div> |
| 72 | + </Link> |
| 73 | + </SwiperSlide> |
69 | 74 | ))}
|
70 |
| - </div> |
71 |
| - <section className="grid max-w-screen-2xl gap-4 pb-4 md:grid-cols-6 md:grid-rows-2 xl:max-h-[calc(100vh-200px)]"> |
72 |
| - <Item size="full" item={firstProduct} priority={true} /> |
73 |
| - <Item size="half" item={secondProduct} priority={true} /> |
74 |
| - <Item size="half" item={thirdProduct} /> |
75 |
| - </section> |
76 |
| - </section> |
| 75 | + <div |
| 76 | + className="absolute bottom-0 z-10 flex w-full flex-row justify-between border-y-2 border-452-blue-light py-2" |
| 77 | + slot="container-end" |
| 78 | + > |
| 79 | + <button className="custom-button-prev ml-2 text-452-blue-light disabled:opacity-50 md:ml-4"> |
| 80 | + <ArrowLongLeftIcon className="w-10" /> |
| 81 | + </button> |
| 82 | + <button className="custom-button-next mr-2 text-452-blue-light disabled:opacity-50 md:mr-4"> |
| 83 | + <ArrowLongRightIcon className="w-10" /> |
| 84 | + </button> |
| 85 | + </div> |
| 86 | + </Swiper> |
| 87 | + </> |
77 | 88 | );
|
78 |
| -}; |
79 |
| - |
80 |
| -export default FeaturedItems; |
| 89 | +} |
0 commit comments