import { useRef } from "../deps.ts"; import { ComponentChildren } from "../deps.ts"; import { Notification } from "../types.ts"; import { FunctionalComponent } from "https://esm.sh/v99/preact@10.11.1/src/index"; import { FeatherProps } from "https://esm.sh/v99/preact-feather@4.2.1/dist/types"; function prettyName(s: string | undefined): string { if (!s) { return ""; } return s.replaceAll("/", " / "); } export type ActionButton = { icon: FunctionalComponent; 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); 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}
); }