# Introduction closes https://github.com/twentyhq/core-team-issues/issues/591 Same than for `twenty-shared` made in https://github.com/twentyhq/twenty/pull/11083. ## TODO - [x] Manual migrate twenty-website twenty-ui imports ## What's next: - Generate barrel and migration script factorization within own package + tests - Refactoring using preconstruct ? TimeBox - Lint circular dependencies - Lint import from barrel and forbid them ### Preconstruct We need custom rollup plugins addition, but preconstruct does not expose its rollup configuration. It might be possible to handle this using the babel overrides. But was a big tunnel. We could give it a try afterwards ! ( allowing cjs interop and stuff like that ) Stuck to vite lib app Closed related PRs: - https://github.com/twentyhq/twenty/pull/11294 - https://github.com/twentyhq/twenty/pull/11203
151 lines
4.1 KiB
TypeScript
151 lines
4.1 KiB
TypeScript
import { useTheme } from '@emotion/react';
|
|
import styled from '@emotion/styled';
|
|
import { ReactNode } from 'react';
|
|
import { useRecoilValue } from 'recoil';
|
|
|
|
import { NavigationDrawerCollapseButton } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerCollapseButton';
|
|
|
|
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
|
|
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
|
|
import {
|
|
IconComponent,
|
|
IconX,
|
|
OverflowingTextWithTooltip,
|
|
} from 'twenty-ui/display';
|
|
import { LightIconButton } from 'twenty-ui/input';
|
|
import { MOBILE_VIEWPORT } from 'twenty-ui/theme';
|
|
|
|
export const PAGE_BAR_MIN_HEIGHT = 40;
|
|
|
|
const StyledTopBarContainer = styled.div`
|
|
align-items: center;
|
|
background: ${({ theme }) => theme.background.noisy};
|
|
color: ${({ theme }) => theme.font.color.primary};
|
|
display: flex;
|
|
flex-direction: row;
|
|
font-size: ${({ theme }) => theme.font.size.lg};
|
|
justify-content: space-between;
|
|
min-height: ${PAGE_BAR_MIN_HEIGHT}px;
|
|
padding: ${({ theme }) => theme.spacing(2)};
|
|
padding-left: 0;
|
|
padding-right: ${({ theme }) => theme.spacing(3)};
|
|
gap: ${({ theme }) => theme.spacing(2)};
|
|
|
|
@media (max-width: ${MOBILE_VIEWPORT}px) {
|
|
box-sizing: border-box;
|
|
padding: ${({ theme }) => theme.spacing(3)};
|
|
}
|
|
`;
|
|
|
|
const StyledLeftContainer = styled.div`
|
|
align-items: center;
|
|
display: flex;
|
|
flex-direction: row;
|
|
gap: ${({ theme }) => theme.spacing(1)};
|
|
padding-left: ${({ theme }) => theme.spacing(1)};
|
|
overflow-x: hidden;
|
|
width: 100%;
|
|
@media (max-width: ${MOBILE_VIEWPORT}px) {
|
|
padding-left: ${({ theme }) => theme.spacing(1)};
|
|
}
|
|
`;
|
|
|
|
const StyledTitleContainer = styled.div`
|
|
display: flex;
|
|
font-size: ${({ theme }) => theme.font.size.md};
|
|
font-weight: ${({ theme }) => theme.font.weight.medium};
|
|
margin-left: ${({ theme }) => theme.spacing(0.5)};
|
|
margin-right: ${({ theme }) => theme.spacing(1)};
|
|
width: 100%;
|
|
overflow: hidden;
|
|
`;
|
|
|
|
const StyledTopBarIconStyledTitleContainer = styled.div`
|
|
align-items: center;
|
|
display: flex;
|
|
gap: ${({ theme }) => theme.spacing(1)};
|
|
flex-direction: row;
|
|
width: 100%;
|
|
overflow: hidden;
|
|
`;
|
|
|
|
const StyledPageActionContainer = styled.div`
|
|
display: inline-flex;
|
|
gap: ${({ theme }) => theme.spacing(2)};
|
|
flex: 1 0 1;
|
|
`;
|
|
|
|
const StyledTopBarButtonContainer = styled.div`
|
|
margin-left: ${({ theme }) => theme.spacing(1)};
|
|
margin-right: ${({ theme }) => theme.spacing(1)};
|
|
`;
|
|
|
|
const StyledIconContainer = styled.div`
|
|
align-items: center;
|
|
display: flex;
|
|
flex-direction: row;
|
|
`;
|
|
|
|
type PageHeaderProps = {
|
|
title?: ReactNode;
|
|
hasClosePageButton?: boolean;
|
|
onClosePage?: () => void;
|
|
Icon?: IconComponent;
|
|
children?: ReactNode;
|
|
};
|
|
|
|
export const PageHeader = ({
|
|
title,
|
|
hasClosePageButton,
|
|
onClosePage,
|
|
Icon,
|
|
children,
|
|
}: PageHeaderProps) => {
|
|
const isMobile = useIsMobile();
|
|
const theme = useTheme();
|
|
const isNavigationDrawerExpanded = useRecoilValue(
|
|
isNavigationDrawerExpandedState,
|
|
);
|
|
|
|
return (
|
|
<StyledTopBarContainer>
|
|
<StyledLeftContainer>
|
|
{!isMobile && !isNavigationDrawerExpanded && (
|
|
<StyledTopBarButtonContainer>
|
|
<NavigationDrawerCollapseButton direction="right" />
|
|
</StyledTopBarButtonContainer>
|
|
)}
|
|
{hasClosePageButton && (
|
|
<LightIconButton
|
|
Icon={IconX}
|
|
size="small"
|
|
accent="tertiary"
|
|
onClick={() => onClosePage?.()}
|
|
/>
|
|
)}
|
|
|
|
<StyledTopBarIconStyledTitleContainer>
|
|
{Icon && (
|
|
<StyledIconContainer>
|
|
<Icon size={theme.icon.size.md} />
|
|
</StyledIconContainer>
|
|
)}
|
|
{title && (
|
|
<StyledTitleContainer data-testid="top-bar-title">
|
|
{typeof title === 'string' ? (
|
|
<OverflowingTextWithTooltip text={title} />
|
|
) : (
|
|
title
|
|
)}
|
|
</StyledTitleContainer>
|
|
)}
|
|
</StyledTopBarIconStyledTitleContainer>
|
|
</StyledLeftContainer>
|
|
|
|
<StyledPageActionContainer className="page-action-container">
|
|
{children}
|
|
</StyledPageActionContainer>
|
|
</StyledTopBarContainer>
|
|
);
|
|
};
|