-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe.js
More file actions
113 lines (99 loc) · 2.38 KB
/
Recipe.js
File metadata and controls
113 lines (99 loc) · 2.38 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
import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import * as recipeService from '../services/recipe.js';
// Styled components
const RecipeCard = styled.div`
width: 200px;
height: 400px;
background-color: white;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
overflow: hidden;
display: flex;
flex-direction: column;
cursor: pointer;
transition: transform 0.2s ease-in-out;
&:hover {
transform: scale(1.05);
}
`;
const RecipeImage = styled.img`
width: 100%;
height: 150px;
object-fit: cover;
`;
const RecipeContent = styled.div`
padding: 16px;
flex-grow: 1;
display: flex;
flex-direction: column;
`;
const RecipeName = styled.h3`
margin: 0 0 8px;
font-size: 18px;
`;
const RecipeDescription = styled.p`
margin: 0 0 8px;
font-size: 14px;
color: #666;
flex-grow: 1;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
`;
const RecipeRating = styled.div`
display: flex;
align-items: center;
margin-bottom: 8px;
`;
const Star = styled.span`
color: ${props => props.filled ? '#ffc107' : '#e0e0e0'};
font-size: 18px;
`;
const RecipeReview = styled.p`
margin: 0;
font-size: 12px;
font-style: italic;
color: #888;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;
// Recipe component
const Recipe = ({ recipe }) => {
const { name, description, image, rating, review } = recipe;
// Handle click event
const handleClick = () => {
recipeService.logRecipe(recipe);
};
return (
<RecipeCard onClick={handleClick}>
<RecipeImage src={image} alt={name} />
<RecipeContent>
<RecipeName>{name}</RecipeName>
<RecipeDescription>{description}</RecipeDescription>
<RecipeRating>
{[1, 2, 3, 4, 5].map((star) => (
<Star key={star} filled={star <= rating}>
★
</Star>
))}
</RecipeRating>
<RecipeReview>{review}</RecipeReview>
</RecipeContent>
</RecipeCard>
);
};
// PropTypes for type checking
Recipe.propTypes = {
recipe: PropTypes.shape({
name: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
image: PropTypes.string.isRequired,
rating: PropTypes.number.isRequired,
review: PropTypes.string.isRequired,
}).isRequired,
};
export default Recipe;