import type { LucideIcon } from 'lucide-react';
import { ChevronLeft } from 'lucide-react';
import type { ReactNode } from 'react';
export interface MSection {
id: string;
label: string;
icon: LucideIcon;
/**
* The heading the section stands under. Consecutive sections with the same
* group share one heading; a screen whose sections name none shows none.
*/
group?: string;
}
interface MSectionRowProps {
section: MSection;
active: boolean;
/** Marks the row as the page on show, for the list that stands beside the page. */
current?: boolean;
onPick: () => void;
}
/** One section of a settings-like screen, in its dropdown or in the list beside the page. */
function MSectionRow({ section, active, current = false, onPick }: MSectionRowProps) {
return (
);
}
/**
* The sections in order, each run of one group under its heading: the same list
* in the dropdown of a phone and in the list beside the page.
*/
export function MSectionList({
sections,
activeId,
markCurrent = false,
onPick,
}: {
sections: MSection[];
activeId: string;
/** Marks the active row as the page on show (the list beside the page). */
markCurrent?: boolean;
onPick: (id: string) => void;
}) {
return (
<>
{sections.map((section, i) => {
const heading = section.group && section.group !== sections[i - 1]?.group ? section.group : null;
return (
{heading && (
{heading}
)}
onPick(section.id)}
/>
);
})}
>
);
}
/**
* The frame of a settings-like screen (settings, administration), one rule for
* both: the page column on a phone, a centred column on a wide window, and from
* the split size class the list of sections beside a page that runs to the same
* width on both screens.
*/
export const SECTION_SCREEN =
'm-corner-flow px-4 pb-[calc(var(--bottom-nav-h,84px)+16px)] pt-[var(--m-safe-top,12px)] wide:mx-auto wide:max-w-[1040px] wide:px-6 split:grid split:max-w-[1240px] split:grid-cols-[260px_minmax(0,1fr)] split:items-start split:gap-8';
interface MSectionNavProps {
title: string;
backLabel: string;
onBack: () => void;
sections: MSection[];
activeId: string;
onPick: (id: string) => void;
/**
* An action of the screen (admin: a new user), on a line of its own under the
* title, so a long title in a long language keeps the whole width.
*/
action?: ReactNode;
}
/**
* The sections of a settings-like screen (settings, administration) as a list
* of their own beside the page, the way Settings on an iPad shows them, once
* the window has room for two panes. It stays in view while the page scrolls.
* Narrower windows keep the dropdown in the screen's header.
*/
export default function MSectionNav({
title,
backLabel,
onBack,
sections,
activeId,
onPick,
action,
}: MSectionNavProps) {
return (
);
}