AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

shop-by.tsx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { useStorefront } from '../context';
  2. import type { ShopBySection, StoreCollection } from '../types';
  3. import { Container, ImagePlaceholder, SectionHeading, SfLink } from '../ui';
  4. /**
  5. * "Shop by": the store's collections as round photos (circles) or larger photo tiles (tiles).
  6. * Shows the collections the design names, in that order, or every collection when it names none.
  7. * Nothing shows until the merchant has a collection with products.
  8. */
  9. export function ShopBy({ section }: { section: ShopBySection }) {
  10. const { shop } = useStorefront();
  11. const { heading, subheading, collections: wanted } = section.content;
  12. const shown: StoreCollection[] =
  13. wanted.length > 0
  14. ? wanted
  15. .map((slug) =>
  16. shop.collections.find((item) => item.slug === slug),
  17. )
  18. .filter((item): item is StoreCollection => Boolean(item))
  19. : shop.collections;
  20. if (shown.length === 0) {
  21. return null;
  22. }
  23. if (section.variant === 'tiles') {
  24. return (
  25. <section
  26. id={section.id}
  27. className="sf-section scroll-mt-20 py-16 md:py-20"
  28. data-layout="tiles"
  29. >
  30. <Container>
  31. <SectionHeading heading={heading} subheading={subheading} />
  32. <ul className="mt-10 grid grid-cols-2 gap-4 md:grid-cols-3">
  33. {shown.map((collection, index) => (
  34. <li key={collection.slug}>
  35. <SfLink
  36. href={`/collections/${collection.slug}`}
  37. className="group relative block overflow-hidden rounded-(--sf-radius-card)"
  38. >
  39. {collection.image ? (
  40. <img
  41. src={collection.image}
  42. alt=""
  43. loading="lazy"
  44. className="sf-card aspect-[4/5] w-full rounded-(--sf-radius-card) object-cover transition-transform duration-500 motion-safe:group-hover:scale-[1.04]"
  45. />
  46. ) : (
  47. <ImagePlaceholder
  48. seed={index}
  49. label={collection.name}
  50. className="aspect-[4/5] w-full"
  51. />
  52. )}
  53. <span className="absolute inset-x-0 bottom-0 rounded-b-(--sf-radius-card) bg-linear-to-t from-black/70 to-transparent p-4 pt-12 text-white">
  54. <span className="sf-heading block text-lg font-semibold">
  55. {collection.name}
  56. </span>
  57. <span className="text-sm text-white/80">
  58. {collection.count}
  59. </span>
  60. </span>
  61. </SfLink>
  62. </li>
  63. ))}
  64. </ul>
  65. </Container>
  66. </section>
  67. );
  68. }
  69. return (
  70. <section
  71. id={section.id}
  72. className="sf-section scroll-mt-20 py-14 md:py-16"
  73. data-layout="circles"
  74. >
  75. <Container>
  76. <SectionHeading
  77. heading={heading}
  78. subheading={subheading}
  79. align="center"
  80. />
  81. <ul className="-mx-5 mt-8 flex snap-x gap-6 overflow-x-auto px-5 pb-2 sm:mx-0 sm:flex-wrap sm:justify-center sm:overflow-visible sm:px-0">
  82. {shown.map((collection, index) => (
  83. <li
  84. key={collection.slug}
  85. className="w-24 shrink-0 snap-start sm:w-32"
  86. >
  87. <SfLink
  88. href={`/collections/${collection.slug}`}
  89. className="group flex flex-col items-center gap-3 text-center"
  90. >
  91. {collection.image ? (
  92. <img
  93. src={collection.image}
  94. alt=""
  95. loading="lazy"
  96. className="aspect-square w-full rounded-full object-cover ring-1 ring-(--sf-border) transition-transform duration-300 motion-safe:group-hover:scale-105"
  97. />
  98. ) : (
  99. <ImagePlaceholder
  100. seed={index}
  101. label={collection.name}
  102. className="aspect-square w-full rounded-full!"
  103. />
  104. )}
  105. <span className="text-sm font-medium group-hover:underline">
  106. {collection.name}
  107. </span>
  108. </SfLink>
  109. </li>
  110. ))}
  111. </ul>
  112. </Container>
  113. </section>
  114. );
  115. }