Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add data table component (#179)
Browse files Browse the repository at this point in the history
- Add DataTable Component
  • Loading branch information
Yago Pérez Vázquez authored Dec 21, 2021
1 parent 47209c6 commit f34f8c3
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 48 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-react-components",
"version": "0.9.5",
"version": "0.9.6",
"description": "Gnosis UI components",
"main": "dist/index.min.js",
"typings": "dist/index.d.ts",
Expand All @@ -25,8 +25,8 @@
"author": "Gnosis (https://gnosis.pm)",
"license": "MIT",
"dependencies": {
"web3-utils": "^1.6.0",
"react-media": "^1.10.0"
"react-media": "^1.10.0",
"web3-utils": "^1.6.0"
},
"devDependencies": {
"@babel/core": "^7.16.0",
Expand All @@ -53,7 +53,6 @@
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"copy-webpack-plugin": "^6.3.0",
"react-qr-reader": "2.2.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
Expand All @@ -67,9 +66,11 @@
"prettier": "^2.4.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-qr-reader": "2.2.1",
"rimraf": "^3.0.2",
"storybook-addon-react-docgen": "^1.2.42",
"styled-components": "^5.3.3",
"@mui/x-data-grid": "4.0.2",
"ts-loader": "^8.2.0",
"typescript": "^4.5.0",
"url-loader": "^4.1.1",
Expand All @@ -79,6 +80,7 @@
},
"peerDependencies": {
"@material-ui/core": "4.X.X",
"@mui/x-data-grid": "^4.X.X",
"react": "16.x.x || 17.x.x",
"react-dom": "16.x.x || 17.x.x",
"styled-components": "5.x.x"
Expand Down
84 changes: 84 additions & 0 deletions src/dataDisplay/DataTable/dataTable.stories.tsx
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}
/>
);
};
38 changes: 38 additions & 0 deletions src/dataDisplay/DataTable/index.tsx
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;
1 change: 1 addition & 0 deletions src/dataDisplay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './Tooltip';
export { default as Text } from './Text';
export { default as Title } from './Title';
export { default as Section } from './Section';
export { default as DataTable } from './DataTable';
4 changes: 2 additions & 2 deletions src/inputs/AddressInput/AddressInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ export const SimpleAddressInput = ({
onError={() => {
console.log('error:');
}}
onScan={(value) => {
onScan={(value: string) => {
if (value) {
setAddress(value);
setOpenQRModal(false);
}
}}
onImageLoad={(address) => setAddress(address)}
onImageLoad={(address: string) => setAddress(address)}
/>
</DialogContent>
</Dialog>
Expand Down
1 change: 1 addition & 0 deletions src/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ declare module '*.svg' {

declare module '*.ttf';
declare module '*.woff2';
declare module 'react-qr-reader';
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`;
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ exports[`Storyshots Inputs/AddressInput Address Input With ENS Resolution 1`] =
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-57 MuiSwitch-switchBase MuiSwitch-colorSecondary"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-63 MuiSwitch-switchBase MuiSwitch-colorSecondary"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -202,7 +202,7 @@ exports[`Storyshots Inputs/AddressInput Address Input With ENS Resolution 1`] =
>
<input
checked={false}
className="PrivateSwitchBase-input-60 MuiSwitch-input"
className="PrivateSwitchBase-input-66 MuiSwitch-input"
onChange={[Function]}
type="checkbox"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`Storyshots Inputs/Checkbox Simple Checkbox 1`] = `
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-62 MuiCheckbox-root Component-root-61 PrivateSwitchBase-checked-63 Mui-checked"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-68 MuiCheckbox-root Component-root-67 PrivateSwitchBase-checked-69 Mui-checked"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -28,7 +28,7 @@ exports[`Storyshots Inputs/Checkbox Simple Checkbox 1`] = `
>
<input
checked={true}
className="PrivateSwitchBase-input-65"
className="PrivateSwitchBase-input-71"
data-indeterminate={false}
disabled={false}
name="checkbox"
Expand Down Expand Up @@ -65,7 +65,7 @@ exports[`Storyshots Inputs/Checkbox With Error 1`] = `
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-67 MuiCheckbox-root Component-root-66"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-73 MuiCheckbox-root Component-root-72"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -84,7 +84,7 @@ exports[`Storyshots Inputs/Checkbox With Error 1`] = `
>
<input
checked={false}
className="PrivateSwitchBase-input-70"
className="PrivateSwitchBase-input-76"
data-indeterminate={false}
disabled={false}
name="checkboxWithError"
Expand Down
4 changes: 2 additions & 2 deletions tests/inputs/Switch/__snapshots__/switch.stories.storyshot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`Storyshots Inputs/Switch Switch Input 1`] = `
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-71 MuiSwitch-switchBase MuiSwitch-colorSecondary PrivateSwitchBase-checked-72 Mui-checked"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-77 MuiSwitch-switchBase MuiSwitch-colorSecondary PrivateSwitchBase-checked-78 Mui-checked"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -25,7 +25,7 @@ exports[`Storyshots Inputs/Switch Switch Input 1`] = `
>
<input
checked={true}
className="PrivateSwitchBase-input-74 MuiSwitch-input"
className="PrivateSwitchBase-input-80 MuiSwitch-input"
onChange={[Function]}
type="checkbox"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Errors In The Label 1`
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-75 MuiSwitch-switchBase MuiSwitch-colorSecondary PrivateSwitchBase-checked-76 Mui-checked"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-81 MuiSwitch-switchBase MuiSwitch-colorSecondary PrivateSwitchBase-checked-82 Mui-checked"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -431,7 +431,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Errors In The Label 1`
>
<input
checked={true}
className="PrivateSwitchBase-input-78 MuiSwitch-input"
className="PrivateSwitchBase-input-84 MuiSwitch-input"
onChange={[Function]}
type="checkbox"
/>
Expand All @@ -454,7 +454,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Errors In The Label 1`
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-75 MuiSwitch-switchBase MuiSwitch-colorSecondary"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-81 MuiSwitch-switchBase MuiSwitch-colorSecondary"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -473,7 +473,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Errors In The Label 1`
>
<input
checked={false}
className="PrivateSwitchBase-input-78 MuiSwitch-input"
className="PrivateSwitchBase-input-84 MuiSwitch-input"
onChange={[Function]}
type="checkbox"
/>
Expand All @@ -496,7 +496,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Errors In The Label 1`
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-75 MuiSwitch-switchBase MuiSwitch-colorSecondary"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-81 MuiSwitch-switchBase MuiSwitch-colorSecondary"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -515,7 +515,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Errors In The Label 1`
>
<input
checked={false}
className="PrivateSwitchBase-input-78 MuiSwitch-input"
className="PrivateSwitchBase-input-84 MuiSwitch-input"
onChange={[Function]}
type="checkbox"
/>
Expand Down Expand Up @@ -588,7 +588,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Hidden Label 1`] = `
>
<span
aria-disabled={false}
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-79 MuiSwitch-switchBase MuiSwitch-colorSecondary PrivateSwitchBase-checked-80 Mui-checked"
className="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root-85 MuiSwitch-switchBase MuiSwitch-colorSecondary PrivateSwitchBase-checked-86 Mui-checked"
onBlur={[Function]}
onDragLeave={[Function]}
onFocus={[Function]}
Expand All @@ -607,7 +607,7 @@ exports[`Storyshots Inputs/TextFieldInput Text Field With Hidden Label 1`] = `
>
<input
checked={true}
className="PrivateSwitchBase-input-82 MuiSwitch-input"
className="PrivateSwitchBase-input-88 MuiSwitch-input"
onChange={[Function]}
type="checkbox"
/>
Expand Down
Loading

0 comments on commit f34f8c3

Please sign in to comment.