mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-08 11:44:05 +00:00
Dependencies overhaul - Update dependencies for all projects (except Mobile-only deps) - Remove unused dependencies from all projects (except Mobile-only deps) - Fix Storybook failing to import sd/ui style - Add Node 21 as not supported due to sass-loader not working on it yet - Add work-around for new rook version requiring webpack specific global property - Fix landing dev not working due to missing default env value on dev - Fix some incorrect uses of phosphor-icons non server side icons on server components on landing - Fix some incorrect uses of phosphor-icons server side icon on client components on landing - Fix landing fail to build on dev due to always required a Github Token to get the latest release - Fix new Next.js version not suporting Response.redirect due to immutable Headers - Add Gitlab as social link for teams page - Update Vítor's team photo - Add Vítor's twitter link - Fix some warning due to missing useEffect dependencies - Remove test-files dir - Fix QuickPreview unblurred buttons in Linux - Formatting
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { ContextMenu, DropdownMenu, useContextMenuContext, useDropdownMenuContext } from '@sd/ui';
|
|
|
|
export const useMenu = (): typeof DropdownMenu | typeof ContextMenu | null => {
|
|
const isDropdownMenu = useDropdownMenuContext();
|
|
const isContextMenu = useContextMenuContext();
|
|
|
|
const menu = useMemo(
|
|
() => (isDropdownMenu ? DropdownMenu : isContextMenu ? ContextMenu : null),
|
|
[isDropdownMenu, isContextMenu]
|
|
);
|
|
|
|
return menu;
|
|
};
|
|
|
|
const Separator = (
|
|
props: Parameters<typeof ContextMenu.Separator | typeof DropdownMenu.Separator>[0]
|
|
) => {
|
|
const Menu = useMenu();
|
|
|
|
if (!Menu) return null;
|
|
|
|
return <Menu.Separator {...props} />;
|
|
};
|
|
|
|
const SubMenu = (
|
|
props: Parameters<typeof ContextMenu.SubMenu | typeof DropdownMenu.SubMenu>[0]
|
|
) => {
|
|
const Menu = useMenu();
|
|
|
|
if (!Menu) return null;
|
|
|
|
return <Menu.SubMenu {...props} />;
|
|
};
|
|
|
|
const Item = (props: Parameters<typeof ContextMenu.Item | typeof DropdownMenu.Item>[0]) => {
|
|
const ContextMenu = useMenu();
|
|
|
|
if (!ContextMenu) return null;
|
|
|
|
return <ContextMenu.Item {...props} />;
|
|
};
|
|
|
|
export const Menu = {
|
|
Item,
|
|
Separator,
|
|
SubMenu
|
|
};
|