resizeableContainer.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import type {ReactNode} from 'react';
  2. import {Fragment} from 'react';
  3. import styled from '@emotion/styled';
  4. import toPixels from 'sentry/utils/number/toPixels';
  5. import {useResizableDrawer} from 'sentry/utils/useResizableDrawer';
  6. import Grabber from 'sentry/views/replays/detail/perfTable/grabber';
  7. interface Props {
  8. children: [ReactNode, ReactNode];
  9. containerWidth: number;
  10. max: number;
  11. min: number;
  12. onResize: (newSize: number, maybeOldSize?: number | undefined) => void;
  13. }
  14. function ResizeableContainer({children, containerWidth, min, max, onResize}: Props) {
  15. const {isHeld, onDoubleClick, onMouseDown, size} = useResizableDrawer({
  16. direction: 'left',
  17. initialSize: containerWidth / 2,
  18. min,
  19. onResize,
  20. });
  21. const leftPx = toPixels(Math.min(size, max));
  22. return (
  23. <Fragment>
  24. <ResizeableContainerGrid style={{gridTemplateColumns: `${leftPx} 1fr`}}>
  25. {children}
  26. </ResizeableContainerGrid>
  27. <Grabber
  28. data-is-held={isHeld}
  29. data-slide-direction="leftright"
  30. onDoubleClick={onDoubleClick}
  31. onMouseDown={onMouseDown}
  32. style={{left: leftPx}}
  33. />
  34. </Fragment>
  35. );
  36. }
  37. const ResizeableContainerGrid = styled('div')`
  38. display: grid;
  39. `;
  40. export default ResizeableContainer;