blob: 5e9934c3aa97d7234068ff54389e5d022fcd2cfe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
import Image from "next/image";
import Link from 'next/link';
import { createSlug } from '@/core/utils/slug';
import useDevice from '@/core/hooks/useDevice';
import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/css';
import { useQuery } from 'react-query';
import { useRouter } from 'next/router';
import {
ChevronDownIcon,
ChevronUpIcon, // Import ChevronUpIcon for toggling
DocumentCheckIcon,
HeartIcon,
} from '@heroicons/react/24/outline';
import { useState } from 'react'; // Import useState
import { getIdFromSlug } from '@/core/utils/slug'
const LobSectionCategory = ({ categories }) => {
const { isDesktop, isMobile } = useDevice();
const [isOpenCategory, setIsOpenCategory] = useState(false); // State to manage category visibility
const handleToggleCategories = () => {
setIsOpenCategory(!isOpenCategory);
};
console.log("categories",categories[0]?.categoryIds)
const displayedCategories = categories[0]?.categoryIds;
return (
<section>
{isDesktop && (
<div className="group/item grid grid-flow-col gap-y-2 gap-x-2 w-full h-full">
{displayedCategories?.map((category) => (
<Link href={createSlug('/shop/category/', category?.name, category?.id)} key={category?.id} passHref>
<div className="group transition-colors duration-300 ">
<div className="KartuInti h-36 w-26 max-w-sm lg:max-w-full flex flex-col border-[2px] border-gray-200 group-hover:border-red-400 rounded relative ">
<div className="flex items-center justify-start h-full px-1 flex-row ">
<Image className="h-full w-full" src={category?.image ? category?.image : 'https://erp.indoteknik.com/web/image?model=x_banner.banner&id=5&field=x_banner_image&unique=09202023100557'} width={56} height={48} quality={100} alt={category?.name} />
{/* <h2 className="text-gray-700 group-hover:text-[#E20613] line-clamp-2 content-center h-fit w-60 px-1 font-semibold text-sm text-start">{category?.name}</h2> */}
</div>
</div>
</div>
</Link>
))}
</div>
)}
{isMobile && (
<div className="py-4">
<Swiper slidesPerView={2.3} spaceBetween={10}>
{displayedCategories.map((category) => (
<SwiperSlide key={category?.id}>
<Link href={createSlug('/shop/category/', category?.name, category?.id)} passHref>
<div className="group transition-colors duration-300">
<div className="KartuInti min-h-16 max-h-16 w-26 max-w-sm lg:max-w-full flex flex-col border-[2px] border-gray-200 group-hover:bg-red-200 group-hover:border-red-400 rounded relative">
<div className="flex items-center justify-center h-full px-1 flex-row">
<Image
src={category?.image1920 ? category?.image1920 : '/images/noimage.jpeg'}
width={56}
height={48}
alt={category?.name}
/>
<h2 className="text-gray-700 group-hover:text-[#E20613] line-clamp-2 content-center h-fit w-60 px-1 font-semibold text-sm text-start">
{category?.name}
</h2>
</div>
</div>
</div>
</Link>
</SwiperSlide>
))}
</Swiper>
{categories.length > 10 && (
<div className="w-full flex justify-end mt-4">
<button
onClick={handleToggleCategories}
className="flex justify-end mt-4 bg-red-500 text-white text-sm px-4 py-2 rounded"
>
{isOpenCategory ? 'Sembunyikan Semua' : 'Lihat Semua'}
</button>
</div>
)}
</div>
)}
</section>
)
}
export default LobSectionCategory
|