index.tsx 676 B

1234567891011121314151617181920212223242526272829303132
  1. import React, { forwardRef } from 'react';
  2. import { ViewportType } from '../../constants/type';
  3. import { Container, Wrapper } from './styled';
  4. type Props = {
  5. children: React.ReactNode;
  6. viewport: ViewportType;
  7. rotation: number;
  8. displayMode: string;
  9. };
  10. type Ref = HTMLDivElement;
  11. const Viewer = forwardRef<Ref, Props>(({
  12. children,
  13. viewport,
  14. rotation,
  15. displayMode,
  16. }: Props, ref) => {
  17. const width = (Math.abs(rotation) / 90) % 2 === 1 ? viewport.height : viewport.width;
  18. return (
  19. <Container ref={ref} isFull={displayMode === 'full'}>
  20. <Wrapper width={width}>
  21. {children}
  22. </Wrapper>
  23. </Container>
  24. );
  25. });
  26. export default Viewer;