Skip to content

Commit

Permalink
Animation: Avoid fixed width when animating the secondary sidebar (#6…
Browse files Browse the repository at this point in the history
…0693)

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: draganescu <[email protected]>
  • Loading branch information
3 people authored Apr 12, 2024
1 parent 65a3f49 commit 6ea845e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/interface/src/components/interface-skeleton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
useMergeRefs,
useReducedMotion,
useViewportMatch,
useResizeObserver,
} from '@wordpress/compose';

/**
* Internal dependencies
*/
import NavigableRegion from '../navigable-region';

const SECONDARY_SIDEBAR_WIDTH = 350;
const ANIMATION_DURATION = 0.25;

function useHTMLClass( className ) {
Expand All @@ -50,12 +50,6 @@ const headerVariants = {
distractionFreeInactive: { opacity: 1, transition: { delay: 0 } },
};

const secondarySidebarVariants = {
open: { width: SECONDARY_SIDEBAR_WIDTH },
closed: { width: 0 },
mobileOpen: { width: '100vw' },
};

function InterfaceSkeleton(
{
isDistractionFree,
Expand All @@ -76,12 +70,14 @@ function InterfaceSkeleton(
},
ref
) {
const [ secondarySidebarResizeListener, secondarySidebarSize ] =
useResizeObserver();
const isMobileViewport = useViewportMatch( 'medium', '<' );
const disableMotion = useReducedMotion();
const defaultTransition = {
type: 'tween',
duration: disableMotion ? 0 : ANIMATION_DURATION,
ease: 'easeOut',
ease: [ 0.6, 0, 0.4, 1 ],
};
const navigateRegionsProps = useNavigateRegions( shortcuts );
useHTMLClass( 'interface-interface-skeleton__html-container' );
Expand Down Expand Up @@ -165,19 +161,22 @@ function InterfaceSkeleton(
isMobileViewport ? 'mobileOpen' : 'open'
}
exit="closed"
variants={ secondarySidebarVariants }
variants={ {
open: { width: secondarySidebarSize.width },
closed: { width: 0 },
mobileOpen: { width: '100vw' },
} }
transition={ defaultTransition }
>
<div
style={ {
position: 'absolute',
width: isMobileViewport
? '100vw'
: SECONDARY_SIDEBAR_WIDTH,
width: 'fit-content',
height: '100%',
right: 0,
} }
>
{ secondarySidebarResizeListener }
{ secondarySidebar }
</div>
</NavigableRegion>
Expand Down

0 comments on commit 6ea845e

Please sign in to comment.