Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add transition animation when panel options are shown/hidden #1724

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/components/controls/panelSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { useSelector } from "react-redux";
import { PanelSectionContainer } from "./styles";
import { PanelOptionsContainer, PanelSectionContainer } from "./styles";
import { Title, Tooltip } from "./annotatedTitle";
import { PanelHeader, PanelId } from "./panelHeader";
import { RootState } from "../../store";
Expand Down Expand Up @@ -31,6 +31,16 @@ export const PanelSection = ({ panel, title, tooltip, options=undefined }: Props
setOptionsAreVisible(panelIsVisible)
}, [panelIsVisible])

const [contentHeight, setContentHeight] = React.useState(1000);
const optionsContainer = React.useRef<HTMLDivElement>(null);

// FIXME: useLayoutEffect?
React.useEffect(() => {
if (optionsContainer.current) {
setContentHeight(optionsContainer.current.scrollHeight); // FIXME: offsetHeight?
}
}, [options]);

return (
<PanelSectionContainer>
<PanelHeader
Expand All @@ -42,7 +52,9 @@ export const PanelSection = ({ panel, title, tooltip, options=undefined }: Props
optionsAreVisible={optionsAreVisible}
setOptionsAreVisible={setOptionsAreVisible}
/>
{optionsAreVisible && options}
<PanelOptionsContainer ref={optionsContainer} className={`${optionsAreVisible ? "open" : ""}`} contentHeight={contentHeight}>
{options}
</PanelOptionsContainer>
</PanelSectionContainer>
);
};
12 changes: 12 additions & 0 deletions src/components/controls/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ export const PanelSectionContainer = styled.div`
}
`;

export const PanelOptionsContainer = styled.div`
visibility: hidden;
transition: visibility .5s, max-height .5s;
max-height: 0;
overflow: hidden;

&.open {
visibility: visible;
max-height: ${({ contentHeight }) => `${contentHeight}px`};
}
`

export const TitleAndIconContainer = styled.span`
display: inline-flex;
align-items: center;
Expand Down