1
0
silverbullet/packages/web/components/top_bar.tsx

74 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-07-04 09:38:16 +00:00
import { faRunning, faHome } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Notification } from "../types";
function prettyName(s: string | undefined): string {
if (!s) {
return "";
}
return s.replaceAll("/", " / ");
}
export function TopBar({
pageName,
unsavedChanges,
notifications,
onClick,
2022-07-04 09:38:16 +00:00
onHomeClick,
onActionClick,
2022-04-04 16:33:13 +00:00
lhs,
rhs,
}: {
pageName?: string;
unsavedChanges: boolean;
notifications: Notification[];
onClick: () => void;
2022-07-04 09:38:16 +00:00
onHomeClick: () => void;
onActionClick: () => void;
2022-04-04 16:33:13 +00:00
lhs?: React.ReactNode;
rhs?: React.ReactNode;
}) {
return (
<div id="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
className={`current-page ${unsavedChanges ? "unsaved" : "saved"}`}
>
{prettyName(pageName)}
2022-04-04 16:33:13 +00:00
</span>
{notifications.length > 0 && (
<div className="status">
{notifications.map((notification) => (
<div key={notification.id}>{notification.message}</div>
))}
</div>
)}
2022-05-06 16:55:04 +00:00
<div className="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();
}}
2022-07-04 09:38:16 +00:00
title="Open the command palette"
2022-06-17 18:17:22 +00:00
>
<FontAwesomeIcon icon={faRunning} />
2022-06-17 18:17:22 +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>
);
}