index.tsx 985 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import { Manager, Reference, Popper } from 'react-popper';
  3. import { TargetContainer, TooltipContainer, Arrow } from './styled';
  4. import Portal from '../Portal';
  5. type Props = {
  6. anchor?: 'left' | 'right' | 'top' | 'bottom';
  7. children: React.ReactNode;
  8. content: React.ReactNode;
  9. };
  10. const Tooltip : React.FunctionComponent<Props> = ({
  11. anchor = 'left',
  12. children,
  13. content,
  14. }) => (
  15. <Manager>
  16. <Reference>
  17. {({ ref }) => (
  18. <TargetContainer ref={ref}>
  19. {children}
  20. </TargetContainer>
  21. )}
  22. </Reference>
  23. <Portal>
  24. <Popper placement={anchor}>
  25. {({ ref, style, placement, arrowProps }) => (
  26. <TooltipContainer ref={ref} style={style} data-placement={placement}>
  27. {content}
  28. <Arrow data-placement={placement} ref={arrowProps.ref} style={arrowProps.style} />
  29. </TooltipContainer>
  30. )}
  31. </Popper>
  32. </Portal>
  33. </Manager>
  34. );
  35. export default Tooltip;