Spaces:
Sleeping
Sleeping
File size: 3,600 Bytes
25b02dd f9c7101 33ce28f 92d45ee 144145d f9c7101 33ce28f f56442a 33ce28f f9c7101 33ce28f 144145d 33ce28f 144145d 25b02dd f9c7101 25b02dd 33ce28f f9c7101 a73107f 33ce28f a73107f 144145d f9c7101 33ce28f 92d45ee 25b02dd f56442a 25b02dd 92d45ee 33ce28f f9c7101 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 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>
);
}
|