-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an example of using the redux toolkit store
- Loading branch information
1 parent
6cdb688
commit 694f8fb
Showing
13 changed files
with
410 additions
and
66 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
47 changes: 47 additions & 0 deletions
47
examples/vite-redux-toolkit-react-app/src/components/ColorPicker.tsx
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,47 @@ | ||
import { Box } from "@mui/material"; | ||
import ChromePicker from "react-color"; | ||
|
||
const ColorPicker = ({ selectedColor, onChange }) => { | ||
return ( | ||
<Box | ||
sx={{ | ||
"& > div": { | ||
width: "100% !important", | ||
boxShadow: "none !important", | ||
background: "transparent !important", | ||
fontFamily: "'IBM Plex Sans',sans-serif !important", | ||
|
||
"& > div:last-of-type": { | ||
"& > div:first-of-type": { | ||
"& > div:first-of-type": { | ||
"& > div": { | ||
// border: `0.0625rem solid ${headerBorderLeftColor}`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"& svg": { | ||
"&:hover": { | ||
// background: `${headerBorderLeftColor} !important`, | ||
}, | ||
}, | ||
|
||
"& input": { | ||
// backgroundColor: `${headerBorderLeftColor} !important`, | ||
boxShadow: "none !important", | ||
// color: `${headingColor} !important`, | ||
"&:focus": { | ||
boxShadow: "none !important", | ||
outline: "none !important", | ||
}, | ||
}, | ||
}, | ||
}} | ||
> | ||
<ChromePicker color={selectedColor} onChange={onChange} /> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ColorPicker; |
81 changes: 81 additions & 0 deletions
81
examples/vite-redux-toolkit-react-app/src/components/CustomFormControlLabel.tsx
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,81 @@ | ||
import {Box, FormControlLabel, Stack, Typography} from "@mui/material"; | ||
import { vars } from "../theme/variables.ts"; | ||
import PickerWrapper from "./PickerWrapper.tsx"; | ||
import { useState } from "react"; | ||
|
||
const { gray600, gray50 } = vars; | ||
|
||
const CustomFormControlLabel = ({ label, color, handleColorChange }) => { | ||
const [selectedColor, setSelectedColor] = useState(color); | ||
const [anchorEl, setAnchorEl] = useState(null); | ||
const [open, setOpen] = useState(false); | ||
|
||
const handleChange = (color) => { | ||
setSelectedColor(color.hex); | ||
handleColorChange(color.hex); | ||
}; | ||
|
||
const handleClick = (event) => { | ||
setAnchorEl(event.currentTarget); | ||
setOpen(true); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<FormControlLabel | ||
control={ | ||
<Box | ||
sx={{ | ||
width: "1rem", | ||
height: ".8rem", | ||
backgroundColor: selectedColor, | ||
borderRadius: "0.2rem", | ||
cursor: "pointer", | ||
marginRight: '.5rem' | ||
}} | ||
onClick={handleClick} | ||
/> | ||
} | ||
sx={{ | ||
width: "100%", | ||
p: ".5rem .5rem .5rem .5rem", | ||
margin: 0, | ||
alignItems: "center", | ||
"&:hover": { | ||
background: gray50, | ||
borderRadius: ".5rem", | ||
}, | ||
"& .MuiFormControlLabel-label": { | ||
width: "100%", | ||
}, | ||
"& .MuiIconButton-root": { | ||
borderRadius: ".25rem", | ||
}, | ||
}} | ||
label={ | ||
<Box> | ||
<Stack | ||
direction="row" | ||
alignItems="center" | ||
width={1} | ||
spacing=".5rem" | ||
justifyContent="space-between" | ||
> | ||
<Typography color={gray600} variant="subtitle1"> | ||
{label} | ||
</Typography> | ||
</Stack> | ||
</Box> | ||
} | ||
/> | ||
<PickerWrapper handleColorChange={handleChange} selectedColor={selectedColor} onClose={handleClose} open={open} anchorEl={anchorEl} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default CustomFormControlLabel; |
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
37 changes: 37 additions & 0 deletions
37
examples/vite-redux-toolkit-react-app/src/components/PickerWrapper.tsx
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,37 @@ | ||
import { Popover } from "@mui/material"; | ||
import ColorPicker from "./ColorPicker"; | ||
|
||
const PickerWrapper = ({ open, anchorEl, onClose, handleColorChange, selectedColor }) => { | ||
return ( | ||
<Popover | ||
id={"id"} | ||
open={open} | ||
anchorEl={anchorEl} | ||
onClose={onClose} | ||
anchorOrigin={{ | ||
vertical: "top", | ||
horizontal: "right", | ||
}} | ||
transformOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "left", | ||
}} | ||
sx={{ | ||
"& .MuiPopover-paper": { | ||
width: "15.375rem", | ||
borderRadius: "0.5rem", | ||
height: "16rem", | ||
boxShadow: "0rem 0.5rem 0.5rem -0.25rem rgba(16, 24, 40, 0.03), 0rem 1.25rem 1.5rem -0.25rem rgba(16, 24, 40, 0.08)", | ||
|
||
"&:after": { | ||
display: "none", | ||
}, | ||
}, | ||
}} | ||
> | ||
<ColorPicker selectedColor={selectedColor} onChange={handleColorChange} /> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default PickerWrapper; |
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.