Skip to content

The open alternative to Salesforce, designed for AI.

1.5 KB
Raw Blame
import { styled } from '@linaria/react';
import { type CSSProperties, type ReactNode } from 'react';

import { useIsMobile } from 'twenty-ui/utilities';
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
import { themeCssVariables } from 'twenty-ui/theme';

const StyledOuterContainer = styled.div`
  display: flex;
  gap: var(--show-page-gap, 0);
  height: 100%;
  width: 100%;
`;

const StyledInnerContainer = styled.div`
  display: flex;
  flex-direction: var(--show-page-direction, row);
  height: 100%;
  width: 100%;
`;

const StyledScrollWrapperContainer = styled.div`
  background-color: ${themeCssVariables.background.secondary};
  overflow: hidden;
`;

export type ShowPageContainerProps = {
  children: ReactNode;
};

export const ShowPageContainer = ({ children }: ShowPageContainerProps) => {
  const isMobile = useIsMobile();

  const mobileStyle = isMobile
    ? ({
        '--show-page-gap': themeCssVariables.spacing[3],
        '--show-page-direction': 'column',
      } as CSSProperties)
    : undefined;

  return isMobile ? (
    <StyledOuterContainer style={mobileStyle}>
      <StyledScrollWrapperContainer>
        <ScrollWrapper componentInstanceId="scroll-wrapper-show-page-container">
          <StyledInnerContainer style={mobileStyle}>
            {children}
          </StyledInnerContainer>
        </ScrollWrapper>
      </StyledScrollWrapperContainer>
    </StyledOuterContainer>
  ) : (
    <StyledOuterContainer>
      <StyledInnerContainer>{children}</StyledInnerContainer>
    </StyledOuterContainer>
  );
};