Skip to content

Commit

Permalink
fix: prevent UI overlaps in header
Browse files Browse the repository at this point in the history
happened on initial load and when scrolling
  • Loading branch information
Xiphe committed Jan 8, 2021
1 parent 2c1a670 commit c6fb84f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/views/Month/Month.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
transition: height 200ms ease-out;
background: var(--background-color);
}

.headerBorder {
display: block;
position: absolute;
Expand All @@ -48,6 +49,8 @@
list-style: none;
margin: 0;
padding: 0 0 3.3rem;
opacity: 0;
transition: opacity 200ms ease-in-out 200ms;
li {
span {
display: inline-block;
Expand All @@ -73,7 +76,9 @@
line-height: 1.1em;
}
}

.headTableVisible {
opacity: 1;
}
.bigBudget {
font-size: 1.5em;
}
Expand Down
15 changes: 11 additions & 4 deletions src/views/Month/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useRef } from 'react';
import React, { useEffect, useState } from 'react';
import cx from 'classnames';
import classNames from 'classnames';
import format from 'date-fns/format';
import subMonths from 'date-fns/subMonths';
Expand Down Expand Up @@ -32,20 +33,26 @@ export default function Overview({
data,
numberFormatter,
}: Props) {
const ref = useRef<HTMLDivElement | null>(null);
const budgetClasses = data
? classNames(
data.toBudget !== 0 && styles.bigBudget,
data.toBudget < 0 && styles.negative,
)
: '';
const [visible, setVisible] = useState(false);
useEffect(() => {
const i = setTimeout(() => setVisible(Boolean(data)), 50);
return () => clearTimeout(i);
}, [data]);

return (
<div ref={ref}>
<div>
<h3 className={styles.title}>{name}</h3>
{data && (
<>
<ul className={styles.headTable}>
<ul
className={cx(styles.headTable, visible && styles.headTableVisible)}
>
<ListItem
amount={numberFormatter.format(data.availableThisMonth.amount)}
title="Available Funds"
Expand Down

0 comments on commit c6fb84f

Please sign in to comment.