-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathCartItem.vue
95 lines (85 loc) · 2.42 KB
/
CartItem.vue
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
<template>
<div class="container mx-auto mt-4 flex-container">
<div class="item">
<span class="block mt-2 font-extrabold">Remove: <br /></span>
<span class="item-content">
<nuxt-img
class="mt-2 ml-4 cursor-pointer"
:class="{ removing: isRemoving }"
alt="Remove icon"
aria-label="Remove"
src="/svg/Remove.svg"
@click="emitRemove"
/>
</span>
</div>
<div class="item">
<span class="block mt-2 font-extrabold">Name: <br /></span>
<span class="item-content">{{ product.product.name }}</span>
</div>
<div class="item">
<span class="block mt-2 font-extrabold">Quantity: <br /></span>
<span class="item-content">
{{ product.quantity }}
</span>
</div>
<div class="item">
<span class="block mt-2 font-extrabold">Subtotal: <br /></span>
<span class="item-content">{{ formatPrice(product.total) }}</span>
</div>
</div>
</template>
<script setup>
/**
* Vue component representing a product item in a shopping cart.
*
* @component CartItem
*
* @prop {Object} product - The product object containing information about the product.
* @prop {Object} product.product - The product details.
* @prop {string} product.product.name - The name of the product.
* @prop {number} product.quantity - The quantity of the product.
* @prop {string} product.total - The subtotal of the product.
* @prop {string} product.key - The unique key for the cart item.
*
* @emits CartItem#remove - Emitted when the remove button is clicked.
*/
import { ref } from "vue";
import { formatPrice } from "@/utils/functions";
const isRemoving = ref(false);
const props = defineProps({
product: {
type: Object,
required: true,
},
});
const emit = defineEmits(["remove"]);
/**
* Emits a "remove" event with the product's key as the payload.
*/
const emitRemove = () => {
isRemoving.value = true;
emit("remove", props.product.key);
};
</script>
<style scoped>
.flex-container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-around;
align-items: center;
align-content: center;
max-width: 1380px;
@apply border border-gray-300 rounded-lg shadow;
}
.item {
@apply lg:m-2 xl:m-4 xl:w-1/6 lg:w-1/6 sm:m-2 w-auto;
}
.item-content {
@apply inline-block mt-4 w-20 h-12 md:w-full lg:w-full xl:w-full;
}
.removing {
@apply animate-spin cursor-not-allowed;
}
</style>