EnergyVenom's picture
Deploy 7831dd1: layout fixes, sidebar folds to icons
f56442a verified
Raw History Blame Contribute Delete
3.6 kB
import { Button } from '@mantine/core';
import { IconChevronLeft, IconLayoutSidebar, IconMenu2, IconSearch, IconSparkles } from '@tabler/icons-react';
import type { ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { NotificationBell } from '../../notify/NotificationBell';
import { EnvBadge, envKind, useChosenEnv } from './EnvSwitcher';
import { useShell } from './prefs';
export const isMac = () => typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
/** The toolbar of every page: sidebar toggle, back link, title and one-line caption on the left; a state chip, the page's
* actions and the search field (it opens the command palette, Ctrl K) on the right. Translucent, content scrolls under it.
* When the sidebar is folded to its icons, the practice-environment cue is repeated here so it never disappears. */
export function TopBar({ title, sub, middle, actions, titleTestId, honesty = true, back, plainTitle = false }: {
title: ReactNode; sub?: ReactNode; middle?: ReactNode; actions?: ReactNode; titleTestId?: string; honesty?: boolean; back?: { label: string; to: string };
/** The page has its own large heading: the toolbar shows the title as plain text, not a second heading. */
plainTitle?: boolean;
}) {
const { size, sidebarExpanded, toggleSidebar, openNav, openPalette } = useShell();
const { pod } = useChosenEnv();
const drawer = size === 'tablet' || size === 'phone';
const cue = honesty && !sidebarExpanded && pod && envKind(pod.kind) === 'mock'
? <span className="fpt-topbar-cue"><EnvBadge kind="mock" /></span> : null;
const phone = size === 'phone';
return (
<header className="fpt-topbar pw-topbar" data-size={size}>
{drawer
? <button type="button" className="fpt-iconbtn fpt-topbar-menu" aria-label="Open the menu" onClick={openNav}><IconMenu2 size={17} /></button>
: <button type="button" className="fpt-iconbtn fpt-topbar-menu" aria-label={sidebarExpanded ? 'Hide the sidebar' : 'Show the sidebar'} aria-pressed={sidebarExpanded} title="Hide or show the sidebar ([)" onClick={toggleSidebar}><IconLayoutSidebar size={17} stroke={1.7} /></button>}
{back && <Link to={back.to} className="fpt-back" aria-label={`Back to ${back.label}`}><IconChevronLeft size={16} stroke={2} aria-hidden />{back.label}</Link>}
<div className="fpt-topbar-left">
<div className="fpt-topbar-row1">
{plainTitle ? <div className="fpt-title" data-testid={titleTestId}>{title}</div> : <h1 className="fpt-title" data-testid={titleTestId}>{title}</h1>}
{middle && <div className="fpt-topbar-mid">{middle}</div>}
</div>
{(sub || cue) && <div className="fpt-topbar-sub">{sub}{sub && cue ? <span aria-hidden className="fpt-topbar-dotsep">·</span> : null}{cue}</div>}
</div>
<div className="fpt-topbar-actions">
{actions}
<NotificationBell />
{!phone && (
<Button component={Link} to="/assistant" variant="default" size="xs" className="pw-askai" aria-label="Ask AI" title="Ask AI" leftSection={<IconSparkles size={14} aria-hidden />}>Ask AI</Button>
)}
<button type="button" className="fpt-search" onClick={openPalette} aria-label={`Search or ask ${isMac() ? '⌘K' : 'Ctrl K'}`} title="Search, go to a page or ask a question">
<IconSearch size={16} stroke={1.8} aria-hidden /><span>Search or ask</span>{' '}<kbd>{isMac() ? '⌘K' : 'Ctrl K'}</kbd>
</button>
</div>
</header>
);
}