-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathDetailCard.jsx
More file actions
62 lines (56 loc) · 1.48 KB
/
DetailCard.jsx
File metadata and controls
62 lines (56 loc) · 1.48 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
import React, { useRef } from "react";
import './DetailCard.css';
import { useReactToPrint } from "react-to-print";
const DetailCard = (props) => {
const printRef = useRef(null); // ref to point when print pdf is triggered
const name = props?.detail?.name;
const image = props?.detail?.sprites?.front_default;
const detailStats = props?.detail?.stats;
const onDownloadPdf = useReactToPrint({
content: () => printRef.current
});
const renderStatsTable = (stats) => (
<div className="table-wrapper">
<table>
<tr>
<th>Name</th>
<th>Base Stats</th>
</tr>
{stats.map((stat, index) => (
<tr key={index}>
<td>{stat.stat.name}</td>
<td>{stat.base_stat}</td>
</tr>
))}
</table>
</div>
);
const renderBarChart = (stats) => (
<div className="barchart-wrapper">
<table>
{stats.map((stat, index) => (
<tr key={index}>
<td>{stat.stat.name}</td>
<td>
<div className="bar-box">
<div className="progress-bar" style={{ width: `${stat?.base_stat}%` }} />
</div>
</td>
</tr>
))}
</table>
</div>
);
return (
<div ref={printRef} className="card-container">
<span className="pokemon-name">{name}</span>
<div className="top-content">
<img className="pokemon-img" src={image} alt={name} />
{renderStatsTable(detailStats)}
</div>
{renderBarChart(detailStats)}
<button onClick={onDownloadPdf}>Download As PDF</button>
</div>
);
};
export default DetailCard;