timestampButton.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import type {MouseEvent} from 'react';
  2. import styled from '@emotion/styled';
  3. import {DateTime} from 'sentry/components/dateTime';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {IconPlay} from 'sentry/icons';
  6. import {space} from 'sentry/styles/space';
  7. import formatReplayDuration from 'sentry/utils/duration/formatReplayDuration';
  8. type Props = {
  9. startTimestampMs: number;
  10. timestampMs: string | number | Date;
  11. className?: string;
  12. format?: 'mm:ss' | 'mm:ss.SSS';
  13. onClick?: (event: MouseEvent) => void;
  14. };
  15. function TimestampButton({
  16. className,
  17. format = 'mm:ss',
  18. onClick,
  19. startTimestampMs,
  20. timestampMs,
  21. }: Props) {
  22. return (
  23. <Tooltip title={<DateTime seconds date={timestampMs} />} skipWrapper>
  24. <StyledButton
  25. as={onClick ? 'button' : 'span'}
  26. onClick={onClick}
  27. className={className}
  28. >
  29. <IconPlay size="xs" />
  30. {formatReplayDuration(
  31. Math.abs(new Date(timestampMs).getTime() - startTimestampMs),
  32. format === 'mm:ss.SSS'
  33. )}
  34. </StyledButton>
  35. </Tooltip>
  36. );
  37. }
  38. const StyledButton = styled('button')`
  39. background: transparent;
  40. border: none;
  41. color: inherit;
  42. font-variant-numeric: tabular-nums;
  43. line-height: 1.2em;
  44. display: flex;
  45. align-items: flex-start;
  46. align-self: baseline;
  47. gap: ${space(0.25)};
  48. padding: 0;
  49. height: 100%;
  50. `;
  51. export default TimestampButton;