Skip to content

Commit

Permalink
show the restore icon when nuclear is full width and height
Browse files Browse the repository at this point in the history
  • Loading branch information
sicin committed Sep 22, 2024
1 parent 280327b commit b0da01d
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions packages/app/app/components/WindowControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,45 @@ const WindowControls: React.FC<WindowControlsProps> = ({
onCloseClick,
onMaxClick,
onMinClick
}) => (
<div className={styles.window_controls_container}>
<WindowButton data-testid='minimize-button' icon='window minimize' onClick={onMinClick} />
<WindowButton data-testid='maximize-button' icon='window maximize outline' onClick={onMaxClick} />
<WindowButton data-testid='close-button' icon='close' onClick={onCloseClick} />
</div>
);
}) => {
const [isMaximized, setIsMaximized] = React.useState(false);

const handleMaximizeClick = (event: React.MouseEvent) => {
setIsMaximized(!isMaximized);
onMaxClick(event);
};

React.useEffect(() => {
const handleWindowResize = () => {
const maximized =
window.outerWidth === window.screen.availWidth &&
window.outerHeight === window.screen.availHeight;
setIsMaximized(maximized);
};

window.addEventListener('resize', handleWindowResize);
return () => window.removeEventListener('resize', handleWindowResize);
}, []);

return (
<div className={styles.window_controls_container}>
<WindowButton
data-testid='minimize-button'
icon='window minimize'
onClick={onMinClick}
/>
<WindowButton
data-testid='maximize-button'
icon={isMaximized ? 'window restore outline' : 'window maximize outline'}
onClick={handleMaximizeClick}
/>
<WindowButton
data-testid='close-button'
icon='close'
onClick={onCloseClick}
/>
</div>
);
};

export default WindowControls;

0 comments on commit b0da01d

Please sign in to comment.