Skip to content

Commit 60a0c49

Browse files
committed
Added toggle on focus functionality for component cards
1 parent 227b399 commit 60a0c49

File tree

1 file changed

+59
-37
lines changed

1 file changed

+59
-37
lines changed

src/components/LeftColExpansionPanel.tsx

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const LeftColExpansionPanel = (props: any) => {
3636
return focusComponent.id === id ? 'focused' : '';
3737
}
3838

39+
// boolean flag to determine if the component card is focused or not
40+
// state/class toggles will be displayed when a component is focused
41+
const focusedToggle = isFocused() === 'focused' ? true : false;
42+
3943
return (
4044
<Grid
4145
container
@@ -48,7 +52,8 @@ const LeftColExpansionPanel = (props: any) => {
4852
<div
4953
className={classes.root}
5054
style={
51-
!isFocused() ? {} : { boxShadow: '0 10px 10px rgba(0,0,0,0.25)' }
55+
// shadow to highlight the focused component card
56+
focusedToggle ? { boxShadow: '4px 4px 4px rgba(0, 0, 0, .4)' } : {}
5257
}
5358
>
5459
<Grid item xs={12} style={{ color: 'red', backgroundColor: color }}>
@@ -75,40 +80,16 @@ const LeftColExpansionPanel = (props: any) => {
7580
>
7681
{title}
7782
</Typography>
78-
{/* TOGGLE FOR STATEFULNESS */}
79-
<InputLabel
80-
htmlFor='stateful'
81-
style={{
82-
color: '#fff',
83-
marginBottom: '10px',
84-
marginTop: '0px',
85-
marginLeft: '11px',
86-
padding: '0px',
87-
fontSize: '18px'
88-
}}
89-
>
90-
State?
91-
</InputLabel>
92-
{/*
93-
Have to change focus component after toggling state
94-
in order to properly change the code that appears in the code
95-
peview
83+
84+
{/* ALL OF THE STATE/CLASS TOGGLES AND LABELS ARE ONLY RENDERED IF THEIR COMPONENT IS THE FOCUSED COMPONENT
85+
86+
TO DO : IMPROVE DRYNESS OF CODE BY RENDERING ALL FOUR MATERIAL ELEMENTS (LABELS/SWITCH) IN ONE CONDITIONAL
9687
*/}
97-
<Switch
98-
checked={stateful}
99-
onChange={e => {
100-
toggleComponentState(id);
101-
changeFocusComponent(title);
102-
}}
103-
value='stateful'
104-
color='primary'
105-
id={props.id.toString()}
106-
// id={props.index.toString()}
107-
/>
108-
<div>
109-
{/* TOGGLE FOR CLASS BASED */}
88+
89+
{/* LABEL AND TOGGLE(SWITCH) FOR STATEFULNESS */}
90+
{focusedToggle ? (
11091
<InputLabel
111-
htmlFor='classBased'
92+
htmlFor='stateful'
11293
style={{
11394
color: '#fff',
11495
marginBottom: '10px',
@@ -118,17 +99,58 @@ const LeftColExpansionPanel = (props: any) => {
11899
fontSize: '18px'
119100
}}
120101
>
121-
Class?
102+
State?
122103
</InputLabel>
104+
) : (
105+
''
106+
)}
107+
108+
{focusedToggle ? (
123109
<Switch
124-
checked={classBased}
110+
checked={stateful}
125111
onChange={e => {
126-
toggleComponentClass(id);
112+
toggleComponentState(id);
127113
changeFocusComponent(title);
128114
}}
129-
value='classBased'
115+
value='stateful'
130116
color='primary'
117+
id={props.id.toString()}
131118
/>
119+
) : (
120+
''
121+
)}
122+
<div>
123+
{/* LABEL/TOGGLE(SWITCH) FOR CLASS BASED */}
124+
{focusedToggle ? (
125+
<InputLabel
126+
htmlFor='classBased'
127+
style={{
128+
color: '#fff',
129+
marginBottom: '10px',
130+
marginTop: '0px',
131+
marginLeft: '11px',
132+
padding: '0px',
133+
fontSize: '18px'
134+
}}
135+
>
136+
Class?
137+
</InputLabel>
138+
) : (
139+
''
140+
)}
141+
{focusedToggle ? (
142+
<Switch
143+
checked={classBased}
144+
onChange={e => {
145+
toggleComponentClass(id);
146+
changeFocusComponent(title);
147+
}}
148+
value='classBased'
149+
color='primary'
150+
/>
151+
) : (
152+
''
153+
)}
132154
</div>
133155
</div>
134156
}

0 commit comments

Comments
 (0)