-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBookCard.vue
More file actions
137 lines (121 loc) · 2.55 KB
/
BookCard.vue
File metadata and controls
137 lines (121 loc) · 2.55 KB
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
<script setup lang="ts">
import type { Book } from "../types/Book";
import { ref } from "vue";
const props = defineProps<{
book: Book;
}>();
const imageError = ref(false);
const handleImageError = () => {
imageError.value = true;
};
</script>
<template>
<div class="book-card">
<div class="book-image-container">
<img
v-if="book.image_url && !imageError"
:src="book.image_url"
:alt="book.title"
class="book-image"
@error="handleImageError"
/>
<div v-else class="no-image">No Image</div>
</div>
<div class="book-info">
<h3 class="book-title">{{ book.title }}</h3>
<p class="book-author">By: {{ book.authors.join(", ") }}</p>
<p class="book-year">Published: {{ book.publication_year }}</p>
<div class="rating-container">
<div class="star-rating">
{{ "★".repeat(Math.round(book.average_rating)) }}
</div>
<span class="rating-text">
{{ book.average_rating.toFixed(1) }} ({{
book.ratings_count.toLocaleString()
}}
ratings)
</span>
</div>
</div>
</div>
</template>
<style scoped>
.book-card {
display: flex;
gap: 1.5rem;
padding: 1.5rem;
background-color: white;
border-radius: 0.5rem;
box-shadow:
0 4px 6px -1px rgba(0, 0, 0, 0.1),
0 2px 4px -1px rgba(0, 0, 0, 0.06);
transition: box-shadow 200ms ease-in-out;
}
.book-card:hover {
box-shadow:
0 10px 15px -3px rgba(0, 0, 0, 0.1),
0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.book-image-container {
flex-shrink: 0;
width: 8rem;
height: 12rem;
background-color: #f3f4f6;
border-radius: 0.375rem;
overflow: hidden;
}
.book-image {
width: 100%;
height: 100%;
object-fit: cover;
}
.no-image {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: #9ca3af;
}
.book-info {
flex: 1;
display: flex;
flex-direction: column;
}
.book-title {
font-size: 1.25rem;
font-weight: 600;
color: #111827;
margin-bottom: 0.5rem;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.book-author {
color: #4b5563;
margin-bottom: 0.25rem;
font-size: 0.875rem;
}
.book-year {
color: #6b7280;
font-size: 0.75rem;
margin-bottom: 0.5rem;
}
.rating-container {
margin-top: auto;
padding-top: 0.5rem;
display: flex;
align-items: center;
}
.star-rating {
color: #f59e0b;
font-size: 1.125rem;
line-height: 1;
}
.rating-text {
margin-left: 0.5rem;
font-size: 0.75rem;
color: #4b5563;
}
</style>