AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

product-card.tsx 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { useStorefront } from './context';
  2. import { storefrontText } from './text';
  3. import { formatPrice } from './theme';
  4. import type { StoreProduct } from './types';
  5. import { ImagePlaceholder, SfLink } from './ui';
  6. /** A product photo, or the themed placeholder when the product has none. */
  7. export function ProductImage({
  8. src,
  9. alt,
  10. seed = 0,
  11. className,
  12. }: {
  13. src: string | null;
  14. alt: string;
  15. seed?: number;
  16. className?: string;
  17. }) {
  18. if (!src) {
  19. return (
  20. <ImagePlaceholder seed={seed} label={alt} className={className} />
  21. );
  22. }
  23. return (
  24. <img
  25. src={src}
  26. alt={alt}
  27. loading="lazy"
  28. className={`rounded-(--sf-radius-card) border border-(--sf-border) object-cover ${className ?? ''}`}
  29. />
  30. );
  31. }
  32. export function Price({ product }: { product: StoreProduct }) {
  33. return (
  34. <p className="text-sm tabular-nums">
  35. <span className="text-(--sf-muted)">
  36. {formatPrice(product.price)}
  37. </span>
  38. {product.compare_at_price !== null && (
  39. <s className="ml-2 text-(--sf-muted) opacity-70">
  40. {formatPrice(product.compare_at_price)}
  41. </s>
  42. )}
  43. </p>
  44. );
  45. }
  46. /** One real product in a grid. The whole card links to the product's page. */
  47. export function ProductCard({
  48. product,
  49. seed = 0,
  50. centered = false,
  51. }: {
  52. product: StoreProduct;
  53. seed?: number;
  54. centered?: boolean;
  55. }) {
  56. const { language } = useStorefront();
  57. const t = storefrontText(language);
  58. return (
  59. <SfLink href={`/products/${product.slug}`} className="group block">
  60. <div className="relative">
  61. <ProductImage
  62. src={product.image}
  63. alt={product.name}
  64. seed={seed}
  65. className="aspect-[4/5] w-full transition-opacity group-hover:opacity-90"
  66. />
  67. {!product.in_stock && (
  68. <span className="absolute top-3 left-3 rounded-(--sf-radius) bg-(--sf-fg) px-2.5 py-1 text-xs font-semibold text-(--sf-bg)">
  69. {t.soldOut}
  70. </span>
  71. )}
  72. </div>
  73. <div
  74. className={
  75. centered
  76. ? 'mt-4 text-center'
  77. : 'mt-4 flex flex-col gap-1 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3'
  78. }
  79. >
  80. <h3 className="font-medium group-hover:underline">
  81. {product.name}
  82. </h3>
  83. <Price product={product} />
  84. </div>
  85. </SfLink>
  86. );
  87. }