Skip to content

Commit 75e83ec

Browse files
authored
Add "more info" and "add to cart" buttons on the product cards (#9)
* Enhance ProductCard component with action buttons and improved layout * Fix selector for product title styling and adjust padding on hover * Refactor CSS variables for product card and button styles into global.css * Fix image path in ProductCard component for correct asset loading
1 parent 25c18d8 commit 75e83ec

2 files changed

Lines changed: 82 additions & 13 deletions

File tree

src/components/ProductCard.astro

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ const { product_name } = Astro.props;
77

88
<Fragment>
99
<div class="product-card" style=`background-image: url("product/${product_id}.png");`>
10-
<h1>{product_name}</h1>
10+
<div class="product-card-content">
11+
<h1>{product_name}</h1>
12+
<div class="product-card-actions">
13+
<button class="product-more-info">More info</button>
14+
<button class="product-add-cart">Add to cart</button>
15+
</div>
16+
</div>
1117
</div>
1218
</Fragment>
1319

1420
<style>
15-
:root {
16-
--card-size-wide: 350px;
17-
--card-size-narrow: calc(var(--card-size-wide) / 2);
18-
}
19-
2021
.product-card {
2122
align-items: center;
2223
background-position: center;
@@ -29,18 +30,70 @@ const { product_name } = Astro.props;
2930
justify-content: end;
3031
min-width: var(--card-size-wide);
3132
min-height: var(--card-size-wide);
33+
position: relative;
34+
overflow: hidden;
35+
}
36+
37+
.product-card-content {
38+
align-items: center;
39+
display: flex;
40+
flex-direction: column;
41+
width: 100%;
3242
}
3343

3444
.product-card > * {
3545
background-color: light-dark(rgb(255 255 255 / 0.5), rgb(0 0 0 / 0.5));
3646
border-radius: inherit;
3747
overflow: hidden;
38-
padding: var(--spacing-small);
3948
text-align: center;
4049
width: 100%;
4150
}
4251

43-
@media screen and (width<=850px) {
52+
.product-card-content > h1 {
53+
padding: var(--spacing-small);
54+
}
55+
56+
.product-card-actions {
57+
cursor: default;
58+
display: flex;
59+
max-height: 0;
60+
opacity: 0;
61+
overflow: hidden;
62+
width: 100%;
63+
}
64+
65+
.product-card-actions button {
66+
border: none;
67+
border-radius: var(--button-border-radius);
68+
cursor: pointer;
69+
font-size: var(--button-font-size);
70+
padding: var(--button-padding);
71+
width: 100%;
72+
}
73+
74+
.product-card-actions button.product-more-info {
75+
background-color: light-dark(#409eff, #3178c6);
76+
}
77+
78+
.product-card-actions button.product-add-cart {
79+
background-color: light-dark(#41b883, #1f883d);
80+
}
81+
82+
.product-card:hover .product-card-actions {
83+
max-height: calc(2rem + var(--spacing-small));
84+
opacity: 1;
85+
transition-delay: 0.05s;
86+
}
87+
88+
.product-card:hover .product-card-content > h1 {
89+
padding: calc(var(--spacing-small) / 2);
90+
}
91+
92+
.product-card-actions button:hover {
93+
filter: brightness(var(--button-hover-brightness));
94+
}
95+
96+
@media screen and (width <= 850px) {
4497
h1 {
4598
font-size: 0.75rem;
4699
}

src/styles/global.css

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
:root {
22
color-scheme: light dark;
33

4-
/*
5-
Define spacing sizes for margins, paddings, and gaps.
6-
Use these to ensure consistent spacing throughout the UI.
4+
/*
5+
Define spacing sizes for margins, paddings, and gaps.
6+
Use these to ensure consistent spacing throughout the UI.
77
*/
88
--spacing-small: 0.4rem;
99
--spacing-medium: 1.6rem;
1010
--spacing-large: 3.2rem;
1111

12-
/*
13-
Define border-radius sizes for rounded corners.
12+
/*
13+
Define border-radius sizes for rounded corners.
1414
Use these to maintain a cohesive design for buttons, cards, and other UI elements.
1515
*/
1616
--border-radius-small: 8px;
1717
--border-radius-medium: 16px;
1818
--border-radius-large: 32px;
19+
20+
/*
21+
Product card sizes for different screen widths.
22+
Use these to ensure cards are responsive and maintain a consistent size across the UI.
23+
*/
24+
--card-size-wide: 350px;
25+
--card-size-narrow: calc(var(--card-size-wide) / 2);
26+
27+
/*
28+
Define button styles for consistent appearance across the UI.
29+
Use these variables to maintain a cohesive design for buttons.
30+
*/
31+
--button-padding: var(--spacing-small);
32+
--button-font-size: 1rem;
33+
--button-border-radius: var(--border-radius-small);
34+
--button-hover-brightness: 1.25;
1935
}
2036

2137
* {

0 commit comments

Comments
 (0)