Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: better integrated titlebar that looks same across platforms

Abdullah Atta69e6263d341f
diff --git a/apps/web/src/app.css b/apps/web/src/app.css
index 35ac364f3..5e3a6a3fa 100644
--- a/apps/web/src/app.css
+++ b/apps/web/src/app.css
@@ -10,7 +10,10 @@
}
.theme-scope-titleBar button,
-.tabsScroll .tab {
+.tabsScroll .tab,
+.editor-action-bar button,
+.route-container-header button,
+.search-container {
-webkit-app-region: no-drag;
}
diff --git a/apps/web/src/app.tsx b/apps/web/src/app.tsx
index ff8eecf2b..cf99c7a00 100644
--- a/apps/web/src/app.tsx
+++ b/apps/web/src/app.tsx
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import React, { useState, Suspense, useEffect, useRef } from "react";
+import { useState, Suspense, useEffect, useRef } from "react";
import { Box, Flex } from "@theme-ui/components";
import { ScopedThemeProvider } from "./components/theme-provider";
import useMobile from "./hooks/use-mobile";
@@ -39,6 +39,12 @@ import AppEffects from "./app-effects";
import HashRouter from "./components/hash-router";
import { useWindowFocus } from "./hooks/use-window-focus";
import { Global } from "@emotion/react";
+import { isMac } from "./utils/platform";
+import useSlider from "./hooks/use-slider";
+import { AppEventManager, AppEvents } from "./common/app-events";
+import { TITLE_BAR_HEIGHT } from "./components/title-bar";
+import { getFontSizes } from "@notesnook/theme/theme/font/fontsize.js";
+import { useWindowControls } from "./hooks/use-window-controls";
new WebExtensionRelay();
@@ -47,6 +53,7 @@ function App() {
const [show, setShow] = useState(true);
const isFocusMode = useStore((store) => store.isFocusMode);
const { isFocused } = useWindowFocus();
+ const { isFullscreen } = useWindowControls();
console.timeEnd("loading app");
return (
@@ -63,6 +70,40 @@ function App() {
`}
/>
)}
+ {IS_DESKTOP_APP && isMac() && !isFullscreen ? (
+ <Global
+ // These styles to make sure the app content doesn't overlap with the traffic lights.
+ styles={`
+ .nav-pane,
+ .mobile-nav-pane {
+ margin-top: env(titlebar-area-height) !important;
+ }
+ .nav-pane.collapsed + .list-pane .route-container-header,
+ .nav-pane.collapsed + .list-pane.collapsed + .editor-pane .editor-action-bar,
+ .nav-pane.collapsed + .editor-pane .editor-action-bar {
+ padding-left: 25px;
+ }
+ .editor-pane:first-of-type .editor-action-bar,
+ .mobile-editor-pane.pane-active .editor-action-bar,
+ .mobile-list-pane.pane-active .route-container-header {
+ padding-left: 80px;
+ }
+ .route-container-header, .editor-action-bar {
+ transition: padding-left 0.4s ease-out;
+ }
+ .editor-action-bar {
+ border-bottom: none;
+ }
+ .route-container-header .routeHeader {
+ font-size: ${getFontSizes().title};
+ }
+ .global-split-pane .react-split__sash {
+ height: calc(100% - ${TITLE_BAR_HEIGHT}px);
+ }
+ `}
+ />
+ ) : null}
+
<Suspense fallback={<div style={{ display: "none" }} />}>
<div id="menu-wrapper">
<GlobalMenuWrapper />
@@ -131,6 +172,7 @@ function DesktopAppContents({ show, setShow }: DesktopAppContentsProps) {
}}
>
<SplitPane
+ className="global-split-pane"
ref={navPane}
autoSaveId="global-panel-group"
direction="vertical"
diff --git a/apps/web/src/components/editor/action-bar.tsx b/apps/web/src/components/editor/action-bar.tsx
index 55f94c53f..e3a0e63c8 100644
--- a/apps/web/src/components/editor/action-bar.tsx
+++ b/apps/web/src/components/editor/action-bar.tsx
@@ -41,7 +41,11 @@ import {
TableOfContents,
Trash,
Undo,
- Unlock
+ Unlock,
+ WindowClose,
+ WindowMaximize,
+ WindowMinimize,
+ WindowRestore
} from "../icons";
import { ScrollContainer } from "@notesnook/ui";
import {
@@ -79,11 +83,14 @@ import { showPublishView } from "../publish-view";
import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
import useMobile from "../../hooks/use-mobile";
import { strings } from "@notesnook/intl";
+import { TITLE_BAR_HEIGHT } from "../title-bar";
+import { desktop } from "../../common/desktop-bridge";
export function EditorActionBar() {
+ const { isMaximized, isFullscreen, hasNativeWindowControls } =
+ useWindowControls();
const editorMargins = useEditorStore((store) => store.editorMargins);
const isFocusMode = useAppStore((store) => store.isFocusMode);
- const { isFullscreen } = useWindowControls();
const activeSession = useEditorStore((store) =>
store.activeSessionId ? store.getSession(store.activeSessionId) : undefined
);
@@ -194,6 +201,31 @@ export function EditorActionBar() {
activeSession.type !== "conflicted" &&
!isFocusMode,
onClick: () => useEditorStore.getState().toggleProperties()
+ },
+
+ {
+ title: strings.minimize(),
+ icon: WindowMinimize,
+ hidden: hasNativeWindowControls || isFullscreen,
+ enabled: true,
+ onClick: () => desktop?.window.minimze.mutate()
+ },
+ {
+ title: isMaximized ? strings.restore() : strings.maximize(),
+ icon: isMaximized ? WindowRestore : WindowMaximize,
+ enabled: true,
+ hidden: hasNativeWindowControls || isFullscreen,
+ onClick: () =>
+ isMaximized
+ ? desktop?.window.restore.mutate()
+ : desktop?.window.maximize.mutate()
+ },
+ {
+ title: strings.close(),
+ icon: WindowClose,
+ hidden: hasNativeWindowControls || isFullscreen,
+ enabled: true,
+ onClick: () => window.close()
}
];
@@ -260,7 +292,7 @@ function TabStrip() {
<ScrollContainer
className="tabsScroll"
suppressScrollY
- style={{ flex: 1 }}
+ style={{ flex: 1, height: TITLE_BAR_HEIGHT }}
trackStyle={() => ({
backgroundColor: "transparent",
"--ms-track-size": "6px"
@@ -443,12 +475,12 @@ function Tab(props: TabProps) {
? Lock
: Unlock
: type === "readonly"
- ? Readonly
- : type === "deleted"
- ? Trash
- : isUnsaved
- ? NoteRemove
- : Note;
+ ? Readonly
+ : type === "deleted"
+ ? Trash
+ : isUnsaved
+ ? NoteRemove
+ : Note;
const { attributes, listeners, setNodeRef, transform, transition, active } =
useSortable({ id });
@@ -461,11 +493,6 @@ function Tab(props: TabProps) {
height: "100%",
cursor: "pointer",
px: 2,
- ":first-of-type": window.hasNativeTitlebar
- ? {}
- : {
- borderLeft: "1px solid var(--border)"
- },
borderRight: "1px solid var(--border)",
transform: CSS.Transform.toString(transform),
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index d337bd470..5f57263fd 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -72,10 +72,11 @@ import { NoteLinkingDialog } from "../../dialogs/note-linking-dialog";
import { strings } from "@notesnook/intl";
import { onPageVisibilityChanged } from "../../utils/page-visibility";
import { Pane, SplitPane } from "../split-pane";
+import { TITLE_BAR_HEIGHT } from "../title-bar";
const PDFPreview = React.lazy(() => import("../pdf-preview"));
-const autoSaveToast = { show: true, hide: () => {} };
+const autoSaveToast = { show: true, hide: () => { } };
async function saveContent(
noteId: string,
@@ -126,20 +127,22 @@ export default function TabsView() {
return (
<>
- {!hasNativeTitlebar ? (
- <EditorActionBarPortal />
- ) : (
- <Flex sx={{ px: 1, borderBottom: "1px solid var(--border)" }}>
- <EditorActionBar />
- </Flex>
- )}
+ <Flex
+ className="editor-action-bar"
+ sx={{
+ zIndex: 2,
+ height: TITLE_BAR_HEIGHT,
+ borderBottom: "1px solid var(--border)"
+ }}
+ >
+ <EditorActionBar />
+ </Flex>
<ScopedThemeProvider
scope="editor"
ref={dropRef}
sx={{
bg: "background",
- pt: 1,
flex: 1,
overflow: "hidden",
display: "flex",
@@ -224,10 +227,10 @@ function EditorView({
session
}: {
session:
- | DefaultEditorSession
- | NewEditorSession
- | ReadonlyEditorSession
- | DeletedEditorSession;
+ | DefaultEditorSession
+ | NewEditorSession
+ | ReadonlyEditorSession
+ | DeletedEditorSession;
}) {
const lastChangedTime = useRef<number>(0);
const root = useRef<HTMLDivElement>(null);
@@ -878,9 +881,3 @@ function UnlockNoteView(props: UnlockNoteViewProps) {
</div>
);
}
-
-function EditorActionBarPortal() {
- const container = document.getElementById("titlebar-portal-container");
- if (!container) return null;
- return ReactDOM.createPortal(<EditorActionBar />, container);
-}
diff --git a/apps/web/src/components/field/index.tsx b/apps/web/src/components/field/index.tsx
index dde2a34c6..8617c041f 100644
--- a/apps/web/src/components/field/index.tsx
+++ b/apps/web/src/components/field/index.tsx
@@ -24,6 +24,13 @@ import { ThemeUIStyleObject } from "@theme-ui/css";
import { PasswordVisible, PasswordInvisible, Icon } from "../icons";
import { useStore as useThemeStore } from "../../stores/theme-store";
+type Action = {
+ testId?: string;
+ onClick?: React.MouseEventHandler<HTMLButtonElement>;
+ disabled?: boolean;
+ icon?: Icon;
+ component?: JSX.Element;
+};
export type FieldProps = InputProps & {
label?: string;
helpText?: string;
@@ -35,13 +42,9 @@ export type FieldProps = InputProps & {
label?: ThemeUIStyleObject;
helpText?: ThemeUIStyleObject;
};
- action?: {
- testId?: string;
- onClick?: React.MouseEventHandler<HTMLButtonElement>;
- disabled?: boolean;
- icon?: Icon;
- component?: JSX.Element;
- };
+ action?: Action;
+ rightActions?: Action[];
+ leftActions?: Action[];
};
function Field(props: FieldProps) {
@@ -61,6 +64,8 @@ function Field(props: FieldProps) {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const colorScheme = useThemeStore((state) => state.colorScheme);
const [isValid, setIsValid] = useState(true);
+ const rightActions = props.rightActions || (action ? [action] : []);
+ const leftActions = props.leftActions || [];
return (
<Flex
@@ -68,6 +73,7 @@ function Field(props: FieldProps) {
m: "2px",
mr: "2px",
opacity: disabled ? 0.7 : 1,
+ gap: 1,
...sx,
flexDirection: "column"
}}
@@ -98,7 +104,7 @@ function Field(props: FieldProps) {
)}
</Label>
- <Flex mt={1} sx={{ position: "relative" }}>
+ <Flex sx={{ position: "relative", flex: 1 }}>
<Input
{...inputProps}
variant={isValid ? inputProps.variant || "input" : "error"}
@@ -139,32 +145,89 @@ function Field(props: FieldProps) {
{isPasswordVisible ? <PasswordVisible /> : <PasswordInvisible />}
</Flex>
)}
- {action && (
- <Button
- type="button"
- variant={"secondary"}
- data-test-id={action.testId}
- onClick={action.onClick}
+
+ {rightActions.length > 0 ? (
+ <Flex
sx={{
- bg: "transparent",
position: "absolute",
- margin: 0,
top: 0,
- right: "2px",
+ left: 0,
height: "100%",
- px: 1,
- borderRadius: "default",
- ":hover": { bg: "border" }
+ borderTopLeftRadius: "default",
+ borderBottomLeftRadius: "default",
+ overflow: "hidden"
}}
- disabled={action.disabled}
>
- {action.component ? (
- action.component
- ) : action.icon ? (
- <action.icon size={20} />
- ) : null}
- </Button>
- )}
+ {leftActions.map((action) => (
+ <Button
+ key={action.testId}
+ type="button"
+ variant={"secondary"}
+ data-test-id={action.testId}
+ onClick={action.onClick}
+ sx={{
+ p: 0,
+ px: 1,
+ height: "100%",
+ bg: "transparent",
+ borderRadius: 0,
+ margin: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center"
+ }}
+ disabled={action.disabled}
+ >
+ {action.component ? (
+ action.component
+ ) : action.icon ? (
+ <action.icon size={20} />
+ ) : null}
+ </Button>
+ ))}
+ </Flex>
+ ) : null}
+ {rightActions.length > 0 ? (
+ <Flex
+ sx={{
+ position: "absolute",
+ top: 0,
+ right: 0,
+ height: "100%",
+ borderTopRightRadius: "default",
+ borderBottomRightRadius: "default",
+ overflow: "hidden"
+ }}
+ >
+ {rightActions.map((action) => (
+ <Button
+ key={action.testId}
+ type="button"
+ variant={"secondary"}
+ data-test-id={action.testId}
+ onClick={action.onClick}
+ sx={{
+ p: 0,
+ px: 1,
+ height: "100%",
+ bg: "transparent",
+ borderRadius: 0,
+ margin: 0,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center"
+ }}
+ disabled={action.disabled}
+ >
+ {action.component ? (
+ action.component
+ ) : action.icon ? (
+ <action.icon size={20} />
+ ) : null}
+ </Button>
+ ))}
+ </Flex>
+ ) : null}
</Flex>
</Flex>
);
diff --git a/apps/web/src/components/route-container/index.tsx b/apps/web/src/components/route-container/index.tsx
index b5523195e..34b2ec73f 100644
--- a/apps/web/src/components/route-container/index.tsx
+++ b/apps/web/src/components/route-container/index.tsx
@@ -26,6 +26,7 @@ import useMobile from "../../hooks/use-mobile";
import { debounce, usePromise } from "@notesnook/common";
import Field from "../field";
import { strings } from "@notesnook/intl";
+import { TITLE_BAR_HEIGHT } from "../title-bar";
import { AppEventManager, AppEvents } from "../../common/app-events";
export type RouteContainerButtons = {
@@ -72,16 +73,23 @@ function Header(props: RouteContainerProps) {
if (isSearching)
return (
<Flex
- sx={{ alignItems: "center", justifyContent: "center", mx: 1, my: 1 }}
+ sx={{
+ alignItems: "center",
+ justifyContent: "center",
+ height: TITLE_BAR_HEIGHT,
+ zIndex: 2
+ }}
+ className="route-container-header search-container"
>
<Field
data-test-id="search-input"
autoFocus
id="search"
name="search"
+ variant="borderless"
type="text"
- sx={{ m: 0, flex: 1 }}
- styles={{ input: { p: "7px" } }}
+ sx={{ m: 0, flex: 1, gap: 0 }}
+ styles={{ input: { p: "5px", m: 0 } }}
defaultValue={query}
placeholder={strings.typeAKeyword()}
onChange={debounce(
@@ -111,11 +119,12 @@ function Header(props: RouteContainerProps) {
return (
<Flex
className="route-container-header"
- mx={2}
sx={{
+ px: 1,
alignItems: "center",
justifyContent: "space-between",
- height: 42.8
+ height: TITLE_BAR_HEIGHT,
+ zIndex: 2
}}
>
<Flex
@@ -123,16 +132,18 @@ function Header(props: RouteContainerProps) {
sx={{
alignItems: "center",
justifyContent: "center",
- overflow: "hidden"
+ overflow: "hidden",
+ gap: 1
}}
>
{buttons?.back ? (
- <ArrowLeft
- size={24}
+ <Button
{...buttons.back}
- sx={{ flexShrink: 0, mr: 2, cursor: "pointer" }}
data-test-id="go-back"
- />
+ sx={{ p: 0, flexShrink: 0 }}
+ >
+ <ArrowLeft size={20} />
+ </Button>
) : (
<Button
onClick={() =>
@@ -140,51 +151,61 @@ function Header(props: RouteContainerProps) {
}
sx={{ p: 0, flexShrink: 0 }}
>
- <Menu
- sx={{
+ <Menu
+ sx={{
display: ["block", "none", "none"],
size: 23
- }}
+ }}
size={24}
- />
+ />
</Button>
)}
{titlePromise.status === "fulfilled" && titlePromise.value && (
- <Text variant="heading" data-test-id="routeHeader" color="heading">
+ <Text
+ className="routeHeader"
+ variant="heading"
+ data-test-id="routeHeader"
+ color="heading"
+ >
{titlePromise.value}
</Text>
)}
</Flex>
- <Flex sx={{ flexShrink: 0 }}>
+ <Flex sx={{ flexShrink: 0, gap: 2 }}>
{buttons?.search && (
- <Search
- data-test-id={"open-search"}
- size={24}
+ <Button
title={buttons.search.title}
onClick={() =>
useSearchStore.setState({ isSearching: true, searchType: type })
}
- sx={{
- size: 24,
- cursor: "pointer"
- }}
- />
+ data-test-id={"open-search"}
+ sx={{ p: 0 }}
+ >
+ <Search
+ size={24}
+ sx={{
+ size: 24
+ }}
+ />
+ </Button>
)}
{!isMobile && buttons?.create && (
- <Plus
- data-test-id={`${type}-action-button`}
- color="accentForeground"
- size={18}
- sx={{
- bg: "accent",
- ml: 2,
- borderRadius: 100,
- size: 28,
- cursor: "pointer",
- ":hover": { boxShadow: "0px 0px 5px 0px var(--accent)" }
- }}
+ <Button
{...buttons.create}
- />
+ data-test-id={`${type}-action-button`}
+ sx={{ p: 0 }}
+ >
+ <Plus
+ color="accentForeground"
+ size={18}
+ sx={{
+ height: 24,
+ width: 24,
+ bg: "accent",
+ borderRadius: 100
+ }}
+ />
+ </Button>
)}
</Flex>
</Flex>
diff --git a/apps/web/src/components/title-bar/index.tsx b/apps/web/src/components/title-bar/index.tsx
index 5057431ba..0183d4c6e 100644
--- a/apps/web/src/components/title-bar/index.tsx
+++ b/apps/web/src/components/title-bar/index.tsx
@@ -17,51 +17,15 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { Button } from "@theme-ui/components";
-import { desktop } from "../../common/desktop-bridge";
import { useWindowControls } from "../../hooks/use-window-controls";
-import { getPlatform } from "../../utils/platform";
-import {
- WindowClose,
- WindowMaximize,
- WindowMinimize,
- WindowRestore
-} from "../icons";
+import { isMac } from "../../utils/platform";
import { BaseThemeProvider } from "../theme-provider";
-import { strings } from "@notesnook/intl";
-export const TITLE_BAR_HEIGHT = IS_DESKTOP_APP ? 37.8 : 0;
+export const TITLE_BAR_HEIGHT = 37;
export function TitleBar() {
- const { isMaximized, isFullscreen, hasNativeWindowControls } =
- useWindowControls();
-
- const tools = [
- {
- title: strings.minimize(),
- icon: WindowMinimize,
- hidden: hasNativeWindowControls || isFullscreen,
- enabled: true,
- onClick: () => desktop?.window.minimze.mutate()
- },
- {
- title: isMaximized ? strings.restore() : strings.maximize(),
- icon: isMaximized ? WindowRestore : WindowMaximize,
- enabled: true,
- hidden: hasNativeWindowControls || isFullscreen,
- onClick: () =>
- isMaximized
- ? desktop?.window.restore.mutate()
- : desktop?.window.maximize.mutate()
- },
- {
- title: strings.close(),
- icon: WindowClose,
- hidden: hasNativeWindowControls || isFullscreen,
- enabled: true,
- onClick: () => window.close()
- }
- ];
+ const { isFullscreen } = useWindowControls();
+ if (isFullscreen || !IS_DESKTOP_APP || !isMac()) return null;
return (
<BaseThemeProvider
scope="titleBar"
@@ -73,63 +37,13 @@ export function TitleBar() {
maxHeight: TITLE_BAR_HEIGHT,
display: "flex",
flexShrink: 0,
- borderBottom: "1px solid var(--border)",
- ...(!isFullscreen && hasNativeWindowControls
- ? getPlatform() === "darwin"
- ? { pl: "calc(100vw - env(titlebar-area-width))" }
- : { pr: "calc(100vw - env(titlebar-area-width))" }
- : { pr: 0 })
+ position: "absolute",
+ top: 0,
+ width: "100%",
+ zIndex: 1,
+ borderBottom: "1px solid var(--border)"
}}
injectCssVars
- >
- {getPlatform() !== "darwin" || isFullscreen ? (
- <svg
- className="titlebarLogo"
- style={{
- alignSelf: "center",
- height: 16,
- width: 12,
- marginRight: 10,
- marginLeft: 10
- }}
- >
- <use href="#themed-logo" />
- </svg>
- ) : null}
- <div
- id="titlebar-portal-container"
- style={{
- flex: 1,
- display: "flex",
- overflow: "hidden"
- }}
- />
- {tools.map((tool) => (
- <Button
- data-test-id={tool.title}
- disabled={!tool.enabled}
- variant={tool.title === "Close" ? "error" : "secondary"}
- title={tool.title}
- key={tool.title}
- sx={{
- height: "100%",
- alignItems: "center",
- bg: "transparent",
- display: tool.hidden ? "none" : "flex",
- borderRadius: 0,
- flexShrink: 0,
- "&:hover svg path": {
- fill:
- tool.title === "Close"
- ? "var(--accentForeground-error) !important"
- : "var(--icon)"
- }
- }}
- onClick={tool.onClick}
- >
- <tool.icon size={18} />
- </Button>
- ))}
- </BaseThemeProvider>
+ ></BaseThemeProvider>
);
}