timestampButton.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import type {MouseEvent} from 'react';
  2. import styled from '@emotion/styled';
  3. import {DateTime} from 'sentry/components/dateTime';
  4. import Duration from 'sentry/components/duration/duration';
  5. import ReplayTooltipTime from 'sentry/components/replays/replayTooltipTime';
  6. import {Tooltip} from 'sentry/components/tooltip';
  7. import {IconPlay} from 'sentry/icons';
  8. import {space} from 'sentry/styles/space';
  9. import {useReplayPrefs} from 'sentry/utils/replays/playback/providers/replayPreferencesContext';
  10. type Props = {
  11. startTimestampMs: number;
  12. timestampMs: number;
  13. className?: string;
  14. onClick?: (event: MouseEvent) => void;
  15. precision?: 'sec' | 'ms';
  16. };
  17. export default function TimestampButton({
  18. className,
  19. precision = 'sec',
  20. onClick,
  21. startTimestampMs,
  22. timestampMs,
  23. }: Props) {
  24. const [prefs] = useReplayPrefs();
  25. const timestampType = prefs.timestampType;
  26. return (
  27. <Tooltip
  28. title={
  29. <div>
  30. <ReplayTooltipTime
  31. timestampMs={timestampMs}
  32. startTimestampMs={startTimestampMs}
  33. />
  34. </div>
  35. }
  36. skipWrapper
  37. >
  38. <StyledButton
  39. as={onClick ? 'button' : 'span'}
  40. onClick={onClick}
  41. className={className}
  42. >
  43. <IconPlay size="xs" />
  44. {timestampType === 'absolute' ? (
  45. <DateTime timeOnly seconds date={timestampMs} />
  46. ) : (
  47. <Duration
  48. duration={[Math.abs(timestampMs - startTimestampMs), 'ms']}
  49. precision={precision}
  50. />
  51. )}
  52. </StyledButton>
  53. </Tooltip>
  54. );
  55. }
  56. const StyledButton = styled('button')`
  57. background: transparent;
  58. border: none;
  59. color: inherit;
  60. font-variant-numeric: tabular-nums;
  61. line-height: 1.2em;
  62. display: flex;
  63. align-items: flex-start;
  64. align-self: baseline;
  65. gap: ${space(0.25)};
  66. padding: 0;
  67. height: 100%;
  68. `;