(props: ToolbarProps)
| 27 | } |
| 28 | |
| 29 | export function Toolbar(props: ToolbarProps) { |
| 30 | const { children, label, minified, onMinifiedChange } = props; |
| 31 | const controls = useToolbarControls(); |
| 32 | const [isReady, setIsReady] = React.useState(false); |
| 33 | const autoExpandTriggeredRef = React.useRef(false); |
| 34 | |
| 35 | const shouldAutoExpand = Boolean(controls?.shouldAutoExpand); |
| 36 | const [shouldAnimateLogo, setShouldAnimateLogo] = React.useState(shouldAutoExpand); |
| 37 | |
| 38 | // Wait for page to be ready, then show the toolbar |
| 39 | React.useEffect(() => { |
| 40 | const handleLoad = () => { |
| 41 | setIsReady(true); |
| 42 | }; |
| 43 | |
| 44 | if (document.readyState === 'complete') { |
| 45 | handleLoad(); |
| 46 | } else { |
| 47 | window.addEventListener('load', handleLoad); |
| 48 | return () => window.removeEventListener('load', handleLoad); |
| 49 | } |
| 50 | }, []); |
| 51 | |
| 52 | // After toolbar appears, wait, then show the full content |
| 53 | React.useEffect(() => { |
| 54 | if (!isReady || autoExpandTriggeredRef.current) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | if (!shouldAutoExpand) { |
| 59 | // When we already know the toolbar should stay expanded (e.g. the user previously |
| 60 | // opened it this session) we short-circuit the auto-expand animation and immediately |
| 61 | // render the expanded state without replaying the logo animation. |
| 62 | autoExpandTriggeredRef.current = true; |
| 63 | setShouldAnimateLogo(false); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | autoExpandTriggeredRef.current = true; |
| 68 | |
| 69 | // On a fresh session we let the toolbar appear in its compact form, play the logo |
| 70 | // animation, and only then expand the toolbar. The timeout mirrors the duration of the |
| 71 | // logo animation so both transitions feel connected. |
| 72 | const expandAfterTimeout = setTimeout(() => { |
| 73 | setShouldAnimateLogo(false); |
| 74 | onMinifiedChange(false); |
| 75 | }, DURATION_LOGO_APPEARANCE + DELAY_BETWEEN_LOGO_AND_CONTENT); |
| 76 | |
| 77 | return () => clearTimeout(expandAfterTimeout); |
| 78 | }, [isReady, onMinifiedChange, shouldAutoExpand]); |
| 79 | |
| 80 | React.useEffect(() => { |
| 81 | if (!minified) { |
| 82 | // Any manual expansion should stop the logo animation so the icon stays in its |
| 83 | // “settled” state once the toolbar is open. |
| 84 | setShouldAnimateLogo(false); |
| 85 | } |
| 86 | }, [minified]); |
nothing calls this directly
no test coverage detected