From 92bc264492a31e29a31d243907d7556a36973ccd Mon Sep 17 00:00:00 2001 From: shams mosowi Date: Tue, 10 Sep 2019 22:46:40 +1000 Subject: [PATCH] setup columns drawer --- src/components/ColumnDrawer.tsx | 114 ++++++++++++++++++++++++++++++++ src/components/Table.tsx | 42 ++++++++---- 2 files changed, 142 insertions(+), 14 deletions(-) create mode 100644 src/components/ColumnDrawer.tsx diff --git a/src/components/ColumnDrawer.tsx b/src/components/ColumnDrawer.tsx new file mode 100644 index 00000000..8a878a59 --- /dev/null +++ b/src/components/ColumnDrawer.tsx @@ -0,0 +1,114 @@ +import React, { useState, useEffect } from "react"; +import { makeStyles } from "@material-ui/core/styles"; +import Drawer from "@material-ui/core/Drawer"; +import List from "@material-ui/core/List"; +import Divider from "@material-ui/core/Divider"; +import ListItem from "@material-ui/core/ListItem"; +import ListItemIcon from "@material-ui/core/ListItemIcon"; +import ListItemText from "@material-ui/core/ListItemText"; +import MailIcon from "@material-ui/icons/Mail"; +import CheckBoxIcon from "@material-ui/icons/CheckBox"; +import SimpleTextIcon from "@material-ui/icons/TextFields"; +import LongTextIcon from "@material-ui/icons/Notes"; +import AddIcon from "@material-ui/icons/Add"; +import PhoneIcon from "@material-ui/icons/Phone"; + +import IconButton from "@material-ui/core/IconButton"; +import TextField from "@material-ui/core/TextField"; +import _camelCase from "lodash/camelCase"; + +const FIELDS = [ + { icon: , name: "Simple Text", type: "SIMPLE_TEXT" }, + { icon: , name: "Long Text", type: "LONG_TEXT" }, + { icon: , name: "Email", type: "EMAIL" }, + { icon: , name: "Phone", type: "PHONE_NUMBER" }, + { icon: , name: "Check Box", type: "CHECK_BOX" } +]; +const useStyles = makeStyles({ + list: { + width: 250 + }, + fields: { + padding: 15 + }, + + fullList: { + width: "auto" + } +}); + +export default function ColumnDrawer() { + const classes = useStyles(); + const [drawerState, toggleDrawer] = useState(false); + const [columnName, setColumnName] = useState(""); + const [fieldName, setFieldName] = useState(""); + useEffect(() => { + setFieldName(_camelCase(columnName)); + }, [columnName]); + const sideList = () => ( +
{ + toggleDrawer(false); + }} + > + + { + setColumnName(e.target.value); + }} + margin="dense" + id="name" + label="Table Name" + type="text" + fullWidth + /> + { + setFieldName(e.target.value); + }} + margin="dense" + id="field" + label="Field Name" + type="text" + fullWidth + /> + + + + {FIELDS.map((field: any) => ( + + {field.icon} + + + ))} + +
+ ); + + return ( +
+ { + toggleDrawer(true); + }} + > + + + + { + toggleDrawer(false); + }} + > + {sideList()} + +
+ ); +} diff --git a/src/components/Table.tsx b/src/components/Table.tsx index 96e39da9..187aeb01 100644 --- a/src/components/Table.tsx +++ b/src/components/Table.tsx @@ -16,9 +16,10 @@ import { TableHeaderProps } from "react-virtualized"; import Button from "@material-ui/core/Button"; -import EditIcon from "@material-ui/icons/Edit"; -// import Skeleton from "@material-ui/lab/Skeleton"; +import { TextField } from "@material-ui/core"; + +import ColumnDrawer from "./ColumnDrawer"; const styles = (theme: Theme) => createStyles({ @@ -95,13 +96,19 @@ class MuiVirtualizedTable extends React.PureComponent< : "left" } > - {cellData} + { + console.log(columnIndex); + }} + /> ); }; headerRenderer = ({ label, + dataKey, columnIndex }: TableHeaderProps & { columnIndex: number }) => { const { headerHeight, columns, classes } = this.props; @@ -118,9 +125,14 @@ class MuiVirtualizedTable extends React.PureComponent< style={{ height: headerHeight }} align={columns[columnIndex].numeric || false ? "right" : "left"} > - + {dataKey === "add" ? ( + + ) : ( + + )} ); }; @@ -174,20 +186,22 @@ const VirtualizedTable = withStyles(styles)(MuiVirtualizedTable); export default function fTable(props: any) { const { columns, rows } = props; - console.log(columns, rows); if (columns) return ( rows[index]} - columns={columns.map( - (column: { fieldName: string; name: string; type: string }) => ({ - width: 200, - label: column.name, - dataKey: column.fieldName - }) - )} + columns={[ + ...columns.map( + (column: { fieldName: string; name: string; type: string }) => ({ + width: 200, + label: column.name, + dataKey: column.fieldName + }) + ), + { width: 20, label: "add", dataKey: "add" } + ]} /> );