1
0
silverbullet/web/components/top_bar.tsx

114 lines
2.8 KiB
TypeScript
Raw Normal View History

// import { Fragment, h } from "../deps.ts";
import {
faHome,
faMoon,
faRunning,
faSun,
} from "https://esm.sh/@fortawesome/free-solid-svg-icons@6.2.0";
import { FontAwesomeIcon } from "../deps.ts";
import { ComponentChildren, useState } from "../deps.ts";
import { Notification } from "../types.ts";
import { isMacLike } from "../../common/util.ts";
function prettyName(s: string | undefined): string {
if (!s) {
return "";
}
return s.replaceAll("/", " / ");
}
export function TopBar({
pageName,
unsavedChanges,
isLoading,
notifications,
onClick,
2022-08-26 22:32:40 +00:00
onThemeClick,
2022-07-04 09:38:16 +00:00
onHomeClick,
onActionClick,
2022-04-04 16:33:13 +00:00
lhs,
rhs,
}: {
pageName?: string;
unsavedChanges: boolean;
isLoading: boolean;
notifications: Notification[];
onClick: () => void;
2022-08-26 22:32:40 +00:00
onThemeClick: () => void;
2022-07-04 09:38:16 +00:00
onHomeClick: () => void;
onActionClick: () => void;
lhs?: ComponentChildren;
rhs?: ComponentChildren;
}) {
const [theme, setTheme] = useState<string>(localStorage.theme ?? "light");
2022-08-26 22:32:40 +00:00
2022-09-24 17:01:16 +00:00
const isMac = isMacLike();
return (
2022-07-22 11:44:28 +00:00
<div id="sb-top" onClick={onClick}>
2022-04-04 16:33:13 +00:00
{lhs}
<div className="main">
<div className="inner">
2022-04-10 09:04:07 +00:00
<span
2022-08-02 12:40:04 +00:00
className={`sb-current-page ${
isLoading
? "sb-loading"
: unsavedChanges
? "sb-unsaved"
: "sb-saved"
2022-08-02 12:40:04 +00:00
}`}
2022-04-10 09:04:07 +00:00
>
{prettyName(pageName)}
2022-04-04 16:33:13 +00:00
</span>
{notifications.length > 0 && (
2022-08-02 12:40:04 +00:00
<div className="sb-notifications">
2022-04-04 16:33:13 +00:00
{notifications.map((notification) => (
<div
key={notification.id}
2022-08-02 12:40:04 +00:00
className={`sb-notification-${notification.type}`}
>
{notification.message}
</div>
2022-04-04 16:33:13 +00:00
))}
</div>
)}
2022-08-02 12:40:04 +00:00
<div className="sb-actions">
2022-06-17 18:17:22 +00:00
<button
onClick={(e) => {
2022-07-04 09:38:16 +00:00
onHomeClick();
e.stopPropagation();
}}
title="Navigate to the 'index' page"
>
<FontAwesomeIcon icon={faHome} />
</button>
<button
onClick={(e) => {
onActionClick();
2022-06-17 18:17:22 +00:00
e.stopPropagation();
}}
title={"Open the command palette (" + (isMac ? "Cmd" : "Ctrl") +
"+/)"}
2022-06-17 18:17:22 +00:00
>
<FontAwesomeIcon icon={faRunning} />
2022-06-17 18:17:22 +00:00
</button>
2022-08-26 22:32:40 +00:00
<button
onClick={(e) => {
onThemeClick();
setTheme(localStorage.theme ?? "light");
2022-08-26 22:32:40 +00:00
e.stopPropagation();
}}
title="Toggle theme"
>
<FontAwesomeIcon icon={theme === "dark" ? faSun : faMoon} />
2022-08-26 22:32:40 +00:00
</button>
2022-05-06 16:55:04 +00:00
</div>
2022-04-04 16:33:13 +00:00
</div>
</div>
2022-04-04 16:33:13 +00:00
{rhs}
</div>
);
}