Created
September 14, 2022 09:10
-
-
Save isaacssemugenyi/e07adb7651b4281a8b03d299abe5bb6b to your computer and use it in GitHub Desktop.
Simple material ui tables
This file contains hidden or 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
import React from 'react'; | |
import { makeStyles } from '@bit/mui-org.material-ui.styles'; | |
import Table from '@bit/mui-org.material-ui.table'; | |
import TableBody from '@bit/mui-org.material-ui.table-body'; | |
import TableCell from '@bit/mui-org.material-ui.table-cell'; | |
import TableHead from '@bit/mui-org.material-ui.table-head'; | |
import TableRow from '@bit/mui-org.material-ui.table-row'; | |
import Paper from '@bit/mui-org.material-ui.paper'; | |
const useStyles = makeStyles(theme => ({ | |
root: { | |
width: '100%', | |
marginTop: theme.spacing(3), | |
overflowX: 'auto', | |
}, | |
table: { | |
minWidth: 650, | |
}, | |
})); | |
function createData(name, calories, fat, carbs, protein) { | |
return { name, calories, fat, carbs, protein }; | |
} | |
const rows = [ | |
createData('Frozen yoghurt', 159, 6.0, 24, 4.0), | |
createData('Ice cream sandwich', 237, 9.0, 37, 4.3), | |
createData('Eclair', 262, 16.0, 24, 6.0), | |
]; | |
export default function AcccessibleTable() { | |
const classes = useStyles(); | |
return ( | |
<Paper className={classes.root}> | |
<Table className={classes.table} aria-label="caption table"> | |
<caption>A barbone structure table example with a caption</caption> | |
<TableHead> | |
<TableRow> | |
<TableCell>Dessert (100g serving)</TableCell> | |
<TableCell align="right">Calories</TableCell> | |
<TableCell align="right">Fat (g)</TableCell> | |
<TableCell align="right">Carbs (g)</TableCell> | |
<TableCell align="right">Protein (g)</TableCell> | |
</TableRow> | |
</TableHead> | |
<TableBody> | |
{rows.map(row => ( | |
<TableRow key={row.name}> | |
<TableCell component="th" scope="row"> | |
{row.name} | |
</TableCell> | |
<TableCell align="right">{row.calories}</TableCell> | |
<TableCell align="right">{row.fat}</TableCell> | |
<TableCell align="right">{row.carbs}</TableCell> | |
<TableCell align="right">{row.protein}</TableCell> | |
</TableRow> | |
))} | |
</TableBody> | |
</Table> | |
</Paper> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple MUI table