-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathShoeCard.js
121 lines (107 loc) · 2.71 KB
/
ShoeCard.js
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
import React from "react";
import styled from "styled-components/macro";
import { COLORS, WEIGHTS } from "../../constants";
import { formatPrice, pluralize, isNewShoe } from "../../utils";
import Spacer from "../Spacer";
const ShoeCard = ({
slug,
name,
imageSrc,
price,
salePrice,
releaseDate,
numOfColors,
}) => {
// There are 3 variants possible, based on the props:
// - new-release
// - on-sale
// - default
//
// Any shoe released in the last month will be considered
// `new-release`. Any shoe with a `salePrice` will be
// on-sale. In theory, it is possible for a shoe to be
// both on-sale and new-release, but in this case, `on-sale`
// will triumph and be the variant used.
// prettier-ignore
const variant = typeof salePrice === 'number'
? 'on-sale'
: isNewShoe(releaseDate)
? 'new-release'
: 'default'
return (
<Link href={`/shoe/${slug}`}>
{variant !== "default" ? (
variant === "on-sale" ? (
<Banner type="sale">Sale</Banner>
) : (
<Banner type="newRelease">Just Released!</Banner>
)
) : (
""
)}
<Wrapper>
<ImageWrapper>
<Image alt="" src={imageSrc} />
</ImageWrapper>
<Spacer size={12} />
<Row>
<Name>{name}</Name>
<Price crossedOut={variant === "on-sale"}>{formatPrice(price)}</Price>
</Row>
<Row>
<ColorInfo>{pluralize("Color", numOfColors)}</ColorInfo>
{variant === "on-sale" && (
<SalePrice>{formatPrice(salePrice)}</SalePrice>
)}
</Row>
</Wrapper>
</Link>
);
};
const Link = styled.a`
text-decoration: none;
color: inherit;
display: flex;
flex: 1 1 400px;
position: relative;
`;
const Wrapper = styled.article``;
const ImageWrapper = styled.div`
position: relative;
`;
const Image = styled.img`
width: 100%;
`;
const Row = styled.div`
font-size: 1rem;
display: flex;
justify-content: space-between;
`;
const Name = styled.h3`
font-weight: ${WEIGHTS.medium};
color: ${COLORS.gray[900]};
`;
const Price = styled.span`
text-decoration: ${(props) => (props.crossedOut ? "line-through" : "none")};
color: ${(props) => (props.crossedOut ? COLORS.gray[700] : "black")};
`;
const ColorInfo = styled.p`
color: ${COLORS.gray[700]};
`;
const SalePrice = styled.span`
font-weight: ${WEIGHTS.medium};
color: ${COLORS.primary};
`;
const Banner = styled.span`
background-color: ${(props) =>
props.type === "sale" ? COLORS.primary : COLORS.secondary};
position: absolute;
top: 20px;
right: -6px;
border-radius: 2px;
z-index: 1;
color: white;
padding: 6px;
font-weight: ${WEIGHTS.medium};
`;
export default ShoeCard;