Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scroll infinite #232

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
.animate-carousel {
animation: carousel var(--duration) linear infinite;
white-space: nowrap;
}
}
133 changes: 104 additions & 29 deletions src/components/containerCards/containerCardsBrands.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,142 @@
'use client';
import { Carousel } from '../carousels/carousel';
import BrandCard from '../cards/brandCard';
import Link from 'next/link';
import { useBrandStore } from '../../store/productStore';
import React from 'react';
import Image from 'next/image';

const imagesBrands = [
const ContainerCardsBrands: React.FC = () => {
const setSelectedBrand = useBrandStore((state) => state.setSelectedBrand);
const imagesBrands = [
{
name: 'Ford',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/ford-logo.webp",
},
{
name: 'Mazda',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/mazda-logo.webp",
},
{
name: 'Toyota',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/toyota-logo.webp",
},
{
name: 'Honda',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/honda-logo.webp",
},
{
name: 'Nissan',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/nissan-logo.webp",
},
{
name: 'Chevrolet',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/chevrolet-logo.webp",
},
{
name: 'Volkswagen',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/volkswagen-logo.webp",
},
{
name: 'Mercedes Benz',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/mercedes-benz-logo.webp",
},
{
name: 'BMW',
image:
'https://user-images.githubusercontent.com/124757365/266650645-7b118906-6a8d-4c07-84be-b6ad1e7f3e7a.png',
image: "/images/brands/bmw-logo.webp",
},
{
name: 'Ferrari',
image: "/images/brands/ferrari-logo.webp",
},
{
name: 'Lexus',
image: "/images/brands/lexus-logo.webp",
},
{
name: 'Mini',
image: "/images/brands/mini-logo.webp",
},
{
name: 'Audi',
image: "/images/brands/audi-logo.webp",
},
{
name: 'Jeep',
image: "/images/brands/jeep-logo.webp",
},
{
name: 'Lamborghini',
image: "/images/brands/lamborghini-logo.webp",
},
{
name: 'KIA',
image: "/images/brands/kia-logo.webp",
},
{
name: 'Land Rover',
image: "/images/brands/land-rover-logo.webp",
},
{
name: 'Porsche',
image: "/images/brands/porsche-logo.webp",
},
{
name: 'Subaru',
image: "/images/brands/subaru-logo.webp",
},
{
name: 'Tesla',
image: "/images/brands/tesla-logo.webp",
},
{
name: 'Volvo',
image: "/images/brands/volvo-logo.webp",
},
{
name: 'RAM',
image: "/images/brands/ram-logo.webp",
},
{
name: 'Hyundai',
image: "/images/brands/hyundai-logo.webp",
},
{
name: 'Mitsubishi',
image: "/images/brands/mitsubishi-logo.webp",
},
];

const ContainerCardsBrands: React.FC = () => {
return (
<div className=" flex flex-col items-center justify-between bg-[#13131D] mb-9 ">
<div className=" w-full max-w-f-hd bg-black py-9">
<Carousel items={9} auto={true}>
{imagesBrands.map((brand, index) => (
<BrandCard key={index} imageSrc={brand.image} title={brand.name} />
))}
</Carousel>
const handleClick = (brandName: string) => {
setSelectedBrand(brandName);
};

return (
<div className="flex flex-col items-center justify-between mb-24 w-full inline-flex flex-nowrap overflow-hidden">
<div className="w-full max-w-f-hd py-9">
<Carousel items={9} auto={true}>
{imagesBrands.map((brand, index) => (
<div
key={index}
onClick={() => handleClick(brand.name)}
className="slider-infinite-scroll autoplay brand-link relative block w-32 h-32 sm:w-40 sm:h-40 m-1"
aria-hidden="true"
>
<Link href={`/products?brand=${brand.name}`} key={index}>
<Image
src={brand.image}
alt={brand.name}
className="brand-image items-center justify-between object-contain w-full h-full m-0 max-h-[100px] max-w-[100px] hover:scale-110 hover:stop-autoplay"
width={300}
height={300}
/>
</Link>
</div>
))}
</Carousel>
</div>
</div>
);
};

export default ContainerCardsBrands;
export default ContainerCardsBrands;
21 changes: 19 additions & 2 deletions src/store/productStore.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
/* eslint-disable no-unused-vars */
import { create } from 'zustand';
import { ProductsProps } from '~/types/products';
import { Brand, ProductsProps } from '~/types/products';
import { Body } from '~/types/products';

interface ProductStore {
products: ProductsProps[];
body: Body;
// eslint-disable-next-line no-unused-vars
brands: Brand[];
pages: number;
updateProducts: (data: ProductsProps[]) => void;
updateBody: (option: string, value: string | number) => void;
resetBody: () => void;
setPages: (value: number) => void;
}

type BrandStore = {
selectedBrand: string;
setSelectedBrand: (brand: string) => void;
};

export const useBrandStore = create<BrandStore>((set) => ({
selectedBrand: '',
setSelectedBrand: (brand) => set(() => ({ selectedBrand: brand })),
}));

export const useProductStore = create<ProductStore>((set) => ({
products: [],
body: {
Expand All @@ -25,6 +36,7 @@ export const useProductStore = create<ProductStore>((set) => ({
name: '',
},
pages: 0,
brands: [],
updateProducts: (data: ProductsProps[]) =>
set(() => ({
products: data,
Expand Down Expand Up @@ -53,4 +65,9 @@ export const useProductStore = create<ProductStore>((set) => ({
pages: value,
}));
},
}));
setBrands: (value: Brand[]) => {
set(() => ({
brands: value,
}));
},
}));
15 changes: 14 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,20 @@ module.exports = {
gap: {
50: '50px',
},
animation: {
'slider-infinite-scroll': 'infinite-scroll 2s linear infinite',
},
keyframes: {
'slider-infinite-scroll': {
from: {
transform: 'translateX(0)',
},
to: {
transform: 'translateX(-100%)',
},
},
},
plugins: [],
},
plugins: [],
},
};