feat(client): add space for flash message (#38327)

This commit is contained in:
Jacob Robinson
2020-03-16 22:37:42 -07:00
committed by GitHub
parent c21af106bb
commit 00347ff8bf
3 changed files with 44 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Alert } from '@freecodecamp/react-bootstrap';
import { TransitionGroup, CSSTransition } from 'react-transition-group';
@ -7,14 +7,44 @@ import './flash.css';
function Flash({ flashMessage, onClose }) {
const { type, message, id } = flashMessage;
const [flashMessageHeight, setFlashMessageHeight] = useState(null);
useEffect(() => {
setFlashMessageHeight(
document.querySelector('.flash-message').offsetHeight
);
document.documentElement.style.setProperty(
'--flash-message-height',
flashMessageHeight + 'px'
);
}, [flashMessageHeight]);
function handleClose() {
document.documentElement.style.setProperty('--flash-message-height', '0px');
onClose();
}
return (
<TransitionGroup>
<CSSTransition classNames='flash-message' key={id} timeout={500}>
<Alert bsStyle={type} className='flash-message' onDismiss={onClose}>
{message}
</Alert>
</CSSTransition>
</TransitionGroup>
<>
<TransitionGroup>
<CSSTransition classNames='flash-message' key={id} timeout={500}>
<Alert
bsStyle={type}
className='flash-message'
onDismiss={handleClose}
>
{message}
</Alert>
</CSSTransition>
</TransitionGroup>
{flashMessage && (
<div
style={{
height: flashMessageHeight + 'px'
}}
></div>
)}
</>
);
}

View File

@ -1,5 +1,7 @@
#learn-app-wrapper .desktop-layout {
height: calc(100vh - var(--header-height, 0px));
height: calc(
100vh - var(--header-height, 0px) - var(--flash-message-height, 0px)
);
}
#learn-app-wrapper .reflex-container.vertical > .reflex-splitter,

View File

@ -32,7 +32,9 @@
}
#challenge-page-tabs .tab-content {
height: calc(100vh - var(--header-height, 0px) - 69px);
height: calc(
100vh - var(--header-height, 0px) - var(--flash-message-height, 0px) - 69px
);
overflow-y: auto;
}