GeomapTooltip.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import { useDialog } from '@react-aria/dialog';
  2. import { useOverlay } from '@react-aria/overlays';
  3. import React, { createRef } from 'react';
  4. import { VizTooltipContainer } from '@grafana/ui';
  5. import { ComplexDataHoverView } from './components/ComplexDataHoverView';
  6. import { GeomapHoverPayload } from './event';
  7. interface Props {
  8. ttip?: GeomapHoverPayload;
  9. isOpen: boolean;
  10. onClose: () => void;
  11. }
  12. export const GeomapTooltip = ({ ttip, onClose, isOpen }: Props) => {
  13. const ref = createRef<HTMLElement>();
  14. const { overlayProps } = useOverlay({ onClose, isDismissable: true, isOpen }, ref);
  15. const { dialogProps } = useDialog({}, ref);
  16. return (
  17. <>
  18. {ttip && ttip.layers && (
  19. <VizTooltipContainer position={{ x: ttip.pageX, y: ttip.pageY }} offset={{ x: 10, y: 10 }} allowPointerEvents>
  20. <section ref={ref} {...overlayProps} {...dialogProps}>
  21. <ComplexDataHoverView layers={ttip.layers} isOpen={isOpen} onClose={onClose} />
  22. </section>
  23. </VizTooltipContainer>
  24. )}
  25. </>
  26. );
  27. };