import { Image } from '@components/common/Image.js'; import { ProductNoThumbnail } from '@components/common/ProductNoThumbnail.js'; import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from '@components/common/ui/Card.js'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@components/common/ui/Table.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import React from 'react'; interface BestSellersProps { bestSellers: Array<{ name: string; price: { regular: { value: number; text: string; }; }; soldQty: number; image?: { url?: string; }; editUrl?: string; }>; listUrl: string; } export default function BestSellers({ bestSellers, listUrl }: BestSellersProps) { return ( {_('Best Sellers')} {_('A list of best selling products')} {_('View All Products')} {/* `table-fixed` is load-bearing: with the default auto layout a long product name widens the table past the card and pushes the Price / Sold columns out of view entirely. Fixed layout pins the numeric columns and lets the name column absorb the remaining width, where `line-clamp-2` caps it at two lines. */} {_('Product')} {_('Price')} {_('Sold')} {bestSellers.length === 0 && ( {_('Look like you just started. No bestsellers yet.')} )} {bestSellers.map((p, i) => ( {/* `whitespace-normal` overrides TableCell's default `whitespace-nowrap`, without which the name cannot wrap and `line-clamp-2` clips it to a single line mid-word. */}
{/* Fixed box so a missing or broken image keeps the row the same height as its neighbours. */}
{p.image?.url ? ( ) : ( )}
{p.name}
{p.price.regular.text} {p.soldQty}
))}
); } export const layout = { areaId: 'leftSide', sortOrder: 20 }; export const query = ` query Query { bestSellers { name price { regular { value text } } soldQty image { url } editUrl } listUrl: url(routeId: "productGrid") } `;