Skip to content

Commit

Permalink
add an example of using the redux toolkit store
Browse files Browse the repository at this point in the history
  • Loading branch information
Salam-Dalloul committed Oct 8, 2024
1 parent 6cdb688 commit 694f8fb
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 66 deletions.
15 changes: 14 additions & 1 deletion examples/vite-redux-toolkit-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@fortawesome/fontawesome-free": "^6.6.0",
"@fortawesome/fontawesome-svg-core": "^6.6.0",
"@fortawesome/free-solid-svg-icons": "^6.6.0",
"@fortawesome/react-fontawesome": "^0.2.2",
"@material-ui/core": "^4.12.4",
"@metacell/geppetto-meta-client": "^2.0.0",
"@metacell/geppetto-meta-core": "^2.0.0",
Expand All @@ -26,10 +29,16 @@
"@react-three/fiber": "^8.17.9",
"@reduxjs/toolkit": "^2.2.7",
"@types/react-redux": "^7.1.34",
"ami.js": ">=0.32.0",
"file-saver": "^2.0.5",
"jszip": "^3.10.1",
"openseadragon": "^5.0.0",
"react": "^18.3.1",
"react-color": "^2.19.3",
"react-dom": "^18.3.1",
"react-redux": "^9.1.2",
"three": "^0.169.0"
"three": "^0.169.0",
"three-render-objects": "^1.29.5"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
Expand Down Expand Up @@ -59,5 +68,9 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"resolutions": {
"bezier-js": "4.0.3",
"three": "0.118.0"
}
}
1 change: 1 addition & 0 deletions examples/vite-redux-toolkit-react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import HomePage from "./pages/HomePage";
import { ThemeProvider, createTheme } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import MainLayout from "./components/MainLayout.tsx";
import '@metacell/geppetto-meta-ui/flex-layout/style/light.scss'

const darkTheme = createTheme({
palette: {
Expand Down
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;
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;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
threeDViewerWidget,
} from "../layoutManager/widgets.ts";
import { useDispatch } from "react-redux";
import "@metacell/geppetto-meta-ui/flex-layout/style/dark.scss";
import { FormControlLabel, FormGroup } from "@mui/material";
import Typography from "@mui/material/Typography";
import CustomSwitch from "./CustomSwitch.tsx";
Expand Down
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;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC } from "react";
import { Center } from "@react-three/drei";
import { useLoader } from "@react-three/fiber";
// @ts-ignore
import { STLLoader } from "three/examples/jsm/loaders/STLLoader";
import { BufferGeometry } from 'three';
import { Instance } from "./ThreeDViewer.tsx";
Expand All @@ -15,7 +16,7 @@ const STLViewer: FC<Props> = ({ instances, isWireframe }) => {
// TODO: Check if useLoader caches or do we need to do it ourselves
// @ts-expect-error Argument type STLLoader is not assignable to parameter type LoaderProto<T>
const stlObjects = useLoader<STLLoader, BufferGeometry[]>(STLLoader, instances.map(i => i.url));

return (
<Center>
<group frustumCulled={false}>
Expand Down
Loading

0 comments on commit 694f8fb

Please sign in to comment.