mirror of
https://github.com/outline/outline.git
synced 2026-12-03 10:00:13 +03:00
* Fix issue #8026: Prevent multiple context menus from being open simultaneously - Created useCoordinatedMenuState hook that wraps Reakit's useMenuState - Enhanced MenuProvider with menu registry and coordination logic - Expanded MenuProvider scope to wrap entire application - Updated key menu components to use coordinated menu state: - DocumentMenu - Template (SubMenu) - FilterOptions - AccountMenu - CollectionMenu - Ensures only one context menu can be open at a time - Maintains existing Reakit integration and component structure * Update all imports, add lint rule * Update to named export * fix: Sidebar still needs separate MenuProvider to track isOpen within * fix: Cannot directly open a menu with another open --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import { ShapesIcon } from "outline-icons";
|
|
import { useTranslation } from "react-i18next";
|
|
import { MenuButton } from "reakit/Menu";
|
|
import Document from "~/models/Document";
|
|
import Button from "~/components/Button";
|
|
import ContextMenu from "~/components/ContextMenu";
|
|
import Template from "~/components/ContextMenu/Template";
|
|
import { useMenuState } from "~/hooks/useMenuState";
|
|
import { useTemplateMenuItems } from "~/hooks/useTemplateMenuItems";
|
|
|
|
type Props = {
|
|
/** The document to which the templates will be applied */
|
|
document: Document;
|
|
/** Whether to render the button as a compact icon */
|
|
isCompact?: boolean;
|
|
/** Callback to handle when a template is selected */
|
|
onSelectTemplate: (template: Document) => void;
|
|
};
|
|
|
|
function TemplatesMenu({ isCompact, onSelectTemplate, document }: Props) {
|
|
const { t } = useTranslation();
|
|
const menu = useMenuState({
|
|
modal: true,
|
|
});
|
|
|
|
const items = useTemplateMenuItems({ onSelectTemplate, document });
|
|
|
|
if (!items.length) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<MenuButton {...menu}>
|
|
{(props) => (
|
|
<Button
|
|
{...props}
|
|
icon={isCompact ? <ShapesIcon /> : undefined}
|
|
disclosure={!isCompact}
|
|
neutral
|
|
>
|
|
{isCompact ? undefined : t("Templates")}
|
|
</Button>
|
|
)}
|
|
</MenuButton>
|
|
<ContextMenu {...menu} aria-label={t("Templates")}>
|
|
<Template {...menu} items={items} />
|
|
</ContextMenu>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default observer(TemplatesMenu);
|