-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Siddharth Tiwari
authored and
Siddharth Tiwari
committed
Jan 3, 2024
1 parent
48b1db0
commit 4154985
Showing
2 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React from "react" | ||
import Table from "@mui/joy/Table" | ||
import { Box, Button } from "@mui/joy" | ||
import DownloadIcon from "@mui/icons-material/Download" | ||
|
||
const SampleCSVTable = () => { | ||
const createCsvContent = () => { | ||
const csvRows = [["username", "dollars", "memo"]] | ||
return csvRows.map((e) => e.join(",")).join("\n") | ||
} | ||
|
||
const handleDownload = () => { | ||
const csvContent = createCsvContent() | ||
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" }) | ||
const link = document.createElement("a") | ||
const url = URL.createObjectURL(blob) | ||
link.setAttribute("href", url) | ||
link.setAttribute("download", "template.csv") | ||
link.style.visibility = "hidden" | ||
document.body.appendChild(link) | ||
link.click() | ||
document.body.removeChild(link) | ||
} | ||
|
||
return ( | ||
<> | ||
<Box | ||
sx={{ | ||
maxWidth: "35em", | ||
margin: "0 auto", | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
justifyContent: "right", | ||
marginBottom: "0.2em", | ||
}} | ||
> | ||
<Button | ||
sx={{ | ||
display: "flex", | ||
gap: "0.5em", | ||
}} | ||
variant="plain" | ||
onClick={handleDownload} | ||
> | ||
<DownloadIcon /> Download Template | ||
</Button> | ||
</Box> | ||
<Table | ||
sx={{ | ||
"width": "100%", | ||
"border": "1px solid #ccc", | ||
"borderCollapse": "collapse", | ||
"& th, & td": { | ||
border: "1px solid #ccc", | ||
padding: "0.5em", | ||
}, | ||
}} | ||
aria-label={`payments`} | ||
> | ||
<thead> | ||
<tr> | ||
<th>username</th> | ||
<th>dollars/sats</th> | ||
<th>memo</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>user a</td> | ||
<td>12</td> | ||
<td>sample memo</td> | ||
</tr> | ||
<tr> | ||
<td>user b</td> | ||
<td>20</td> | ||
<td>sample memo</td> | ||
</tr> | ||
<tr> | ||
<td>user a</td> | ||
<td>30</td> | ||
<td>sample memo</td> | ||
</tr> | ||
</tbody> | ||
</Table> | ||
</Box> | ||
</> | ||
) | ||
} | ||
|
||
export default SampleCSVTable |