This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add DataTable Component
- Loading branch information
Yago Pérez Vázquez
authored
Dec 21, 2021
1 parent
47209c6
commit f34f8c3
Showing
14 changed files
with
210 additions
and
48 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,84 @@ | ||
import React from 'react'; | ||
import { GridDensityTypes, GridRowsProp } from '@mui/x-data-grid'; | ||
import DataTable from './index'; | ||
|
||
export default { | ||
title: 'Data Display/Data Table', | ||
component: DataTable, | ||
parameters: { | ||
componentSubtitle: | ||
'Advanced tables. Wrapper around Material UI x-data-grid', | ||
docs: { | ||
description: { | ||
component: | ||
'Check the <a href="https://v4.mui.com/components/data-grid" target="_blank">official DataGrid docs</a> for options and API', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const COLUMN_CONFIG = [ | ||
{ | ||
field: 'asset', | ||
headerName: 'Asset', | ||
flex: 1, | ||
}, | ||
{ | ||
field: 'amount', | ||
headerName: 'Amount', | ||
sortable: false, | ||
flex: 1, | ||
}, | ||
{ | ||
field: 'value', | ||
headerName: 'Value', | ||
flex: 1, | ||
}, | ||
]; | ||
|
||
const randomIntFromInterval = (min: number, max: number): number => { | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
}; | ||
|
||
const generateTestData = (howMany: number): GridRowsProp => { | ||
const testData = []; | ||
|
||
for (let index = 0; index < howMany; index++) { | ||
testData.push({ | ||
id: index, | ||
asset: `Token ${index}`, | ||
amount: randomIntFromInterval(1, 100), | ||
value: `$${randomIntFromInterval(0, 10000)}`, | ||
}); | ||
} | ||
|
||
return testData; | ||
}; | ||
|
||
export const DataGrid = (): React.ReactElement => { | ||
return ( | ||
<DataTable | ||
rows={generateTestData(5)} | ||
columns={COLUMN_CONFIG} | ||
checkboxSelection | ||
hideFooter | ||
autoHeight | ||
density={GridDensityTypes.Comfortable} | ||
/> | ||
); | ||
}; | ||
|
||
export const PaginatedDataGrid = (): React.ReactElement => { | ||
return ( | ||
<DataTable | ||
rows={generateTestData(20)} | ||
columns={COLUMN_CONFIG} | ||
pageSize={5} | ||
rowsPerPageOptions={[5]} | ||
disableColumnMenu | ||
checkboxSelection | ||
autoHeight | ||
density={GridDensityTypes.Comfortable} | ||
/> | ||
); | ||
}; |
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,38 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { DataGrid as DataGridMui, DataGridProps } from '@mui/x-data-grid'; | ||
import theme from '../../theme'; | ||
|
||
const DataTable = (props: DataGridProps): React.ReactElement => { | ||
const classes = useStyles(); | ||
|
||
return <DataGridMui classes={classes} {...props} />; | ||
}; | ||
|
||
const useStyles = makeStyles({ | ||
row: { | ||
'&.Mui-selected': { | ||
backgroundColor: 'transparent !important', | ||
}, | ||
}, | ||
cell: { | ||
'&:focus,&:focus-within,&.MuiDataGrid-cellCheckbox:focus': { | ||
backgroundColor: 'rgba(0, 0, 0, 0.04)', | ||
outline: 'none !important', | ||
}, | ||
'&.MuiDataGrid-cellCheckbox .Mui-checked': { | ||
color: theme.colors.primary, | ||
}, | ||
}, | ||
columnHeader: { | ||
'&:focus,&:focus-within': { | ||
backgroundColor: 'rgba(0, 0, 0, 0.04)', | ||
outline: 'none !important', | ||
}, | ||
'&.MuiDataGrid-columnHeader .Mui-checked': { | ||
color: theme.colors.primary, | ||
}, | ||
}, | ||
}); | ||
|
||
export default DataTable; |
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
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ declare module '*.svg' { | |
|
||
declare module '*.ttf'; | ||
declare module '*.woff2'; | ||
declare module 'react-qr-reader'; |
5 changes: 5 additions & 0 deletions
5
tests/dataDisplay/DataTable/__snapshots__/dataTable.stories.storyshot
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Storyshots Data Display/Data Table Data Grid 1`] = `null`; | ||
|
||
exports[`Storyshots Data Display/Data Table Paginated Data Grid 1`] = `null`; |
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
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
Oops, something went wrong.