|
1 | | -import ComponentPanelItem from '../right/ComponentPanelItem'; |
2 | | -import Grid from '@mui/material/Grid'; |
3 | | -import React from 'react'; |
4 | | -import { RootState } from '../../redux/store'; |
5 | | -import makeStyles from '@mui/styles/makeStyles'; |
6 | | -import { useSelector } from 'react-redux'; |
7 | | - |
8 | | -const ComponentDrag = ({ isThemeLight }): JSX.Element => { |
9 | | - const classes = useStyles(); |
10 | | - const state = useSelector((store: RootState) => store.appState); |
11 | | - |
12 | | - const isFocus = (targetId: Number) => { |
13 | | - return state.canvasFocus.componentId === targetId ? true : false; |
14 | | - }; |
15 | | - |
16 | | - return ( |
17 | | - <div className={classes.panelWrapper}> |
18 | | - <div className={classes.panelWrapperList}> |
19 | | - <h4 className={classes.darkThemeFontColor}> |
20 | | - {state.projectType === 'Next.js' || state.projectType === 'Gatsby.js' |
21 | | - ? 'Pages' |
22 | | - : 'Root Components'} |
23 | | - </h4> |
24 | | - <Grid |
25 | | - container |
26 | | - direction="row" |
27 | | - justifyContent="center" |
28 | | - alignItems="center" |
29 | | - > |
30 | | - {state.components |
31 | | - .filter((comp) => state.rootComponents.includes(comp.id)) |
32 | | - .map((comp) => { |
33 | | - return ( |
34 | | - <ComponentPanelItem |
35 | | - isFocus={isFocus(comp.id)} |
36 | | - key={`comp-${comp.id}`} |
37 | | - name={comp.name} |
38 | | - id={comp.id} |
39 | | - root={true} |
40 | | - isThemeLight={isThemeLight} |
41 | | - /> |
42 | | - ); |
43 | | - })} |
44 | | - </Grid> |
45 | | - </div> |
46 | | - </div> |
47 | | - ); |
48 | | -}; |
49 | | - |
50 | | -const useStyles = makeStyles({ |
51 | | - panelWrapper: { |
52 | | - display: 'flex', |
53 | | - flexDirection: 'column', |
54 | | - alignItems: 'center', |
55 | | - flexGrow: 1, |
56 | | - overflow: 'auto' |
57 | | - }, |
58 | | - panelWrapperList: { |
59 | | - minHeight: '120px' |
60 | | - }, |
61 | | - lightThemeFontColor: { |
62 | | - color: '#fff' |
63 | | - }, |
64 | | - darkThemeFontColor: { |
65 | | - color: '#fff' |
66 | | - } |
67 | | -}); |
68 | | - |
69 | | -export default ComponentDrag; |
| 1 | +import React from 'react'; |
| 2 | +import Grid from '@mui/material/Grid'; |
| 3 | +import { RootState } from '../../redux/store'; |
| 4 | +import makeStyles from '@mui/styles/makeStyles'; |
| 5 | +import { useSelector } from 'react-redux'; |
| 6 | +import ComponentPanelItem from '../right/ComponentPanelItem'; |
| 7 | + |
| 8 | + |
| 9 | +const useStyles = makeStyles({ |
| 10 | + panelWrapper: { |
| 11 | + display: 'flex', |
| 12 | + flexDirection: 'column', |
| 13 | + alignItems: 'center', |
| 14 | + flexGrow: 1, |
| 15 | + overflow: 'auto' |
| 16 | + }, |
| 17 | + panelWrapperList: { |
| 18 | + minHeight: 'auto' |
| 19 | + }, |
| 20 | + lightThemeFontColor: { |
| 21 | + color: '#fff' |
| 22 | + }, |
| 23 | + darkThemeFontColor: { |
| 24 | + color: '#fff' |
| 25 | + } |
| 26 | +}); |
| 27 | + |
| 28 | +const ComponentDrag = ({ isVisible, isThemeLight }): JSX.Element | null => { |
| 29 | + const classes = useStyles(); |
| 30 | + const state = useSelector((store: RootState) => store.appState); |
| 31 | + |
| 32 | + const isFocus = (targetId: Number) => { |
| 33 | + return state.canvasFocus.componentId === targetId ? true : false; |
| 34 | + }; |
| 35 | + |
| 36 | + if (!isVisible) return null; |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className={classes.panelWrapper}> |
| 40 | + <div className={classes.panelWrapperList}> |
| 41 | + <h4 className={classes.darkThemeFontColor}> |
| 42 | + {state.projectType === 'Next.js' || state.projectType === 'Gatsby.js' |
| 43 | + ? 'Pages' |
| 44 | + : ''} |
| 45 | + </h4> |
| 46 | + <Grid |
| 47 | + container |
| 48 | + direction="row" |
| 49 | + justifyContent="center" |
| 50 | + alignItems="center" |
| 51 | + > |
| 52 | + {state.components |
| 53 | + .filter((comp) => state.rootComponents.includes(comp.id)) |
| 54 | + .map((comp) => { |
| 55 | + return ( |
| 56 | + <ComponentPanelItem |
| 57 | + isFocus={isFocus(comp.id)} |
| 58 | + key={`comp-${comp.id}`} |
| 59 | + name={comp.name} |
| 60 | + id={comp.id} |
| 61 | + root={true} |
| 62 | + isThemeLight={isThemeLight} |
| 63 | + /> |
| 64 | + ); |
| 65 | + })} |
| 66 | + </Grid> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + ); |
| 70 | +}; |
| 71 | + |
| 72 | +export default ComponentDrag; |
| 73 | + |
0 commit comments