timestampButton.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {MouseEvent} from 'react';
  2. import styled from '@emotion/styled';
  3. import DateTime from 'sentry/components/dateTime';
  4. import {showPlayerTime} from 'sentry/components/replays/utils';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {IconPlay} from 'sentry/icons';
  7. import {space} from 'sentry/styles/space';
  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. {showPlayerTime(timestampMs, startTimestampMs, format === 'mm:ss.SSS')}
  31. </StyledButton>
  32. </Tooltip>
  33. );
  34. }
  35. const StyledButton = styled('button')`
  36. background: transparent;
  37. border: none;
  38. color: inherit;
  39. font-variant-numeric: tabular-nums;
  40. display: flex;
  41. align-items: center;
  42. gap: ${space(0.25)};
  43. padding: 0;
  44. height: 100%;
  45. `;
  46. export default TimestampButton;