All files / src/entities/catalog/ui ProductMasonry.vue

100% Statements 4/4
100% Branches 4/4
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                          3x         4x 3x                                                                                            
<script setup lang="ts">
import type { ProductSummary } from "@plain-journal/foundation";
 
import ProductCard from "./ProductCard.vue";
 
withDefaults(defineProps<{
  products: ProductSummary[];
  headingLevel?: 2 | 3;
}>(), {
  headingLevel: 3,
});
 
function mediaAspect(index: number): "landscape" | "square" {
  return index % 4 === 0 || index % 4 === 3 ? "landscape" : "square";
}
</script>
 
<template>
  <div class="product-masonry">
    <ProductCard
      v-for="(product, index) in products"
      :key="product.id"
      class="product-masonry__item"
      :product="product"
      :heading-level="headingLevel"
      :media-aspect="mediaAspect(index)"
    />
  </div>
</template>
 
<style scoped>
.product-masonry {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: clamp(2rem, 4vw, 4.5rem) clamp(1rem, 2vw, 2rem);
  align-items: start;
}
 
.product-masonry__item {
  grid-column: span 5;
}
 
.product-masonry__item:nth-child(4n + 1),
.product-masonry__item:nth-child(4n) {
  grid-column: span 7;
}
 
@media (max-width: 48rem) {
  .product-masonry {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
 
  .product-masonry__item,
  .product-masonry__item:nth-child(4n + 1),
  .product-masonry__item:nth-child(4n) {
    grid-column: span 1;
  }
}
 
@media (max-width: 32rem) {
  .product-masonry {
    gap: var(--pj-space-7) var(--pj-space-3);
  }
}
</style>