allow modal to close on outside click
This commit is contained in:
@@ -6,52 +6,52 @@ import './rcSelectTheme.css';
|
|||||||
const SliderWithToolTip = createSliderWithTooltip(RCSlider);
|
const SliderWithToolTip = createSliderWithTooltip(RCSlider);
|
||||||
|
|
||||||
const SelectStyle = {
|
const SelectStyle = {
|
||||||
control: (provided) => ({
|
control: (provided) => ({
|
||||||
...provided,
|
...provided,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const Slider = (props) => {
|
const Slider = (props) => {
|
||||||
return (
|
return (
|
||||||
<SliderWithToolTip
|
<SliderWithToolTip
|
||||||
tipFormatter={(v) => `${v}`}
|
tipFormatter={(v) => `${v}`}
|
||||||
min={props.min}
|
min={props.min}
|
||||||
max={props.max}
|
max={props.max}
|
||||||
value={props.parameter}
|
value={props.parameter}
|
||||||
onChange={(v) => props.onChange(v)}
|
onChange={(v) => props.onChange(v)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const SelectList = (props) => {
|
const SelectList = (props) => {
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
value={{ value: props.value }}
|
value={{ value: props.value }}
|
||||||
options={props.list}
|
options={props.list}
|
||||||
getOptionLabel={
|
getOptionLabel={
|
||||||
props.labelFunction
|
props.labelFunction
|
||||||
? props.labelFunction
|
? props.labelFunction
|
||||||
: (option) => `${option.value}`
|
: (option) => `${option.value}`
|
||||||
}
|
}
|
||||||
onChange={(e) => props.onChange(e.value)}
|
onChange={(e) => props.onChange(e.value)}
|
||||||
styles={SelectStyle}
|
styles={SelectStyle}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Checkbox = (props) => {
|
const Checkbox = (props) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<span>{`${props.name}:`}</span>
|
<span>{`${props.name}:`}</span>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
value={props.parameter}
|
value={props.parameter}
|
||||||
defaultChecked={props.parameter}
|
defaultChecked={props.parameter}
|
||||||
onChange={(e) => props.onChange(e.target.checked)}
|
onChange={(e) => props.onChange(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { Slider, SelectList, Checkbox };
|
export { Slider, SelectList, Checkbox };
|
||||||
|
|||||||
@@ -14,11 +14,3 @@
|
|||||||
border: 0.09em solid slategray;
|
border: 0.09em solid slategray;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.show {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hide {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -65,11 +65,7 @@ const Dropzone = ({ setFile }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function IO({ show }) {
|
export default function IO() {
|
||||||
const display = show
|
|
||||||
? 'dropzone-container show'
|
|
||||||
: 'dropzone-container hide';
|
|
||||||
|
|
||||||
const [file, setFile] = useState(null);
|
const [file, setFile] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -77,8 +73,10 @@ export default function IO({ show }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={display}>
|
<div className="dropzone-container">
|
||||||
<Dropzone className="dropzone-modal" setFile={setFile} />
|
<Dropzone className="dropzone-modal" setFile={setFile} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO -- possibly add clicking outside the modal to close it*/
|
||||||
|
|||||||
+61
-38
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import IO from '../io/IO';
|
import IO from '../io/IO';
|
||||||
import { useDispatch, useSelector } from 'react-redux'; // probably temporarily here
|
import { useDispatch, useSelector } from 'react-redux'; // probably temporarily here
|
||||||
import { parameterRefreshAll } from '../timbre/parameters/parameterSlice'; // probably temporarily here
|
import { parameterRefreshAll } from '../timbre/parameters/parameterSlice'; // probably temporarily here
|
||||||
@@ -6,31 +6,34 @@ import logo from '../../1f3b9.svg';
|
|||||||
import './Menu.css';
|
import './Menu.css';
|
||||||
|
|
||||||
// for things such as (do you want to save? or do you want to reset things?)
|
// for things such as (do you want to save? or do you want to reset things?)
|
||||||
const Modal = ({ show, handleSave, handleNoSave, handleClose }) => {
|
const Modal = ({ children, show, setShow }) => {
|
||||||
|
const node = useRef();
|
||||||
const modalDisplay = show ? 'modal modal-display' : 'modal modal-hide';
|
const modalDisplay = show ? 'modal modal-display' : 'modal modal-hide';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const current = node.current;
|
||||||
|
|
||||||
|
const handleOutsideClick = (event) => {
|
||||||
|
console.log('clicking anywhere');
|
||||||
|
if (current.contains(event.target)) {
|
||||||
|
return;
|
||||||
|
} else setShow();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (show) {
|
||||||
|
document.addEventListener('mousedown', handleOutsideClick);
|
||||||
|
} else {
|
||||||
|
document.removeEventListener('mousedown', handleOutsideClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleOutsideClick);
|
||||||
|
};
|
||||||
|
}, [show, setShow]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={modalDisplay}>
|
<div ref={node} className={modalDisplay}>
|
||||||
<div className="modal-main">
|
{children}
|
||||||
<span className="modal-header">Save Changes</span>
|
|
||||||
<span className="modal-text">
|
|
||||||
Do you want to save your changes?
|
|
||||||
</span>
|
|
||||||
<button
|
|
||||||
className="menu-button button-save"
|
|
||||||
onClick={handleSave}>
|
|
||||||
Save Changes
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="menu-button button-no-save"
|
|
||||||
onClick={handleNoSave}>
|
|
||||||
Don't Save
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
className="menu-button button-cancel"
|
|
||||||
onClick={handleClose}>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -73,19 +76,37 @@ export default function MainMenu() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Modal
|
<Modal show={showModal.saveCheck} setShow={showSaveCheck}>
|
||||||
show={showModal.saveCheck}
|
<div className="modal-main">
|
||||||
handleClose={showSaveCheck}
|
<span className="modal-header">Save Changes</span>
|
||||||
handleSave={() => {
|
<span className="modal-text">
|
||||||
showSaveCheck();
|
Do you want to save your changes?
|
||||||
HandleClick(); // temporary while I implement the binary parsing stuff
|
</span>
|
||||||
}}
|
<button
|
||||||
handleNoSave={() => {
|
className="menu-button button-save"
|
||||||
dispatch(parameterRefreshAll());
|
onClick={() => {
|
||||||
showSaveCheck();
|
showSaveCheck();
|
||||||
HandleClick();
|
HandleClick();
|
||||||
}}
|
}} // temporary while I implement the binary parsing stuff
|
||||||
/>
|
>
|
||||||
|
Save Changes
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="menu-button button-no-save"
|
||||||
|
onClick={() => {
|
||||||
|
dispatch(parameterRefreshAll());
|
||||||
|
showSaveCheck();
|
||||||
|
HandleClick();
|
||||||
|
}}>
|
||||||
|
Don't Save
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className="menu-button button-cancel"
|
||||||
|
onClick={showSaveCheck}>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
<div
|
<div
|
||||||
className={`menu ${open.className}`}
|
className={`menu ${open.className}`}
|
||||||
onAnimationEnd={AnimationEnd}>
|
onAnimationEnd={AnimationEnd}>
|
||||||
@@ -111,7 +132,9 @@ export default function MainMenu() {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<IO show={showModal.ioModal} />
|
<Modal show={showModal.ioModal} setShow={showIOModal}>
|
||||||
|
<IO />
|
||||||
|
</Modal>
|
||||||
<button className="menu-open-button" onClick={HandleClick} />
|
<button className="menu-open-button" onClick={HandleClick} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user