/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ import Icon, {MacCommandOutlined} from '@ant-design/icons'; import {css} from '@emotion/css'; import {Button, Menu, MenuItemProps, Row, Tooltip} from 'antd'; import { NormalizedMenuEntry, NUX, TrackingScope, useTrackedCallback, } from 'flipper-plugin'; import React, {useEffect} from 'react'; import {getActivePlugin} from '../selectors/connections'; import {registerShortcut} from '../utils/registerShortcut'; import {useStore} from '../utils/useStore'; function MagicIcon() { return ( // https://www.svgrepo.com/svg/59702/magic Magic ); } const menu = css` border: none; `; const submenu = css` .ant-menu-submenu-title { width: 32px; height: 32px !important; line-height: 32px !important; padding: 0; margin: 0; } .ant-menu-submenu-arrow { display: none; } `; function PluginActionMenuItem({ label, action, handler, accelerator, // Some props like `eventKey` are auto-generated by ant-design // We need to pass them through to MenuItem ...antdProps }: NormalizedMenuEntry & MenuItemProps) { const trackedHandler = useTrackedCallback(action, handler, [action, handler]); useEffect(() => { if (accelerator) { return registerShortcut(accelerator, trackedHandler); } }, [trackedHandler, accelerator]); return ( {label} {accelerator ? ( ) : null} ); } export function PluginActionsMenu() { const menuEntries = useStore((state) => state.connections.pluginMenuEntries); const activePlugin = useStore(getActivePlugin); if (!menuEntries.length || !activePlugin) { return null; } return ( } title="Plugin actions" type="ghost" /> } className={submenu}> {menuEntries.map((entry) => ( ))} ); }