contextMenu.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import styled from '@emotion/styled';
  2. import classNames from 'classnames';
  3. import DeprecatedDropdownMenu from 'sentry/components/deprecatedDropdownMenu';
  4. import {IconEllipsis} from 'sentry/icons';
  5. const ContextMenu = ({children}) => (
  6. <DeprecatedDropdownMenu>
  7. {({isOpen, getRootProps, getActorProps, getMenuProps}) => {
  8. const topLevelCx = classNames('dropdown', {
  9. 'anchor-right': true,
  10. open: isOpen,
  11. });
  12. return (
  13. <MoreOptions
  14. {...getRootProps({
  15. className: topLevelCx,
  16. })}
  17. >
  18. <DropdownTarget
  19. {...getActorProps<HTMLDivElement>({
  20. onClick: (event: React.MouseEvent) => {
  21. event.stopPropagation();
  22. event.preventDefault();
  23. },
  24. })}
  25. >
  26. <IconEllipsis data-test-id="context-menu" size="md" />
  27. </DropdownTarget>
  28. {isOpen && (
  29. <ul {...getMenuProps({})} className={classNames('dropdown-menu')}>
  30. {children}
  31. </ul>
  32. )}
  33. </MoreOptions>
  34. );
  35. }}
  36. </DeprecatedDropdownMenu>
  37. );
  38. const MoreOptions = styled('span')`
  39. display: flex;
  40. color: ${p => p.theme.textColor};
  41. `;
  42. const DropdownTarget = styled('div')`
  43. display: flex;
  44. cursor: pointer;
  45. padding: 0 5px;
  46. `;
  47. export default ContextMenu;