feat(mobile): optimize mobile brands carousel, peek category swipe, and touch product cards

This commit is contained in:
iFixKart Dev 2026-11-16 23:21:46 +05:30
parent 801b580bd5
commit ac3590d30a
4 changed files with 31 additions and 20 deletions

View file

@ -302,10 +302,10 @@ export const ProductCard: React.FC<ProductCardProps> = ({
<div
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
className="bg-white p-4 md:p-5 flex flex-col relative font-sans group/card h-full min-h-[380px]"
className="bg-white p-3 sm:p-4 md:p-5 flex flex-col relative font-sans group/card h-full min-h-[330px] sm:min-h-[380px]"
>
{/* Badges — top right */}
<div className="absolute top-3 right-3 z-10 flex flex-col items-end gap-1">
<div className="absolute top-2.5 right-2.5 sm:top-3 sm:right-3 z-10 flex flex-col items-end gap-1">
{isOutOfStock ? (
<span className="bg-[#222] text-white text-[10px] font-bold px-1.5 py-0.5 leading-none uppercase tracking-wide">
Out of Stock
@ -318,12 +318,12 @@ export const ProductCard: React.FC<ProductCardProps> = ({
) : null}
</div>
{/* Hover actions — top left */}
{/* Hover actions — top left (always visible on touch/mobile, hover on desktop) */}
<div
className={`absolute left-3 top-3 z-20 flex flex-col gap-2 transition-all duration-200 ${
className={`absolute left-2.5 top-2.5 sm:left-3 sm:top-3 z-20 flex flex-col gap-1.5 sm:gap-2 transition-all duration-200 ${
isHovered
? 'opacity-100 translate-y-0'
: 'opacity-0 -translate-y-1 pointer-events-none'
: 'opacity-100 sm:opacity-0 sm:-translate-y-1 pointer-events-auto sm:pointer-events-none'
}`}
>
<button
@ -342,7 +342,7 @@ export const ProductCard: React.FC<ProductCardProps> = ({
<button
type="button"
onClick={handleCompareClick}
className={`${iconBtn} ${isCompared ? '!bg-primary !text-white' : ''}`}
className={`hidden sm:flex ${iconBtn} ${isCompared ? '!bg-primary !text-white' : ''}`}
title="Compare"
aria-label="Compare product"
>
@ -351,7 +351,7 @@ export const ProductCard: React.FC<ProductCardProps> = ({
<button
type="button"
onClick={handleQuickViewClick}
className={iconBtn}
className={`hidden sm:flex ${iconBtn}`}
title="Quick View"
aria-label="Quick view"
>
@ -360,7 +360,7 @@ export const ProductCard: React.FC<ProductCardProps> = ({
</div>
<Link href={href} className="flex flex-col items-center flex-1 select-none">
<div className="relative w-full h-[150px] flex items-center justify-center mb-1">
<div className="relative w-full h-[125px] sm:h-[150px] flex items-center justify-center mb-1">
{mainImageUrl ? (
<>
<BlurHashImage

View file

@ -24,11 +24,19 @@ interface BrandsSectionProps {
}
function toBrandItem(b: any, idx: number): BrandItem {
const rawLogo = b.logo_url || b.logo || b.image;
const isPlaceholder =
!rawLogo ||
rawLogo === 'null' ||
rawLogo === 'undefined' ||
String(rawLogo).includes('placeholder') ||
String(rawLogo).trim() === '';
return {
id: String(b.brand_id || b.id || b.slug || idx),
name: b.name || 'Brand',
slug: b.slug || String(b.brand_id || b.id || idx),
logo: getImageUrl(b.logo_url || b.logo || b.image) || undefined,
logo: isPlaceholder ? undefined : (getImageUrl(rawLogo) || undefined),
fontClass: FALLBACK_FONT,
};
}
@ -100,32 +108,35 @@ export const BrandsSection: React.FC<BrandsSectionProps> = ({
</div>
{loading ? (
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 gap-3 md:gap-4">
<div className="flex md:grid md:grid-cols-5 gap-3 overflow-x-auto no-scrollbar py-1 snap-x">
{Array.from({ length: 10 }).map((_, i) => (
<BrandTileSkeleton key={i} />
<div
key={i}
className="snap-start shrink-0 min-w-[130px] sm:min-w-[150px] md:min-w-0 md:w-auto h-[54px] md:h-[80px] rounded-xl bg-gray-100 animate-pulse"
/>
))}
</div>
) : (
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 gap-3 md:gap-4">
<div className="flex md:grid md:grid-cols-5 gap-3 overflow-x-auto no-scrollbar py-1 snap-x">
{brands.map((brand) => (
<Link
key={brand.id}
href={`/shop?brand=${encodeURIComponent(brand.slug)}`}
className="group flex items-center justify-center h-[72px] md:h-[80px] px-4 rounded-lg bg-[#F3F3F3] hover:bg-[#ebebeb] transition-colors"
className="group snap-start shrink-0 min-w-[130px] sm:min-w-[150px] md:min-w-0 md:w-auto flex items-center justify-center h-[54px] md:h-[80px] px-4 rounded-xl bg-white md:bg-[#F3F3F3] border border-gray-200 md:border-transparent hover:border-primary/40 hover:bg-[#ebebeb] shadow-2xs md:shadow-none hover:shadow-sm transition-all"
>
{brand.logo ? (
<img
src={brand.logo}
alt={brand.name}
className="max-h-[36px] md:max-h-[40px] max-w-[70%] object-contain opacity-70 group-hover:opacity-100 transition-opacity"
className="max-h-[36px] md:max-h-[40px] max-w-[70%] object-contain opacity-75 group-hover:opacity-100 transition-opacity"
style={{
filter: 'grayscale(1) contrast(0.85) brightness(0.55)',
}}
/>
) : (
<span
className={`select-none text-[#555] group-hover:text-[#222] transition-colors ${
brand.fontClass || 'font-bold text-[15px]'
className={`select-none text-[#333] group-hover:text-primary transition-colors text-center ${
brand.fontClass || 'font-bold text-[14px] md:text-[15px]'
}`}
>
{brand.name}

View file

@ -280,10 +280,10 @@ export const CategoriesSection: React.FC<CategoriesSectionProps> = ({
nextEl: '.cat-swiper-next',
}}
watchOverflow
spaceBetween={18}
slidesPerView={2}
spaceBetween={14}
slidesPerView={2.3}
breakpoints={{
480: { slidesPerView: 3, spaceBetween: 18 },
480: { slidesPerView: 3, spaceBetween: 16 },
768: { slidesPerView: 4, spaceBetween: 20 },
1024: { slidesPerView: 5, spaceBetween: 22 },
1280: { slidesPerView: 6, spaceBetween: 24 },

View file

@ -216,7 +216,7 @@ export const UltimateTechSection: React.FC<UltimateTechSectionProps> = ({
idx < 2 ? 'border-b md:border-b-0' : '',
].join(' ')}
>
<ProductCard product={product} products={techGadgets} />
<ProductCard product={product} products={techGadgets} variant="techshop" />
</div>
))}
</div>