import type { ReactNode } from 'react'; import { useNavigate } from 'react-router-dom'; import { Box, IconButton, Stack, Tooltip, Typography } from '@mui/material'; import ArrowBack from '@mui/icons-material/ArrowBack'; import { useT } from '../i18n'; /** Back one step in the browser history, or to `to` when this page was opened directly. */ export function BackButton({ to }: { to: string }) { const nav = useNavigate(); const t = useT(); const goBack = () => { const idx = (window.history.state as { idx?: number } | null)?.idx ?? 0; if (idx > 0) nav(-1); else nav(to); }; return ( ); } export function PageHeader({ title, subtitle, actions, lead, backTo, }: { title: ReactNode; subtitle?: ReactNode; actions?: ReactNode; lead?: ReactNode; /** show a back button; the value is where to go when there is no history */ backTo?: string; }) { return ( {backTo && } {lead} {/* the page's one h1: a screen reader's outline starts from it */} {title} {subtitle && {subtitle}} {actions && {actions}} ); }