index.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React from 'react';
  2. import { Manager, Reference, Popper } from 'react-popper';
  3. import { TargetWrapper, 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.FC<Props> = ({
  11. anchor = 'left',
  12. children,
  13. content,
  14. }: Props) => (
  15. <Manager>
  16. <Reference>
  17. {({ ref }): React.ReactElement => (
  18. <TargetWrapper ref={ref}>{children}</TargetWrapper>
  19. )}
  20. </Reference>
  21. <Portal>
  22. <Popper placement={anchor}>
  23. {({ ref, style, placement, arrowProps }): React.ReactElement => (
  24. <TooltipContainer ref={ref} style={style} data-placement={placement}>
  25. {content}
  26. <Arrow
  27. data-placement={placement}
  28. ref={arrowProps.ref}
  29. style={arrowProps.style}
  30. />
  31. </TooltipContainer>
  32. )}
  33. </Popper>
  34. </Portal>
  35. </Manager>
  36. );
  37. export default Tooltip;