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 spacing and layout of registered TopBar items #4991

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions src/renderer/components/layout/top-bar/top-bar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,33 @@
justify-content: space-between;

/* Use topbar as draggable region */
-webkit-user-select: none;
user-select: none;
-webkit-app-region: drag;
}

.topBar .items {
align-items: center;
display: flex;
height: 100%;
-webkit-app-region: no-drag;

&:first-of-type {
padding-left: 1.5rem;

& > * {
margin-right: 1rem;
}
}

&:last-of-type {
padding-right: 1.5rem;

& > * {
margin-left: 1rem;
}
}
}

:global(.is-mac) .topBar {
padding-left: var(--hotbar-width);
}
Expand All @@ -39,23 +62,8 @@
}
}

.tools {
@apply flex items-center;
-webkit-app-region: no-drag;
}

.controls {
align-self: flex-end;
padding-right: 1.5rem;
align-items: center;
display: flex;
height: 100%;
-webkit-app-region: no-drag;
}

.windowButtons {
display: flex;
margin-left: 1.5rem;
margin-right: -1.5rem;

> div {
Expand Down Expand Up @@ -94,7 +102,8 @@
}
}

.minimize, .maximize {
.minimize,
.maximize {
&:hover {
background-color: var(--borderFaintColor);
}
Expand Down
43 changes: 14 additions & 29 deletions src/renderer/components/layout/top-bar/top-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { WindowAction } from "../../../../common/ipc/window";
import isLinuxInjectable from "../../../../common/vars/is-linux.injectable";
import isWindowsInjectable from "../../../../common/vars/is-windows.injectable";

export interface TopBarProps extends React.HTMLAttributes<any> {}
export interface TopBarProps {}

interface Dependencies {
items: IComputedValue<TopBarRegistration[]>;
Expand All @@ -41,7 +41,7 @@ ipcRendererOn("history:can-go-forward", (event, state: boolean) => {
nextEnabled.set(state);
});

const NonInjectedTopBar = observer(({ items, children, isWindows, isLinux, ...rest }: TopBarProps & Dependencies) => {
const NonInjectedTopBar = observer(({ items, isWindows, isLinux }: TopBarProps & Dependencies) => {
const elem = useRef<HTMLDivElement>();

const openAppContextMenu = () => {
Expand All @@ -61,12 +61,9 @@ const NonInjectedTopBar = observer(({ items, children, isWindows, isLinux, ...re
};

const windowSizeToggle = (evt: React.MouseEvent) => {
if (elem.current != evt.target) {
// Skip clicking on child elements
return;
if (elem.current === evt.target) {
toggleMaximize();
}

toggleMaximize();
};

const minimizeWindow = () => {
Expand All @@ -84,8 +81,8 @@ const NonInjectedTopBar = observer(({ items, children, isWindows, isLinux, ...re
useEffect(() => watchHistoryState(), []);

return (
<div className={styles.topBar} onDoubleClick={windowSizeToggle} ref={elem} {...rest}>
<div className={styles.tools}>
<div className={styles.topBar} onDoubleClick={windowSizeToggle} ref={elem}>
<div className={styles.items}>
{(isWindows || isLinux) && (
<div className={styles.winMenu}>
<div onClick={openAppContextMenu} data-testid="window-menu">
Expand All @@ -100,28 +97,24 @@ const NonInjectedTopBar = observer(({ items, children, isWindows, isLinux, ...re
<Icon
data-testid="home-button"
material="home"
className="ml-4"
onClick={goHome}
disabled={isActiveRoute(catalogRoute)}
/>
<Icon
data-testid="history-back"
material="arrow_back"
className="ml-5"
onClick={goBack}
disabled={!prevEnabled.get()}
/>
<Icon
data-testid="history-forward"
material="arrow_forward"
className="ml-5"
onClick={goForward}
disabled={!nextEnabled.get()}
/>
</div>
<div className={styles.controls}>
<div className={styles.items}>
{renderRegisteredItems(items.get())}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, it should now be relatively easy to add the ability to add items to either side via the extension API. That, however, is left for future work.

{children}
{(isWindows || isLinux) && (
<div className={cssNames(styles.windowButtons, { [styles.linuxButtons]: isLinux })}>
<div className={styles.minimize} data-testid="window-minimize" onClick={minimizeWindow}>
Expand All @@ -147,22 +140,14 @@ const NonInjectedTopBar = observer(({ items, children, isWindows, isLinux, ...re
});

const renderRegisteredItems = (items: TopBarRegistration[]) => (
<div>
{items.map((registration, index) => {
if (!registration?.components?.Item) {
return null;
}

return (
<div key={index}>
<registration.components.Item />
</div>
);
})}
</div>
);

items.map((registration, index) => {
if (!registration?.components?.Item) {
return null;
}

return <registration.components.Item key={index} />;
})
);

export const TopBar = withInjectables<Dependencies, TopBarProps>(NonInjectedTopBar, {
getProps: (di, props) => ({
Expand Down