-
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.
- Loading branch information
1 parent
6c5b9f7
commit c4b9ba0
Showing
9 changed files
with
398 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Box from "@mui/material/Box"; | ||
import { styled } from "@mui/material/styles"; | ||
|
||
interface ColorBoxProps { | ||
color: string; | ||
} | ||
|
||
const ColorBox = styled(Box, { | ||
shouldForwardProp: (prop) => prop !== "color" | ||
})<ColorBoxProps>(({ theme, color }) => ({ | ||
width: 24, | ||
height: 24, | ||
backgroundColor: color, | ||
borderRadius: "50%", | ||
borderColor: theme.palette.text.primary, | ||
borderWidth: 2, | ||
borderStyle: "solid" | ||
})); | ||
|
||
export default ColorBox; |
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,103 @@ | ||
import { FC } from "react"; | ||
|
||
import Box from "@mui/material/Box"; | ||
import Grid from "@mui/material/Grid"; | ||
import Modal from "@mui/material/Modal"; | ||
import Typography from "@mui/material/Typography"; | ||
import { | ||
blue, | ||
green, | ||
amber, | ||
red, | ||
cyan, | ||
teal, | ||
deepOrange, | ||
indigo, | ||
yellow, | ||
lightBlue, | ||
orange, | ||
lime, | ||
deepPurple, | ||
lightGreen, | ||
pink, | ||
purple | ||
} from "@mui/material/colors"; | ||
import { useTheme } from "@mui/material/styles"; | ||
|
||
import ModalBox from "@components/ModalBox"; | ||
|
||
const colors = [ | ||
red, | ||
deepOrange, | ||
orange, | ||
amber, | ||
yellow, | ||
lime, | ||
lightGreen, | ||
green, | ||
teal, | ||
cyan, | ||
lightBlue, | ||
blue, | ||
indigo, | ||
deepPurple, | ||
purple, | ||
pink | ||
]; | ||
|
||
const MaterialColorPicker: FC<{ | ||
isOpen: boolean; | ||
setState: (isOpen: boolean) => void; | ||
selectedColor: string; | ||
setColor: (color: string) => void; | ||
}> = ({ setState, isOpen, selectedColor, setColor }) => { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Modal | ||
open={isOpen} | ||
onClose={() => setState(false)} | ||
aria-labelledby="color-picker" | ||
aria-describedby="Pick a material color" | ||
component="div" | ||
> | ||
<ModalBox> | ||
<Typography gutterBottom variant="h4"> | ||
Pick a color | ||
</Typography> | ||
<Grid container spacing={1} columns={12}> | ||
{colors.map((color, i) => ( | ||
<Grid item key={i}> | ||
{Object.values(color) | ||
.slice(0, 10) | ||
.map((shade, i) => ( | ||
<Box | ||
onClick={() => setColor(shade)} | ||
key={i} | ||
sx={{ | ||
width: 24, | ||
height: 24, | ||
backgroundColor: shade, | ||
borderRadius: "50%", | ||
border: | ||
shade == selectedColor | ||
? { | ||
borderColor: theme.palette.text.primary, | ||
borderWidth: 2, | ||
borderStyle: "solid" | ||
} | ||
: null, | ||
cursor: "pointer", | ||
mb: 1 | ||
}} | ||
></Box> | ||
))} | ||
</Grid> | ||
))} | ||
</Grid> | ||
</ModalBox> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default MaterialColorPicker; |
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,17 @@ | ||
import Box from "@mui/material/Box"; | ||
|
||
import styled from "@mui/system/styled"; | ||
|
||
const ModalBox = styled(Box)(({ theme }) => ({ | ||
padding: "2rem", | ||
position: "absolute", | ||
left: "50%", | ||
top: "50%", | ||
transform: "translate(-50%, -50%)", | ||
minWidth: "20rem", | ||
backgroundColor: theme.palette.background.paper, | ||
borderRadius: 5, | ||
outline: "none" | ||
})); | ||
|
||
export default ModalBox; |
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
Oops, something went wrong.