From 1c64e18d3ebe9d7ee847ca005ff453c55504bc0d Mon Sep 17 00:00:00 2001 From: Shams mosowi Date: Tue, 19 Jan 2021 13:39:35 +0800 Subject: [PATCH] single select settings --- .../fields/SingleSelect/Settings.tsx | 103 ++++++++++++++++++ .../components/fields/SingleSelect/index.tsx | 5 + 2 files changed, 108 insertions(+) create mode 100644 www/src/components/fields/SingleSelect/Settings.tsx diff --git a/www/src/components/fields/SingleSelect/Settings.tsx b/www/src/components/fields/SingleSelect/Settings.tsx new file mode 100644 index 00000000..d77e3165 --- /dev/null +++ b/www/src/components/fields/SingleSelect/Settings.tsx @@ -0,0 +1,103 @@ +import React,{useState} from "react"; +import SettingsHeading from "components/Table/ColumnMenu/Settings/SettingsHeading"; +import _sortBy from "lodash/sortBy"; +import { createStyles, makeStyles } from "@material-ui/core/styles"; +import TextField from "@material-ui/core/TextField"; +import Grid from "@material-ui/core/Grid"; +import _includes from "lodash/includes"; +import _camelCase from "lodash/camelCase"; +import AddIcon from "@material-ui/icons/AddCircle"; +import IconButton from "@material-ui/core/IconButton"; +import Typography from '@material-ui/core/Typography'; +import Divider from '@material-ui/core/Divider'; +import RemoveIcon from "@material-ui/icons/CancelRounded"; +const useStyles = makeStyles((Theme) => + createStyles({ + root: {}, + field: { + width: "100%", + }, + optionsList :{ + maxHeight:150, + overflowX:'scroll' + } + }) +); + +const Settings = ({ handleChange, config }) => { + + const options = config.options ?? [] + const classes = useStyles(); + const [newOption, setNewOption] = useState(""); + const handleAdd = () => { + if (newOption.trim() !== "") { + handleChange('options')([...options, newOption.trim()]); + setNewOption(""); + } + }; + const handleDelete = (optionToDelete: string) => () => + handleChange('options')(options.filter((option: string) => option !== optionToDelete)); + + return ( + <> + Single Select Config +
+ {options?.map((option:string) => + <> + + + {option} + + + + { + handleDelete(option); + }} + > + {} + + + + + + )} + +
+ + + + { + handleAdd(); + }} + > + {} + + + + + { + setNewOption(e.target.value); + }} + onKeyPress={(e: any) => { + if (e.key === "Enter") { + handleAdd(); + } + }}/> + + + + + + ); +}; + +export default Settings; diff --git a/www/src/components/fields/SingleSelect/index.tsx b/www/src/components/fields/SingleSelect/index.tsx index 68641e38..0ac1c226 100644 --- a/www/src/components/fields/SingleSelect/index.tsx +++ b/www/src/components/fields/SingleSelect/index.tsx @@ -16,6 +16,10 @@ const SideDrawerField = lazy( "./SideDrawerField" /* webpackChunkName: "SideDrawerField-SingleSelect" */ ) ); +const Settings = lazy( + () => import("./Settings" /* webpackChunkName: "Settings-SingleSelect" */) +); + export const config: IFieldConfig = { type: FieldType.singleSelect, @@ -32,5 +36,6 @@ export const config: IFieldConfig = { }), TableEditor: NullEditor, SideDrawerField, + settings:Settings }; export default config;