From f2fd774dc478613a07aa3f9298bc2d4743b5dca3 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sun, 14 Jun 2026 12:12:58 +0330 Subject: [PATCH] color icon --- .../(Main)/components/CategoryScroll.tsx | 105 +++++++++++++++--- .../listview/CategorySmallItemRenderer.tsx | 11 +- 2 files changed, 98 insertions(+), 18 deletions(-) diff --git a/src/app/[name]/(Main)/components/CategoryScroll.tsx b/src/app/[name]/(Main)/components/CategoryScroll.tsx index 48e9624..63012b1 100644 --- a/src/app/[name]/(Main)/components/CategoryScroll.tsx +++ b/src/app/[name]/(Main)/components/CategoryScroll.tsx @@ -1,11 +1,70 @@ -'use client'; +"use client"; -import Image from "next/image"; -import clsx from "clsx"; -import HorizontalScrollView from "@/components/listview/HorizontalScrollView"; +import { Category } from "@/app/[name]/(Main)/types/Types"; import CategoryItemRenderer from "@/components/listview/CategoryItemRenderer"; import CategorySmallItemRenderer from "@/components/listview/CategorySmallItemRenderer"; -import { Category } from "@/app/[name]/(Main)/types/Types"; +import HorizontalScrollView from "@/components/listview/HorizontalScrollView"; +import clsx from "clsx"; +import { usePathname } from "next/navigation"; + +/** TODO: remove when backend sends avatarRenderMode */ +const COLORED_SVG_RESTAURANT_SLUGS = new Set(["havasone"]); + +const SVG_MASK_STYLE = { + maskSize: "contain", + maskRepeat: "no-repeat", + maskPosition: "center", + WebkitMaskSize: "contain", + WebkitMaskRepeat: "no-repeat", + WebkitMaskPosition: "center", +} as const; + +function CategoryImage({ + src, + size, + alt, + tintWithPrimary = true, +}: { + src: string; + size: number; + alt: string; + tintWithPrimary?: boolean; +}) { + const isSvg = src.endsWith(".svg"); + const shouldUseSvgMask = isSvg && tintWithPrimary; + + if (shouldUseSvgMask) { + return ( +
+ ); + } + + return ( + // eslint-disable-next-line @next/next/no-img-element + {alt} { + event.currentTarget.src = "/assets/images/food-image.png"; + }} + /> + ); +} type Variant = "large" | "small"; @@ -41,6 +100,10 @@ const CategoryScroll = ({ variant = "large", className, }: Props) => { + const segment = usePathname()?.split("/").filter(Boolean)[0]; + const usesColoredSvg = + segment != null && + COLORED_SVG_RESTAURANT_SLUGS.has(segment.toLowerCase()); const { renderer: Renderer, imageSize } = variantConfig[variant]; const selectedParent = categories.find((c) => c.id === selectedCategory) ?? @@ -53,9 +116,10 @@ const CategoryScroll = ({
0 ? "pt-4! pb-1!" : "py-4!", variant === "large" && "mt-4!", - className + className, )} > {categories.map((item) => { @@ -69,14 +133,15 @@ const CategoryScroll = ({ className={clsx(isSelected && "bg-container!")} onClick={handleSelect(item.id)} > - category image - {item.title} + + {item.title} + ); })} @@ -86,7 +151,7 @@ const CategoryScroll = ({ {children.map((child) => { @@ -95,10 +160,21 @@ const CategoryScroll = ({ return ( - {child.title} + {child.avatarUrl && ( + + )} + + {child.title} + ); })} @@ -109,4 +185,3 @@ const CategoryScroll = ({ }; export default CategoryScroll; - diff --git a/src/components/listview/CategorySmallItemRenderer.tsx b/src/components/listview/CategorySmallItemRenderer.tsx index afe9a51..a34411a 100644 --- a/src/components/listview/CategorySmallItemRenderer.tsx +++ b/src/components/listview/CategorySmallItemRenderer.tsx @@ -4,14 +4,19 @@ import React from 'react'; type Props = { children: React.ReactNode; + compact?: boolean; } & React.HTMLAttributes; -function CategorySmallItemRenderer({ children, ...rest }: Props) { +function CategorySmallItemRenderer({ children, compact = false, className, ...rest }: Props) { return ( -
+
{children}