forked from intrig-unicamp/paths-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#17: Creates dialog to change label and color on dynamic mode
- Loading branch information
1 parent
0822806
commit c1ecbb4
Showing
8 changed files
with
202 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { Box } from "@mui/material"; | ||
import Button from "@mui/material/Button"; | ||
import Dialog from "@mui/material/Dialog"; | ||
import DialogActions from "@mui/material/DialogActions"; | ||
import DialogContent from "@mui/material/DialogContent"; | ||
import DialogTitle from "@mui/material/DialogTitle"; | ||
import TextField from "@mui/material/TextField"; | ||
import { FunctionComponent, useEffect, useState } from "react"; | ||
import ColorPicker from "../ColorPicker/ColorPicker"; | ||
|
||
interface EntityDialogProps { | ||
open: boolean; | ||
setOpen: (open: boolean) => void; | ||
label: string; | ||
setLabel: (label: string) => void; | ||
color: string; | ||
setColor: (color: string) => void; | ||
} | ||
const EntityDialog: FunctionComponent<EntityDialogProps> = ({ | ||
open, | ||
setOpen, | ||
label, | ||
setLabel, | ||
color, | ||
setColor, | ||
}) => { | ||
const [currentColor, setCurrentColor] = useState<string>(""); | ||
const [currentLabel, setCurrentLabel] = useState<string>(""); | ||
|
||
useEffect(() => { | ||
setCurrentColor(color); | ||
setCurrentLabel(label); | ||
}, [open]); | ||
|
||
const handleSubmit = () => { | ||
setColor(currentColor); | ||
setLabel(currentLabel); | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Dialog open={open} onClose={() => setOpen(false)}> | ||
<DialogTitle>Edit entity</DialogTitle> | ||
|
||
<DialogContent> | ||
<Box | ||
component="form" | ||
onSubmit={handleSubmit} | ||
noValidate | ||
sx={{ mt: 1 }} | ||
> | ||
<div | ||
style={{ | ||
display: "flex", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
justifyContent: "space-between", | ||
}} | ||
> | ||
<div style={{ justifyContent: "flex-start", paddingRight: 8 }}> | ||
<ColorPicker | ||
selectedColor={currentColor} | ||
onChangeColor={(evt) => setCurrentColor(evt.target.value)} | ||
/> | ||
</div> | ||
<TextField | ||
id="label" | ||
name="label" | ||
label="Label" | ||
size="small" | ||
value={currentLabel} | ||
required | ||
autoFocus | ||
onChange={(evt) => setCurrentLabel(evt.target.value)} | ||
sx={{ alignSelf: "center" }} | ||
/> | ||
</div> | ||
<Button | ||
onClick={handleSubmit} | ||
type="button" | ||
fullWidth | ||
variant="contained" | ||
> | ||
Save | ||
</Button> | ||
</Box> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={() => setOpen(false)}>Cancel</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</div> | ||
); | ||
}; | ||
|
||
export default EntityDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const Colors = { | ||
Gray: "#212529", | ||
Red: "#c92a2a", | ||
Pink: "#a61e4d", | ||
Grape: "#862e9c", | ||
Violet: "#5f3dc4", | ||
Indigo: "#364fc7", | ||
Blue: "#1864ab", | ||
Cyan: "#0b7285", | ||
Teal: "#087f5b", | ||
Green: "#2b8a3e", | ||
Lime: "#5c940d", | ||
Yellow: "#e67700", | ||
Orange: "#d9480f", | ||
}; | ||
|
||
export const getRandomColor = (): string => { | ||
const colors = Object.keys(Colors); | ||
const index = Math.floor(Math.random() * colors.length); | ||
const key = colors[index]; | ||
|
||
return Colors[key]; | ||
}; |