timestampButton.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import styled from '@emotion/styled';
  2. import DateTime from 'sentry/components/dateTime';
  3. import {showPlayerTime} from 'sentry/components/replays/utils';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {IconPlay} from 'sentry/icons';
  6. import space from 'sentry/styles/space';
  7. type Props = {
  8. startTimestampMs: number;
  9. timestampMs: string | number | Date;
  10. className?: string;
  11. format?: 'mm:ss' | 'mm:ss.SSS';
  12. onClick?: () => void;
  13. };
  14. function TimestampButton({
  15. className,
  16. format = 'mm:ss',
  17. onClick,
  18. startTimestampMs,
  19. timestampMs,
  20. }: Props) {
  21. return (
  22. <Tooltip title={<DateTime date={timestampMs} />}>
  23. <StyledButton
  24. as={onClick ? 'button' : 'span'}
  25. onClick={onClick}
  26. className={className}
  27. >
  28. <IconPlay size="xs" />
  29. {showPlayerTime(timestampMs, startTimestampMs, format === 'mm:ss.SSS')}
  30. </StyledButton>
  31. </Tooltip>
  32. );
  33. }
  34. const StyledButton = styled('button')`
  35. background: transparent;
  36. border: none;
  37. color: 'inherit';
  38. font-size: ${p => p.theme.fontSizeSmall};
  39. font-variant-numeric: tabular-nums;
  40. display: flex;
  41. align-items: center;
  42. gap: ${space(0.25)};
  43. padding: 0;
  44. & > svg {
  45. visibility: hidden;
  46. }
  47. &:hover svg {
  48. visibility: visible;
  49. }
  50. `;
  51. export default TimestampButton;