fix: smooth tool expansion animation

This commit is contained in:
Bohdan Triapitsyn
2026-05-27 00:41:04 +03:00
parent 52ffe9daef
commit e8e4df5ea9
2 changed files with 26 additions and 21 deletions
@@ -197,8 +197,8 @@ const LiveDuration: React.FC<{ start: number; end?: number; active: boolean }> =
return <>{formatDuration(start, end, now)}</>;
};
const EXPANDED_CONTENT_TRANSITION_MS = 350;
const EXPANDED_CONTENT_SPRING = { type: 'spring' as const, visualDuration: 0.35, bounce: 0 };
const EXPANDED_CONTENT_TRANSITION_MS = 200;
const EXPANDED_CONTENT_TRANSITION = { duration: 0.2, ease: 'easeOut' as const };
const useAnimatedExpandedContent = (isExpanded: boolean) => {
const [shouldRender, setShouldRender] = React.useState(isExpanded);
@@ -1876,7 +1876,6 @@ const ToolPartContent: React.FC<ToolPartProps> = ({
if (!expandedContentMountedRef.current) {
expandedContentMountedRef.current = true;
element.style.height = isExpanded ? 'auto' : '0px';
element.style.opacity = isExpanded ? '1' : '0';
element.style.overflow = isExpanded ? 'visible' : 'hidden';
return;
}
@@ -1885,16 +1884,14 @@ const ToolPartContent: React.FC<ToolPartProps> = ({
if (isExpanded) {
element.style.height = '0px';
element.style.opacity = '0';
} else {
element.style.height = `${element.scrollHeight}px`;
element.style.opacity = '1';
}
const animation = animate(
element,
{ height: isExpanded ? 'auto' : '0px', opacity: isExpanded ? 1 : 0 },
EXPANDED_CONTENT_SPRING,
{ height: isExpanded ? 'auto' : '0px' },
EXPANDED_CONTENT_TRANSITION,
);
expandedContentAnimationRef.current = animation;
@@ -2725,13 +2722,19 @@ const ToolPartContent: React.FC<ToolPartProps> = ({
aria-hidden={!isExpanded}
style={{
height: isExpanded ? 'auto' : '0px',
opacity: isExpanded ? 1 : 0,
overflow: isExpanded ? 'visible' : 'hidden',
overflowAnchor: 'none',
}}
>
{shouldRenderExpandedContent ? (
<div className="relative ml-2 pl-3">
<div
className="relative ml-2 pl-3"
style={{
opacity: isExpanded ? 1 : 0,
transform: isExpanded ? 'translateY(0)' : 'translateY(-4px)',
transition: 'opacity 180ms ease-out, transform 180ms ease-out',
}}
>
<span
aria-hidden="true"
className="pointer-events-none absolute left-0 top-px bottom-0 w-px"