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

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

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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159                                        11x         6x                       11x 6x 6x     11x       6x                                                                                                                                                                                                                                
<script setup lang="ts">
import { RouterLink } from "vue-router";
 
import { formatMoney, type ProductSummary } from "@plain-journal/foundation";
import {
  PjResponsiveImage,
  resolveCatalogImageDelivery,
} from "@plain-journal/ui";
 
withDefaults(defineProps<{
  product: ProductSummary;
  headingLevel?: 2 | 3;
  mediaAspect?: "portrait" | "square" | "landscape";
}>(), {
  headingLevel: 3,
  mediaAspect: "portrait",
});
</script>
 
<template>
  <article class="product-card" :class="`product-card--${mediaAspect}`">
    <RouterLink
      class="product-card__link"
      :to="{ name: 'product-detail', params: { productId: product.id } }"
    >
      <div class="product-card__media">
        <PjResponsiveImage
          v-if="product.coverUrl"
          v-bind="resolveCatalogImageDelivery(product.coverUrl)"
          :alt="product.title"
          sizes="(max-width: 48rem) 48vw, (max-width: 64rem) 31vw, 22vw"
          loading="lazy"
          decoding="async"
        />
        <div v-else class="product-card__placeholder" aria-hidden="true">
          <span>{{ product.category.name }}</span>
        </div>
      </div>
      <div class="product-card__content">
        <p class="product-card__path">
          {{ product.category.name }} / {{ product.brand.name }}
        </p>
        <component :is="`h${headingLevel}`">{{ product.title }}</component>
        <p v-if="product.subtitle" class="product-card__subtitle">
          {{ product.subtitle }}
        </p>
        <p class="product-card__price">自 {{ formatMoney(product.minimumPrice) }} 起</p>
      </div>
    </RouterLink>
  </article>
</template>
 
<style scoped>
.product-card {
  min-width: 0;
}
 
.product-card__link {
  display: grid;
  gap: var(--pj-space-4);
  color: var(--pj-text-primary);
  text-decoration: none;
}
 
.product-card__media {
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: var(--pj-radius-md);
  background: var(--pj-surface-media);
  transition:
    background-color var(--pj-duration-normal) var(--pj-ease-standard),
    color 220ms var(--pj-ease-standard),
    border-color 220ms var(--pj-ease-standard);
}
 
.product-card--square .product-card__media {
  aspect-ratio: 1;
}
 
.product-card--landscape .product-card__media {
  aspect-ratio: 4 / 3;
}
 
.product-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--pj-duration-normal) var(--pj-ease-standard);
}
 
.product-card__link:hover img {
  transform: scale(1.015);
}
 
.product-card__link:focus-visible {
  outline: none;
}
 
.product-card__link:focus-visible .product-card__media {
  outline: 0.15rem solid var(--pj-focus-ring);
  outline-offset: 0.2rem;
}
 
.product-card__placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(
      145deg,
      var(--pj-color-media-muted) 0%,
      var(--pj-color-media-highlight) 58%,
      var(--pj-color-media-shadow) 100%
    );
  color: var(--pj-color-muted);
}
 
.product-card__placeholder span {
  font-size: var(--pj-font-size-xs);
  letter-spacing: 0.12em;
}
 
.product-card__content {
  display: grid;
  gap: var(--pj-space-2);
}
 
.product-card__path,
.product-card__subtitle,
.product-card__price {
  margin: 0;
  color: var(--pj-text-secondary);
  font-size: var(--pj-font-size-sm);
}
 
.product-card__content h2,
.product-card__content h3 {
  margin: 0;
  font-size: clamp(1.05rem, 1.6vw, 1.25rem);
  font-weight: 620;
  line-height: var(--pj-line-height-tight);
}
 
.product-card__price {
  margin-top: var(--pj-space-1);
  color: var(--pj-text-primary);
  font-variant-numeric: tabular-nums;
}
 
@media (max-width: 32rem) {
  .product-card__path {
    display: none;
  }
}
</style>