clipboardTooltip.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import styled from '@emotion/styled';
  2. import Clipboard from 'sentry/components/clipboard';
  3. import TextOverflow from 'sentry/components/textOverflow';
  4. import Tooltip from 'sentry/components/tooltip';
  5. import {IconCopy} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import space from 'sentry/styles/space';
  8. type Props = Omit<React.ComponentProps<typeof Tooltip>, 'isHoverable' | 'title'> & {
  9. title: string;
  10. onSuccess?: () => void;
  11. };
  12. function ClipboardTooltip({title, onSuccess, ...props}: Props) {
  13. return (
  14. <Tooltip
  15. {...props}
  16. title={
  17. <TooltipClipboardWrapper
  18. onClick={event => {
  19. event.stopPropagation();
  20. }}
  21. >
  22. <TextOverflow>{title}</TextOverflow>
  23. <Clipboard value={title} onSuccess={onSuccess}>
  24. <TooltipClipboardIconWrapper>
  25. <IconCopy size="xs" aria-label={t('Copy to clipboard')} />
  26. </TooltipClipboardIconWrapper>
  27. </Clipboard>
  28. </TooltipClipboardWrapper>
  29. }
  30. isHoverable
  31. />
  32. );
  33. }
  34. export default ClipboardTooltip;
  35. const TooltipClipboardWrapper = styled('div')`
  36. display: grid;
  37. grid-template-columns: auto max-content;
  38. align-items: center;
  39. gap: ${space(0.5)};
  40. `;
  41. const TooltipClipboardIconWrapper = styled('div')`
  42. pointer-events: auto;
  43. position: relative;
  44. bottom: -${space(0.25)};
  45. :hover {
  46. cursor: pointer;
  47. }
  48. `;