-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathCreditCard.js
More file actions
43 lines (41 loc) · 1.01 KB
/
CreditCard.js
File metadata and controls
43 lines (41 loc) · 1.01 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
import "./CreditCard.css";
import logo from "../assets/images/visa.png";
import icon from "../assets/images/master-card-copy.svg";
function CreditCard({
type,
number,
expirationMonth,
expirationYear,
bank,
owner,
bgColor,
color,
}) {
let cardStyle = { background: bgColor, color: color };
let month = expirationMonth.toString().padStart(2, "0");
let year = expirationYear.toString().slice(-2);
let maskNumber = number.slice(-4).padStart(number.length, "•");
let cardNumber =
maskNumber.slice(0, 4) +
" " +
maskNumber.slice(4, 8) +
" " +
maskNumber.slice(8, 12) +
" " +
maskNumber.slice(12, 16);
return (
<div id="ccbox" style={cardStyle}>
<img src={type === "Visa" ? logo : icon} alt={type} width={50} />
<div id="cnumber">{cardNumber}</div>
<div id="cdetails">
<div>
{" "}
Expires {month}/{year}
<span>{bank}</span>
</div>
<div>{owner}</div>
</div>
</div>
);
}
export default CreditCard;