From 4cbc6fcbfaffc5aa2b2b364b0475c7123dd37ae6 Mon Sep 17 00:00:00 2001 From: Miriam Shams-Rainey Date: Fri, 16 Sep 2022 17:09:03 -0400 Subject: [PATCH] #513: Added Customizable Icons for Ratings Field --- src/components/fields/Rating/Settings.tsx | 113 +++++++++++++-------- src/components/fields/Rating/TableCell.tsx | 13 ++- 2 files changed, 84 insertions(+), 42 deletions(-) diff --git a/src/components/fields/Rating/Settings.tsx b/src/components/fields/Rating/Settings.tsx index 5504bd08..6b3cf710 100644 --- a/src/components/fields/Rating/Settings.tsx +++ b/src/components/fields/Rating/Settings.tsx @@ -1,48 +1,81 @@ import { ISettingsProps } from "@src/components/fields/types"; - -import { Slider, InputLabel, TextField, Grid } from "@mui/material"; +import RatingIcon from "@mui/icons-material/Star"; +import { Slider, InputLabel, TextField, Grid, FormControlLabel, Checkbox, Stack, Fab } from "@mui/material"; import ToggleButton from "@mui/material/ToggleButton"; import ToggleButtonGroup from "@mui/material/ToggleButtonGroup"; +import { get } from "lodash-es"; export default function Settings({ onChange, config }: ISettingsProps) { return ( - <> - - - { - onChange("max")(parseInt(e.target.value)); - }} - inputProps={{ min: 1, max: 20 }} - /> - - - Star fraction - { - onChange("precision")(value); - }} - aria-label="text alignment" - > - - 1/4 - - - 1/2 - - - 1 - - - + + + { + onChange("max")(parseInt(e.target.value)); + }} + inputProps={{ min: 1, max: 20 }} + /> - + + Star fraction + { + onChange("precision")(value); + }} + aria-label="text alignment" + > + + 1/4 + + + 1/2 + + + 1 + + + + + onChange("customIcons.enabled")(e.target.checked) + } + name="customIcons.enabled" + /> + } + label="Customize button icons with emoji" + style={{ marginLeft: -11 }} + /> + {config.customIcons?.enabled && ( + + + + + onChange("customIcons.rating")(e.target.value) + } + label="Rating:" + className="labelHorizontal" + inputProps={{ style: { width: "3ch" } }} + /> + + {get(config, "customIcons.rating") || } + + + + + )} + ); -} +} \ No newline at end of file diff --git a/src/components/fields/Rating/TableCell.tsx b/src/components/fields/Rating/TableCell.tsx index 34da84cf..bd4df1ca 100644 --- a/src/components/fields/Rating/TableCell.tsx +++ b/src/components/fields/Rating/TableCell.tsx @@ -1,7 +1,15 @@ import { IHeavyCellProps } from "@src/components/fields/types"; import MuiRating from "@mui/material/Rating"; -import StarBorderIcon from "@mui/icons-material/StarBorder"; +import RatingIcon from "@mui/icons-material/Star"; +import { get } from "lodash-es"; + + +const getStateIcon = (config: any) => { + // only use the config to get the custom rating icon if enabled via toggle + if (!get(config, "customIcons.enabled")) { return } + return get(config, "customIcons.rating") || ; +}; export default function Rating({ row, @@ -28,9 +36,10 @@ export default function Rating({ name={`${row.id}-${column.key}`} value={typeof value === "number" ? value : 0} onClick={(e) => e.stopPropagation()} + icon={getStateIcon(column.config)} disabled={disabled} onChange={(_, newValue) => onSubmit(newValue)} - emptyIcon={} + emptyIcon={getStateIcon(column.config)} max={max} precision={precision} sx={{ mx: -0.25 }}