Product Display

This commit is contained in:
Jérémy Munsch 2024-01-12 15:54:15 +01:00
parent 851819465f
commit 00bc9a42fe
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC

View file

@ -1,15 +1,58 @@
<template>
<div class="page-ranges-index">
<div class="page-ranges-index py-5 my-5">
<h1>Range {{ route.params.slug }}</h1>
<br>
<div class="container">
<div v-if="range.products" class="row">
<div v-for="(product, productIndex) of range.products" :key="productIndex" class="col-12 col-md-6">
<div>
<img class="img-fluid" :src="`/data/${product.picture}`" :alt="`Produit ${product.name}`">
<template
v-for="(product, productIndex) of range.products"
:key="productIndex"
>
<div
:class="{
'col-12 product': true,
'col-md-6': activeProduct?.id !== product.id
}"
>
<button
:class="{
'd-inline-block btn position-relative': true,
'border border-primary-subtle my-3': activeProduct?.id === product.id
}"
title="En savoir plus sur ce produit"
data-bs-toggle="tooltip"
@click.stop="showProduct(product, $event)"
>
<button
v-if="activeProduct?.id === product.id"
type="button"
class="btn-close position-absolute top-0 end-0 me-4 mt-3"
aria-label="Close"
@click.stop="closeProduct()"
/>
<div class="row text-start">
<div
:class="{
'col-12': true,
'col-md-6': activeProduct?.id === product.id,
}"
>
<img class="img-fluid" :src="`/data/${product.picture}`" :alt="`Produit ${product.name}`">
</div>
<Transition>
<div v-if="activeProduct?.id === product.id" class="col pt-5">
<div class="text-end" />
<div v-sane-html="product.description" class="p-3 my-5 description" />
</div>
</Transition>
</div>
<span class="fs-2 fw-bold">{{ product.name }}</span>
</button>
</div>
<span class="fs-2 fw-bold">{{ product.name }}</span>
</div>
<!-- Force next columns to break to new line -->
<div v-if="activeProduct?.id === product.id" class="w-100" />
</template>
</div>
<div v-else class="row">
<div class="col">
@ -22,21 +65,34 @@
<script lang="ts">
import DOMPurify from "dompurify";
import type { DirectiveBinding } from "vue";
import { defineComponent } from "vue";
import { useRoute, type RouteLocationNormalizedLoaded } from "vue-router";
import Toast, { ToastTypeEnum } from "~/classes/Toast";
const saneHtml = {
mounted: (el: HTMLElement, binding: DirectiveBinding) => {
el.innerHTML = DOMPurify.sanitize(binding.value);
},
};
export default defineComponent({
name: "RangesIndex",
directives: {
saneHtml,
},
props: {
},
data(): {
route: RouteLocationNormalizedLoaded;
range: TypeRange;
activeProduct: TypeProduct|null;
} {
return {
route: useRoute(),
range: {} as TypeRange
range: {} as TypeRange,
activeProduct: null
};
},
mounted() {
@ -49,6 +105,46 @@ export default defineComponent({
this.range = range;
},
methods: {
showProduct(product:TypeProduct, $event:Event) {
const el = $event.target as HTMLButtonElement;
this.activeProduct = product;
setTimeout(() => el.scrollIntoView({
behavior: "smooth",
block: "center"
}), 500);
},
closeProduct() {
this.activeProduct = null;
}
}
});
</script>
<style lang="scss" scoped>
@import "bootstrap/scss/vendor/rfs";
.product {
transition: all 0.2s ease-out allow-discrete;
}
.product.col-md-6 {
transition: none;
}
.btn-close {
@include rfs(2em, font-size);
}
.description {
@include rfs(1.2em, font-size);
}
.v-enter-active,
.v-leave-active {
transition: opacity .3s ease-in;
transition-delay: 0.4s;
}
.v-enter-from,
.v-leave-to {
opacity: 0;
transition: none;
}
</style>