这是indexloc提供的服务,不要输入任何密码
Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Connect to your database, manage data in table-UI with role based access control

Set up Rowy on your Google Cloud Platform project with this easy deploy button.

[![Run on Google Cloud](https://deploy.cloud.run/button.svg)](https://deploy.rowy.app/)
[<img width="250" alt="Guided quick start button" src="https://user-images.githubusercontent.com/307298/185548050-e9208fb6-fe53-4c84-bbfa-53c08e03c15f.png">](https://rowy.app/)

https://deploy.rowy.app/
https://rowy.app

## Documentation

Expand Down Expand Up @@ -91,7 +91,7 @@ https://user-images.githubusercontent.com/307298/157185793-f67511cd-7b7b-4229-95

Set up Rowy on your Google Cloud project with this one-click deploy button. Your data and cloud functions stay on your own Firestore/GCP.

[![Run on Google Cloud](https://deploy.cloud.run/button.svg)](https://deploy.rowy.app/)
[![Run on Google Cloud](https://deploy.cloud.run/button.svg)](https://rowy.app/)

The one-click deploy makes the process of setting up easy with a step by step
guide and ensures your project is setup correctly.
Expand Down
127 changes: 87 additions & 40 deletions src/components/fields/Rating/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,95 @@
import { ISettingsProps } from "@src/components/fields/types";

import { Slider, InputLabel, TextField, Grid } from "@mui/material";
import RatingIcon from "@mui/icons-material/Star";
import RatingOutlineIcon from "@mui/icons-material/StarBorder"
import { InputLabel, TextField, Grid, FormControlLabel, Checkbox, Stack } from "@mui/material";
import ToggleButton from "@mui/material/ToggleButton";
import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
import MuiRating from "@mui/material/Rating";
import { get } from "lodash-es";

export default function Settings({ onChange, config }: ISettingsProps) {
return (
<>
<Grid container spacing={2} justifyItems="end" direction={"row"}>
<Grid item xs={6}>
<TextField
label="Maximum number of stars"
type={"number"}
value={config.max}
fullWidth
onChange={(e) => {
onChange("max")(parseInt(e.target.value));
}}
inputProps={{ min: 1, max: 20 }}
/>
</Grid>
<Grid item xs={6}>
<InputLabel>Star fraction</InputLabel>
<ToggleButtonGroup
value={config.precision}
exclusive
fullWidth
onChange={(_, value) => {
onChange("precision")(value);
}}
aria-label="text alignment"
>
<ToggleButton value={0.25} aria-label="quarter">
1/4
</ToggleButton>
<ToggleButton value={0.5} aria-label="half">
1/2
</ToggleButton>
<ToggleButton value={1} aria-label="whole">
1
</ToggleButton>
</ToggleButtonGroup>
</Grid>
<Grid container spacing={2} justifyItems="end" direction={"row"}>
<Grid item xs={6}>
<TextField
label="Highest possible rating"
type={"number"}
value={config.max}
fullWidth
error={false}
onChange={(e) => {
let input = parseInt(e.target.value) || 0
if (input > 20) { input = 20 }
onChange("max")(input);
}}
/>
</Grid>
<Grid item xs={6}>
<InputLabel>Rating fraction</InputLabel>
<ToggleButtonGroup
value={config.precision}
exclusive
fullWidth
onChange={(_, value) => {
onChange("precision")(value);
}}
aria-label="text alignment"
sx={{ pt: 0.5 }}
>
<ToggleButton value={0.25} aria-label="quarter">
1/4
</ToggleButton>
<ToggleButton value={0.5} aria-label="half">
1/2
</ToggleButton>
<ToggleButton value={1} aria-label="whole">
1
</ToggleButton>
</ToggleButtonGroup>
</Grid>
</>
<Grid item xs={6}>
<FormControlLabel
control={
<Checkbox
checked={config.customIcons?.enabled}
onChange={(e) =>
onChange("customIcons.enabled")(e.target.checked)
}
name="customIcons.enabled"
/>
}
label="Customize ratings with emoji"
style={{ marginLeft: -11 }}
/>
</Grid>
{config.customIcons?.enabled && (
<Grid item xs={6} sm={true}>
<Stack direction="row" spacing={1}>
<TextField
id="customIcons.rating"
value={get(config, "customIcons.rating")}
onChange={(e) =>
onChange("customIcons.rating")(e.target.value)
}
label="Custom icon preview:"
className="labelHorizontal"
inputProps={{ style: { width: "2ch" } }}
/>

<MuiRating aria-label="Preview of the rating field with custom icon"
name="Preview"
onClick={(e) => e.stopPropagation()}
icon={get(config, "customIcons.rating") || <RatingIcon />}
size="small"
emptyIcon={get(config, "customIcons.rating") || <RatingOutlineIcon />}
max={get(config, "max")}
precision={get(config, "precision")}
sx={{ pt: 0.5 }}
/>
</Stack>

</Grid>
)}
</Grid>
);
}
}
9 changes: 5 additions & 4 deletions src/components/fields/Rating/SideDrawerField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { ISideDrawerFieldProps } from "@src/components/fields/types";
import { Grid } from "@mui/material";
import { Rating as MuiRating } from "@mui/material";
import "@mui/lab";
import StarBorderIcon from "@mui/icons-material/StarBorder";

import { fieldSx, getFieldId } from "@src/components/SideDrawer/utils";
import { getStateIcon, getStateOutline } from "./TableCell";
import { fieldSx } from "@src/components/SideDrawer/utils";

export default function Rating({
column,
Expand All @@ -29,7 +28,9 @@ export default function Rating({
onChange(newValue);
onSubmit();
}}
emptyIcon={<StarBorderIcon fontSize="inherit" />}
icon={getStateIcon(column.config)}
emptyIcon={getStateOutline(column.config)}
size="small"
max={max}
precision={precision}
sx={{ ml: -0.5 }}
Expand Down
20 changes: 18 additions & 2 deletions src/components/fields/Rating/TableCell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
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 RatingOutlineIcon from "@mui/icons-material/StarBorder"
import { get } from "lodash-es";


export const getStateIcon = (config: any) => {
// only use the config to get the custom rating icon if enabled via toggle
if (!get(config, "customIcons.enabled")) { return <RatingIcon /> }
return get(config, "customIcons.rating") || <RatingIcon />;
};

export const getStateOutline = (config: any) => {
if (!get(config, "customIcons.enabled")) { return <RatingOutlineIcon /> }
return get(config, "customIcons.rating") || <RatingOutlineIcon />;
}

export default function Rating({
row,
Expand All @@ -28,9 +42,11 @@ export default function Rating({
name={`${row.id}-${column.key}`}
value={typeof value === "number" ? value : 0}
onClick={(e) => e.stopPropagation()}
icon={getStateIcon(column.config)}
size="small"
disabled={disabled}
onChange={(_, newValue) => onSubmit(newValue)}
emptyIcon={<StarBorderIcon />}
emptyIcon={getStateOutline(column.config)}
max={max}
precision={precision}
sx={{ mx: -0.25 }}
Expand Down