link-stack/packages/ui/components/List.tsx

91 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-03-17 12:58:25 +01:00
"use client";
import { FC } from "react";
import { Grid, Box } from "@mui/material";
import { DataGridPro, GridColDef } from "@mui/x-data-grid-pro";
import { typography } from "../styles/theme";
interface ListProps {
title: string;
rows: any;
columns: GridColDef<any>[];
2024-04-21 20:47:55 +02:00
onRowClick?: (id: string) => void;
2024-03-17 12:58:25 +01:00
buttons?: React.ReactNode;
}
2024-04-21 20:47:55 +02:00
export const List: FC<ListProps> = ({
title,
rows,
columns,
2024-04-23 13:36:51 +02:00
onRowClick,
2024-04-21 20:47:55 +02:00
buttons,
}) => {
2024-03-17 12:58:25 +01:00
const { h3 } = typography;
return (
<Box sx={{ height: "100vh", backgroundColor: "#ddd", p: 3 }}>
<Grid container direction="column">
<Grid item container direction="row" justifyContent="space-between">
<Grid item>
<Box sx={h3}>{title}</Box>
</Grid>
2024-04-21 20:47:55 +02:00
<Grid item>{buttons}</Grid>
2024-03-17 12:58:25 +01:00
</Grid>
<Grid item>
<Box
sx={{
2024-04-23 13:36:51 +02:00
mt: 2,
2024-03-17 12:58:25 +01:00
backgroundColor: "#ddd",
border: 0,
width: "100%",
2024-04-23 13:36:51 +02:00
height: "calc(100vh - 100px)",
2024-03-17 12:58:25 +01:00
".MuiDataGrid-row": {
cursor: "pointer",
"&:hover": {
backgroundColor: "#1982fc33 !important",
fontWeight: "bold",
},
},
".MuiDataGrid-row:nth-of-type(1n)": {
backgroundColor: "#f3f3f3",
},
".MuiDataGrid-row:nth-of-type(2n)": {
backgroundColor: "#fff",
},
".MuiDataGrid-columnHeaderTitle": {
color: "#333",
fontWeight: "bold",
fontSize: 11,
margin: "0 auto",
},
".MuiDataGrid-columnHeader": {
backgroundColor: "#ccc",
border: 0,
borderBottom: "3px solid #ddd",
},
}}
>
<DataGridPro
rows={rows}
columns={columns}
density="compact"
pagination
initialState={{
pagination: { paginationModel: { pageSize: 25 } },
}}
pageSizeOptions={[5, 10, 25]}
paginationMode="client"
2024-04-23 13:36:51 +02:00
sx={{ height: "100%" }}
2024-03-17 12:58:25 +01:00
rowHeight={46}
scrollbarSize={0}
disableVirtualization
disableColumnMenu
2024-04-23 13:36:51 +02:00
onRowClick={(row: any) => onRowClick?.(row.id)}
2024-03-17 12:58:25 +01:00
/>
</Box>
</Grid>
</Grid>
</Box>
);
};