Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples for row actions #448

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { SourceCodeSnippet } from '../../components/mdx/SourceCodeSnippet';
import Example from './sandbox/src/TS';
const JS = require('!!raw-loader!./sandbox/src/JS.js').default;
const TS = require('!!raw-loader!./sandbox/src/TS.tsx').default;

const ExampleTable = () => {
return (
<SourceCodeSnippet
Component={Example}
javaScriptCode={JS}
typeScriptCode={TS}
tableId="row-actions-buttons"
/>
);
};

export default ExampleTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example

To run this example:

- `npm install` or `yarn`
- `npm run start` or `yarn start`
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Material React Table Example</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "material-react-table-example-minimal",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite --port 3001",
"build": "vite build",
"serve": "vite preview",
"start": "vite"
},
"dependencies": {
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.4",
"material-react-table": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.0.1",
"typescript": "^4.9.4",
"vite": "^4.0.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { useMemo } from 'react';
import MaterialReactTable from 'material-react-table';
import { data } from './makeData';
import { Box, IconButton } from '@mui/material';
import { Edit as EditIcon, Delete as DeleteIcon } from '@mui/icons-material';

export const Example = () => {
const columns = useMemo(
//column definitions...
() => [
{
accessorKey: 'firstName',
header: 'First Name',
},
{
accessorKey: 'lastName',
header: 'Last Name',
},
{
accessorKey: 'address',
header: 'Address',
},
{
accessorKey: 'city',
header: 'City',
},
{
accessorKey: 'state',
header: 'State',
},
],
[],
//end
);

return (
<MaterialReactTable
columns={columns}
data={data}
enableRowActions
renderRowActions={({ row }) => (
<Box>
<IconButton onClick={() => console.info('Edit')}>
<EditIcon />
</IconButton>
<IconButton onClick={() => console.info('Delete')}>
<DeleteIcon />
</IconButton>
</Box>
)}
/>
);
};

export default Example;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { useMemo } from 'react';
import MaterialReactTable, { type MRT_ColumnDef } from 'material-react-table';
import { data, type Person } from './makeData';
import { Box, IconButton } from '@mui/material';
import { Edit as EditIcon, Delete as DeleteIcon } from '@mui/icons-material';

export const Example = () => {
const columns = useMemo<MRT_ColumnDef<Person>[]>(
//column definitions...
() => [
{
accessorKey: 'firstName',
header: 'First Name',
},
{
accessorKey: 'lastName',
header: 'Last Name',
},
{
accessorKey: 'address',
header: 'Address',
},
{
accessorKey: 'city',
header: 'City',
},
{
accessorKey: 'state',
header: 'State',
},
],
[],
//end
);

return (
<MaterialReactTable
columns={columns}
data={data}
enableRowActions
renderRowActions={({ row }) => (
<Box>
<IconButton onClick={() => console.info('Edit')}>
<EditIcon />
</IconButton>
<IconButton onClick={() => console.info('Delete')}>
<DeleteIcon />
</IconButton>
</Box>
)}
/>
);
};

export default Example;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import Example from './TS';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<Example />
</React.StrictMode>,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export type Person = {
firstName: string;
lastName: string;
address: string;
city: string;
state: string;
};

export const data = [
{
firstName: 'Dylan',
lastName: 'Murray',
address: '261 Erdman Ford',
city: 'East Daphne',
state: 'Kentucky',
},
{
firstName: 'Raquel',
lastName: 'Kohler',
address: '769 Dominic Grove',
city: 'Columbus',
state: 'Ohio',
},
{
firstName: 'Ervin',
lastName: 'Reinger',
address: '566 Brakus Inlet',
city: 'South Linda',
state: 'West Virginia',
},
{
firstName: 'Brittany',
lastName: 'McCullough',
address: '722 Emie Stream',
city: 'Lincoln',
state: 'Nebraska',
},
{
firstName: 'Branson',
lastName: 'Frami',
address: '32188 Larkin Turnpike',
city: 'Charleston',
state: 'South Carolina',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node"
},
"include": ["vite.config.ts"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { SourceCodeSnippet } from '../../components/mdx/SourceCodeSnippet';
import Example from './sandbox/src/TS';
const JS = require('!!raw-loader!./sandbox/src/JS.js').default;
const TS = require('!!raw-loader!./sandbox/src/TS.tsx').default;

const ExampleTable = () => {
return (
<SourceCodeSnippet
Component={Example}
javaScriptCode={JS}
typeScriptCode={TS}
tableId="row-actions-menu-items"
/>
);
};

export default ExampleTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example

To run this example:

- `npm install` or `yarn`
- `npm run start` or `yarn start`
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Material React Table Example</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "material-react-table-example-minimal",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite --port 3001",
"build": "vite build",
"serve": "vite preview",
"start": "vite"
},
"dependencies": {
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.4",
"material-react-table": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.0.1",
"typescript": "^4.9.4",
"vite": "^4.0.4"
}
}
Loading