Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix side panel exit animation #349

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 29 additions & 27 deletions src/Playroom/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useState, useCallback } from 'react';
import { useContext, useState, useCallback, useEffect } from 'react';
import { useTimeoutFn } from 'react-use';
import classnames from 'classnames';
import type { PlayroomProps } from '../Playroom';
Expand Down Expand Up @@ -58,6 +58,14 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
const isSettingsOpen = activeToolbarPanel === 'settings';
const isPreviewOpen = activeToolbarPanel === 'preview';

const [lastActivePanel, setLastActivePanel] = useState('snippets');

useEffect(() => {
if (activeToolbarPanel) {
setLastActivePanel(activeToolbarPanel);
}
}, [activeToolbarPanel]);

const hasSnippets = snippets && snippets.length > 0;
const hasFilteredFrames =
visibleThemes.length > 0 || visibleWidths.length > 0;
Expand Down Expand Up @@ -150,11 +158,8 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
</div>

<div className={styles.panel}>
{isSnippetsOpen && (
<div
hidden={isSnippetsOpen ? undefined : true}
className={styles.preference}
>
{lastActivePanel === 'snippets' && (
<div className={styles.preference}>
<Snippets
snippets={snippets}
onHighlight={(snippet) => {
Expand All @@ -176,29 +181,26 @@ export default ({ themes: allThemes, widths: allWidths, snippets }: Props) => {
/>
</div>
)}
<div
hidden={isFramesOpen ? undefined : true}
className={styles.preference}
>
<FramesPanel
availableWidths={allWidths}
availableThemes={allThemes}
/>
</div>
{lastActivePanel === 'frames' && (
<div className={styles.preference}>
<FramesPanel
availableWidths={allWidths}
availableThemes={allThemes}
/>
</div>
)}

<div
hidden={isPreviewOpen ? undefined : true}
className={styles.preference}
>
<PreviewPanel themes={allThemes} visibleThemes={visibleThemes} />
</div>
{lastActivePanel === 'preview' && (
<div className={styles.preference}>
<PreviewPanel themes={allThemes} visibleThemes={visibleThemes} />
</div>
)}

<div
hidden={isSettingsOpen ? undefined : true}
className={styles.preference}
>
<SettingsPanel />
</div>
{lastActivePanel === 'settings' && (
<div className={styles.preference}>
<SettingsPanel />
</div>
)}
</div>
</div>
</div>
Expand Down