This functional React component takes in the prop 'modal', which comes from the 'ui' slice of the Redux State. This prop designates which type of modal, if any, should be present on the page. The 'hideModal' prop is a function which, well, hides any present modal on dispatch! The switch statement governs which specific modal component to render on the page, and it defines classes which are interpolated into the HTML elements in the return statement so that each type of modal can have its own styling.
function Modal({modal, hideModal}) {
if (!modal) {
return null;
}
let component
let backgroundClass
let childClass
switch (modal) {
case 'Sign In':
component = <SignInFormContainer />
backgroundClass = 'modal-background'
childClass = 'modal-child'
break
case 'Sign Up':
component = <SignUpFormContainer />
backgroundClass = 'modal-background'
childClass = 'modal-child'
break
case 'Dropdown':
component = <DropdownModalContainer />
backgroundClass = 'dropdown modal-background'
childClass = 'dropdown modal-child'
break
case 'Comments':
component = <CommentsModalContainer />
backgroundClass = 'comments modal-background'
childClass = 'comments modal-child'
break
default:
return null;
}
return (
<div className={backgroundClass} onClick={hideModal}>
<div className={childClass} onClick={e => e.stopPropagation()}>
{ component }
</div>
</div>
);
}
export default Modal