cg / hackerproducts
63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.
Quick jump: page.tsxpage.tsxglobals.cssschema.sqlpackage.json
root / src / components / ProductIcon.tsx
src/components/ProductIcon.tsx · 36 lines · 604 B← back to folder
| 1 | import { getFallbackIconColor } from "@/lib/format"; |
| 2 | |
| 3 | export function ProductIcon({ |
| 4 | name, |
| 5 | iconUrl, |
| 6 | }: { |
| 7 | name: string; |
| 8 | iconUrl: string | null; |
| 9 | }) { |
| 10 | if (iconUrl) { |
| 11 | return ( |
| 12 | <img |
| 13 | src={iconUrl} |
| 14 | alt="" |
| 15 | width={24} |
| 16 | height={24} |
| 17 | className="product-icon" |
| 18 | loading="lazy" |
| 19 | /> |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | const initial = (name.trim()[0] || "?").toUpperCase(); |
| 24 | const bg = getFallbackIconColor(name); |
| 25 | |
| 26 | return ( |
| 27 | <span |
| 28 | className="product-icon" |
| 29 | style={{ backgroundColor: bg }} |
| 30 | aria-hidden="true" |
| 31 | > |
| 32 | {initial} |
| 33 | </span> |
| 34 | ); |
| 35 | } |
| 36 |