@@ -5,101 +5,158 @@ import React from 'react';
5
5
import { RootState } from '../../redux/store' ;
6
6
import { deleteElement } from '../../redux/reducers/slice/appStateSlice' ;
7
7
import { emitEvent } from '../../helperFunctions/socket' ;
8
+ import Accordion from '@mui/material/Accordion' ;
9
+ import AccordionSummary from '@mui/material/AccordionSummary' ;
10
+ import AccordionDetails from '@mui/material/AccordionDetails' ;
11
+ import ExpandMoreIcon from '@mui/icons-material/ExpandMore' ;
12
+ import { makeStyles } from '@mui/styles' ;
13
+ import ComponentDrag from './ComponentDrag' ;
8
14
9
- /*
10
- DESCRIPTION: This is the top half of the left panel, starting from the 'HTML
11
- Elements' header. The boxes containing each HTML element are rendered in
12
- HTMLItem, which itself is rendered by this component.
13
15
14
- Central state contains all available HTML elements (stored in the HTMLTypes property).
15
- The data for HTMLTypes is stored in HTMLTypes.tsx and is added to central state in
16
- initialState.tsx.
16
+ const useStyles = makeStyles ( {
17
+ accordion : {
18
+ backgroundColor : '#000000' , // Set the background color to gray
19
+ color : '#ffffff' , // Set the text color to white
20
+ } ,
21
+ accordionSummary : {
22
+ backgroundColor : '#000000' , // Set the background color of the summary to gray
23
+ color : '#ffffff' , // Set the text color of the summary to white
24
+ } ,
25
+ } ) ;
17
26
18
- Hook state:
19
- -tag:
20
- */
21
- // Extracted the drag and drop functionality from HTMLPanel to make a modular component that can hang wherever the future designers may choose.
22
27
const DragDropPanel = ( props ) : JSX . Element => {
28
+ const classes = useStyles ( ) ;
23
29
const dispatch = useDispatch ( ) ;
24
30
25
- const state = useSelector ( ( store : RootState ) => store . appState ) ; // current state
26
- const contextParam = useSelector ( ( store : RootState ) => store . contextSlice ) ; // current contextParam
27
- const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ; // current roomCode
31
+ const state = useSelector ( ( store : RootState ) => store . appState ) ;
32
+ const contextParam = useSelector ( ( store : RootState ) => store . contextSlice ) ;
33
+ const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ;
28
34
29
- // function for delete element
30
35
const handleDelete = ( id : number ) : void => {
31
36
dispatch ( deleteElement ( { id : id , contextParam : contextParam } ) ) ;
32
37
if ( roomCode ) {
33
- // send delete element to server to broadcast to all users
34
38
emitEvent ( 'deleteElementAction' , roomCode , {
35
39
id,
36
40
contextParam
37
41
} ) ;
38
42
}
39
43
} ;
40
44
41
- // filter out separator so that it will not appear on the html panel
42
45
const htmlTypesToRender = state . HTMLTypes . filter (
43
46
( type ) => type . name !== 'separator'
44
47
) ;
48
+
45
49
return (
46
50
< div className = { 'HTMLItems' } >
47
51
< div id = "HTMLItemsTopHalf" >
48
- < h3 style = { { color : '#ffffff' } } > HTML Elements </ h3 >
49
- < Grid
50
- container
51
- // spacing={{ xs: 0.5, md: 0.5 }}
52
- // columns={{ xs: 4, sm: 4, md: 4 }}
53
- justifyContent = "center"
54
- >
55
- { htmlTypesToRender . map ( ( option ) => {
56
- if (
57
- ! [ 'Switch' , 'LinkTo' , 'LinkHref' , 'Image' , 'Route' ] . includes (
58
- option . name
59
- )
60
- ) {
61
- return (
62
- < HTMLItem
63
- name = { option . name }
64
- key = { `html-${ option . name } ` }
65
- id = { option . id }
66
- icon = { option . icon }
67
- handleDelete = { handleDelete }
68
- />
69
- ) ;
70
- }
71
- } ) }
72
- </ Grid >
73
-
74
- { state . projectType === 'Classic React' ? (
75
- < h3 style = { { color : '#ffffff' } } > React Router</ h3 >
76
- ) : null }
77
- < Grid
78
- container
79
- // spacing={{ xs: 0.5, md: 0.5 }}
80
- // columns={{ xs: 4, sm: 4, md: 4 }}
81
- justifyContent = "center"
82
- >
83
- { htmlTypesToRender . map ( ( option ) => {
84
- if (
85
- ( option . name === 'Switch' ||
86
- option . name === 'LinkTo' ||
87
- option . name === 'Route' ) &&
88
- state . projectType === 'Classic React'
89
- ) {
90
- return (
91
- < HTMLItem
92
- name = { option . name }
93
- key = { `html-${ option . name } ` }
94
- id = { option . id }
95
- icon = { option . icon }
96
- handleDelete = { handleDelete }
97
- />
98
- ) ;
99
- }
100
- } ) }
101
- </ Grid >
102
-
52
+ < Accordion className = { classes . accordion } >
53
+ < AccordionSummary
54
+ expandIcon = { < ExpandMoreIcon /> }
55
+ aria-controls = "panel1a-content"
56
+ id = "panel1a-header"
57
+ className = { classes . accordionSummary }
58
+ >
59
+ < h3 > Root Components</ h3 >
60
+ </ AccordionSummary >
61
+ < AccordionDetails >
62
+ < ComponentDrag isVisible = { true } isThemeLight = { props . isThemeLight } />
63
+ </ AccordionDetails >
64
+ </ Accordion >
65
+ < Accordion className = { classes . accordion } >
66
+ < AccordionSummary
67
+ expandIcon = { < ExpandMoreIcon /> }
68
+ aria-controls = "panel1a-content"
69
+ id = "panel1a-header"
70
+ className = { classes . accordionSummary }
71
+ >
72
+ < h3 > HTML Elements</ h3 >
73
+ </ AccordionSummary >
74
+ < AccordionDetails >
75
+ < Grid container justifyContent = "center" >
76
+ { htmlTypesToRender . map ( ( option ) => {
77
+ if (
78
+ ! [ 'Switch' , 'LinkTo' , 'LinkHref' , 'Image' , 'Route' ] . includes (
79
+ option . name
80
+ )
81
+ ) {
82
+ return (
83
+ < HTMLItem
84
+ name = { option . name }
85
+ key = { `html-${ option . name } ` }
86
+ id = { option . id }
87
+ icon = { option . icon }
88
+ handleDelete = { handleDelete }
89
+ />
90
+ ) ;
91
+ }
92
+ } ) }
93
+ </ Grid >
94
+ </ AccordionDetails >
95
+ </ Accordion >
96
+
97
+ { /* MUI Components */ }
98
+ < Accordion className = { classes . accordion } >
99
+ < AccordionSummary
100
+ expandIcon = { < ExpandMoreIcon /> }
101
+ aria-controls = "panel2a-content"
102
+ id = "panel2a-header"
103
+ className = { classes . accordionSummary }
104
+ >
105
+ < h3 > MUI Components</ h3 >
106
+ </ AccordionSummary >
107
+ < AccordionDetails >
108
+ < Grid container justifyContent = "center" >
109
+ { htmlTypesToRender . map ( ( option ) => {
110
+ if ( option . name === 'MUI' ) {
111
+ return (
112
+ < HTMLItem
113
+ name = { option . name }
114
+ key = { `html-${ option . name } ` }
115
+ id = { option . id }
116
+ icon = { option . icon }
117
+ handleDelete = { handleDelete }
118
+ />
119
+ ) ;
120
+ }
121
+ } ) }
122
+ </ Grid >
123
+ </ AccordionDetails >
124
+ </ Accordion >
125
+
126
+ { /* React Router */ }
127
+ < Accordion className = { classes . accordion } >
128
+ < AccordionSummary
129
+ expandIcon = { < ExpandMoreIcon /> }
130
+ aria-controls = "panel1a-content"
131
+ id = "panel1a-header"
132
+ className = { classes . accordionSummary }
133
+ >
134
+ < h3 > React Router</ h3 >
135
+ </ AccordionSummary >
136
+ < AccordionDetails >
137
+ < Grid container justifyContent = "center" >
138
+ { htmlTypesToRender . map ( ( option ) => {
139
+ if (
140
+ ( option . name === 'Switch' ||
141
+ option . name === 'LinkTo' ||
142
+ option . name === 'Route' ) &&
143
+ state . projectType === 'Classic React'
144
+ ) {
145
+ return (
146
+ < HTMLItem
147
+ name = { option . name }
148
+ key = { `html-${ option . name } ` }
149
+ id = { option . id }
150
+ icon = { option . icon }
151
+ handleDelete = { handleDelete }
152
+ />
153
+ ) ;
154
+ }
155
+ } ) }
156
+ </ Grid >
157
+ </ AccordionDetails >
158
+ </ Accordion >
159
+
103
160
{ /* Next.js */ }
104
161
{ state . projectType === 'Next.js' ? (
105
162
< h3 style = { { color : 'C6C6C6' } } > Next.js</ h3 >
@@ -126,3 +183,4 @@ const DragDropPanel = (props): JSX.Element => {
126
183
} ;
127
184
128
185
export default DragDropPanel ;
186
+
0 commit comments