Files
consumocuidado/components/CategoryRow.vue
2025-11-12 13:37:16 +01:00

169 lines
3.5 KiB
Vue

<template>
<div class="row container">
<ClientOnly placeholder="Loading...">
<Carousel
ref="categoryDetails"
class="carousel"
:items-to-show="itemsToShow"
:breakpoints="config.breakpoints"
:gap="1"
:pagination-enabled="false"
:wrap-around="false"
:mouse-wheel="false"
:breakpoints-enabled="true"
>
<Slide v-for="item in items" :key="`category-${item.image}`" class="slide-container">
<div class="slide" @click="searchByCategory(item.name)">
<div class="image-container">
<img class="image" :src="item.image ? item.image : defaultImage" :alt="`${item.name} category image`" />
</div>
<p class="category-name">{{ item.name }}</p>
</div>
</Slide>
<template #addons>
<Navigation />
</template>
</Carousel>
</ClientOnly>
</div>
</template>
<script>
import { Carousel, Slide, Navigation } from 'vue3-carousel'
import 'vue3-carousel/dist/carousel.css'
import defaultImage from '@/assets/img/producto-default.png'
export default {
components: {
Carousel,
Slide,
Navigation
},
props: {
type: {
type: String,
required: true,
},
items: {
type: Array,
default: () => [],
},
itemsToShow: {
type: Number,
default: 1,
},
},
data() {
return {
defaultImage,
config: {
height: 200,
breakpointMode: 'carousel', // o 'viewport'
breakpoints: {
768: {
itemsToShow: 3,
snapAlign: 'center',
},
1024: {
itemsToShow: 4,
snapAlign: 'start',
},
1440: {
itemsToShow: 5,
snapAlign: 'start',
},
},
}
}
},
methods: {
searchByCategory(categoryName) {
const formattedCategory = categoryName
.toLowerCase()
.replace(/á/g, 'a')
.replace(/é/g, 'e')
.replace(/í/g, 'i')
.replace(/ó/g, 'o')
.replace(/ú/g, 'u')
.replace(/ñ/g, 'n')
.replace(/\s+/g, '-')
console.log('Searching by category:', formattedCategory)
this.$router.push(`/busqueda?category=${formattedCategory}`)
}
}
}
</script>
<style lang="scss" scoped>
.row {
padding: 0 4rem;
display: flex;
align-items: center;
justify-content: center
}
.image-container {
width: 100%;
height: 50%;
display: flex;
@include mobile {
max-height: 10rem;
max-width: 10rem;
}
.image {
width: fit-content;
height: fit-content;
margin: auto;
}
}
.slide-container {
padding: 0.5rem;
}
.slide {
width: 179px;
height: 213px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: stretch;
background-color: transparent;
border: 5px solid white;
border-radius: 24px;
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.15);
text-decoration: none;
position: relative; // necesario para controlar hijos absolutos
overflow: hidden;
padding: 16px;
&:hover {
cursor: pointer;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.25);
transform: translateY(-4px);
transition: all 0.3s ease-in-out;
}
p {
text-align: center;
display: -webkit-box;
--webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
width: 100%;
font-weight: $medium;
font-size: $m;
}
.category-name {
color: black;
font-weight: bold;
text-transform: uppercase;
}
}
</style>