Skip to content

Commit 10573b4

Browse files
authored
Merge pull request #5 from oslabs-beta/feature/CustomPanelButtons
Feature/custom panel buttons
2 parents bc63540 + d5f634e commit 10573b4

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

app/src/components/main/DeleteButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ function DeleteButton({ id, name, onClickHandler }: DeleteButtons) {
3434
id={'btn' + id}
3535
onClick={(event) => {
3636
event.stopPropagation();
37-
onClickHandler(event);
37+
if (typeof onClickHandler === 'function') {
38+
onClickHandler(event);
39+
}
3840
deleteHTMLtype(id);
3941
}}
4042
>

app/src/containers/CustomizationPanel.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
5656
const [flexDir, setFlexDir] = useState('');
5757
const [flexJustify, setFlexJustify] = useState('');
5858
const [flexAlign, setFlexAlign] = useState('');
59+
const [flexOptionsVisible, setFlexOptionsVisible] = useState(false);
5960
const [BGColor, setBGColor] = useState('');
6061
const [compText, setCompText] = useState('');
6162
const [compLink, setCompLink] = useState('');
@@ -69,7 +70,9 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
6970
const [useContextObj, setUseContextObj] = useState({});
7071
const [stateUsedObj, setStateUsedObj] = useState({});
7172
const [eventAll, setEventAll] = useState(['', '']);
73+
const [eventOptionsVisible, setEventOptionsVisible] = useState(false);
7274
const [eventRow, setEventRow] = useState([]);
75+
const [eventRowsVisible, setEventRowsVisible] = useState(false);
7376

7477
const currFocus = getFocus().child;
7578

@@ -86,6 +89,35 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
8689
}
8790
}, [state]);
8891

92+
useEffect(() => {
93+
if (displayMode === 'flex') {
94+
return setFlexOptionsVisible(true);
95+
}
96+
return setFlexOptionsVisible(false);
97+
}, [displayMode]);
98+
99+
useEffect(() => {
100+
if (eventAll[0] !== '') {
101+
return setEventOptionsVisible(true);
102+
}
103+
return setEventOptionsVisible(false);
104+
}, [eventAll]);
105+
106+
useEffect(() => {
107+
if (eventRow.length) {
108+
return setEventRowsVisible(true);
109+
}
110+
return setEventRowsVisible(false);
111+
}, [eventRow]);
112+
113+
const marginTopAmount = () => {
114+
let totalMargin = 0;
115+
if (eventOptionsVisible) totalMargin += 90;
116+
if (flexOptionsVisible) totalMargin = Math.max(totalMargin, 210);
117+
if (eventRowsVisible) totalMargin = Math.max(totalMargin, 335);
118+
return `${totalMargin}px`;
119+
};
120+
89121
//this function allows properties to persist and appear in nested divs
90122
function deepIterate(arr) {
91123
const output = [];
@@ -128,7 +160,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
128160
resetFields();
129161
}, [state.canvasFocus.componentId, state.canvasFocus.childId]);
130162
// handles all input field changes, with specific updates called based on input's name
131-
const handleChange = (e: React.ChangeEvent<{ value: any }>) => {
163+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
132164
const inputVal = e.target.value;
133165
switch (e.target.name) {
134166
case 'display':
@@ -862,7 +894,10 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
862894
)}
863895
</div>
864896
</section>
865-
<div className={classes.buttonRow}>
897+
<div
898+
className={classes.buttonRow}
899+
style={{ marginTop: marginTopAmount() }}
900+
>
866901
<div>
867902
<Button
868903
variant="contained"
@@ -957,7 +992,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
957992
</Button>
958993
</div>
959994
)}
960-
<div style={{marginLeft: '17px'}}>
995+
<div style={{ marginLeft: '17px' }}>
961996
<Button
962997
variant="contained"
963998
color="primary"
@@ -1039,6 +1074,7 @@ const useStyles = makeStyles({
10391074
justifyContent: 'center',
10401075
alignItems: 'center',
10411076
textAlign: 'center',
1077+
marginLeft: '15px',
10421078
'& > .MuiButton-textSecondary': {
10431079
color: isThemeLight ? '#808080' : '#ECECEA', // color for delete page
10441080
border: isThemeLight ? '1px solid #808080' : '1px solid #ECECEA'

0 commit comments

Comments
 (0)