// import { Fragment, h } from "../deps.ts"; import { FontAwesomeIcon, useRef } from "../deps.ts"; import { ComponentChildren, IconDefinition, useEffect, 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 type ActionButton = { icon: IconDefinition; description: string; callback: () => void; }; export function TopBar({ pageName, unsavedChanges, isLoading, notifications, onRename, actionButtons, lhs, rhs, }: { pageName?: string; unsavedChanges: boolean; isLoading: boolean; notifications: Notification[]; onRename: (newName?: string) => void; actionButtons: ActionButton[]; lhs?: ComponentChildren; rhs?: ComponentChildren; }) { // const [theme, setTheme] = useState(localStorage.theme ?? "light"); const inputRef = useRef(null); // const isMac = isMacLike(); return (
{lhs}
{ (e.target as any).value = pageName; }} onKeyDown={(e) => { e.stopPropagation(); if (e.key === "Enter") { e.preventDefault(); const newName = (e.target as any).value; onRename(newName); } if (e.key === "Escape") { onRename(); } }} /> {notifications.length > 0 && (
{notifications.map((notification) => (
{notification.message}
))}
)}
{actionButtons.map((actionButton) => ( ))}
{rhs}
); }