mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
remove the spacing effect
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Alert } from '@freecodecamp/react-bootstrap';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
||||
import { FlashState } from '../../redux/types';
|
||||
@@ -15,45 +15,24 @@ type FlashProps = {
|
||||
function Flash({ flashMessage, removeFlashMessage }: FlashProps): JSX.Element {
|
||||
const { type, message, id, variables } = flashMessage;
|
||||
const { t } = useTranslation();
|
||||
const [flashMessageHeight, setFlashMessageHeight] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const flashMessageElem: HTMLElement | null =
|
||||
document.querySelector('.flash-message');
|
||||
setFlashMessageHeight(flashMessageElem?.offsetHeight || 0);
|
||||
document.documentElement.style.setProperty(
|
||||
'--flash-message-height',
|
||||
`${flashMessageHeight}px`
|
||||
);
|
||||
}, [flashMessageHeight]);
|
||||
|
||||
function handleClose() {
|
||||
document.documentElement.style.setProperty('--flash-message-height', '0px');
|
||||
removeFlashMessage();
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<TransitionGroup>
|
||||
<CSSTransition classNames='flash-message' key={id} timeout={500}>
|
||||
<Alert
|
||||
bsStyle={type}
|
||||
className='flash-message'
|
||||
closeLabel={t('buttons.close')}
|
||||
onDismiss={handleClose}
|
||||
>
|
||||
{t(message, variables)}
|
||||
</Alert>
|
||||
</CSSTransition>
|
||||
</TransitionGroup>
|
||||
{flashMessage && (
|
||||
<div
|
||||
style={{
|
||||
height: `${flashMessageHeight}px`
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
<TransitionGroup>
|
||||
<CSSTransition classNames='flash-message' key={id} timeout={500}>
|
||||
<Alert
|
||||
bsStyle={type}
|
||||
className='flash-message'
|
||||
closeLabel={t('buttons.close')}
|
||||
onDismiss={handleClose}
|
||||
>
|
||||
{t(message, variables)}
|
||||
</Alert>
|
||||
</CSSTransition>
|
||||
</TransitionGroup>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user