gridlines.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Timeline from 'sentry/components/replays/breadcrumbs/timeline';
  4. import {countColumns, formatTime} from '../utils';
  5. type LineStyle = 'dotted' | 'solid' | 'none';
  6. const Line = styled(Timeline.Col)<{lineStyle: LineStyle}>`
  7. border-right: 1px ${p => p.lineStyle} ${p => p.theme.gray100};
  8. text-align: right;
  9. `;
  10. function Gridlines({
  11. children,
  12. cols,
  13. lineStyle,
  14. remaining,
  15. }: {
  16. cols: number;
  17. lineStyle: LineStyle;
  18. remaining: number;
  19. children?: (i: number) => React.ReactNode;
  20. }) {
  21. return (
  22. <Timeline.Columns totalColumns={cols} remainder={remaining}>
  23. {[...Array(cols)].map((_, i) => (
  24. <Line key={i} lineStyle={lineStyle}>
  25. {children ? children(i) : null}
  26. </Line>
  27. ))}
  28. </Timeline.Columns>
  29. );
  30. }
  31. type Props = {
  32. duration: number;
  33. width: number;
  34. minWidth?: number;
  35. };
  36. export function MajorGridlines({duration, minWidth = 50, width}: Props) {
  37. const {timespan, cols, remaining} = countColumns(duration, width, minWidth);
  38. return (
  39. <Gridlines cols={cols} lineStyle="solid" remaining={remaining}>
  40. {i => <small>{formatTime((i + 1) * timespan)}</small>}
  41. </Gridlines>
  42. );
  43. }
  44. export function MinorGridlines({duration, minWidth = 20, width}: Props) {
  45. const {cols, remaining} = countColumns(duration, width, minWidth);
  46. return <Gridlines cols={cols} lineStyle="dotted" remaining={remaining} />;
  47. }