import { For, Show, createMemo, type JSX } from "solid-js"; import { Portal } from "solid-js/web"; import { X } from "../../../lib/icons"; import { getWorkspaceContextMenuEyebrow, getWorkspaceContextMenuSections, type WorkspaceContextMenuAction, type WorkspaceContextMenuSection, type WorkspaceContextMenuTarget, } from "../data/shell.data"; import styles from "./WorkspaceMobileActionSheet.module.scss"; type WorkspaceMobileActionSheetProps = { target: WorkspaceContextMenuTarget | null; onClose: VoidFunction; onSelect: (action: WorkspaceContextMenuAction, target: WorkspaceContextMenuTarget) => void; }; type FlattenedActionSection = { id: string; label?: string; items: readonly WorkspaceContextMenuAction[]; }; const flattenMobileSections = ( sections: readonly WorkspaceContextMenuSection[], ): readonly FlattenedActionSection[] => { // Mobile uses a flat action-sheet model, so desktop flyout groups become // standalone labeled sections instead of nested menus. return sections.flatMap((section) => { const directActions = section.items.filter((action) => !action.children?.length); const nestedSections = section.items .filter((action) => action.children?.length) .map((action) => ({ id: `${section.id}-${action.id}`, label: action.label, items: action.children ?? [], })); const flattenedSections: FlattenedActionSection[] = []; if (directActions.length > 0) { flattenedSections.push({ id: section.id, label: section.label, items: directActions, }); } return [...flattenedSections, ...nestedSections]; }); }; export const WorkspaceMobileActionSheet = (props: WorkspaceMobileActionSheetProps): JSX.Element => { const sheetState = createMemo(() => { if (!props.target) { return null; } return { target: props.target, sections: flattenMobileSections(getWorkspaceContextMenuSections(props.target)), }; }); const handleActionSelect = (action: WorkspaceContextMenuAction, target: WorkspaceContextMenuTarget): void => { props.onSelect(action, target); props.onClose(); }; return ( {(sheetState): JSX.Element => { const target = sheetState().target; const sections = sheetState().sections; return (
{(section): JSX.Element => (
{section.label}
{(action): JSX.Element => ( )}
)}
); }}
); };