4a4e65fe4a
# 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
74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
import { useTheme } from '@emotion/react';
|
|
import styled from '@emotion/styled';
|
|
import { ReactNode, useState } from 'react';
|
|
import { TableBody } from './TableBody';
|
|
import { IconChevronDown, IconChevronUp, Label } from 'twenty-ui/display';
|
|
|
|
type TableSectionProps = {
|
|
children: ReactNode;
|
|
isInitiallyExpanded?: boolean;
|
|
title: string;
|
|
};
|
|
|
|
const StyledSectionHeader = styled.div<{ isExpanded: boolean }>`
|
|
align-items: center;
|
|
background-color: ${({ theme }) => theme.background.transparent.lighter};
|
|
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};
|
|
cursor: pointer;
|
|
display: flex;
|
|
height: ${({ theme }) => theme.spacing(6)};
|
|
justify-content: space-between;
|
|
padding: 0 ${({ theme }) => theme.spacing(2)};
|
|
text-align: left;
|
|
`;
|
|
|
|
const StyledSection = styled.div<{ isExpanded: boolean }>`
|
|
max-height: ${({ isExpanded }) => (isExpanded ? 'fit-content' : 0)};
|
|
opacity: ${({ isExpanded }) => (isExpanded ? 1 : 0)};
|
|
overflow: hidden;
|
|
transition:
|
|
max-height ${({ theme }) => theme.animation.duration.normal}s,
|
|
opacity ${({ theme }) => theme.animation.duration.normal}s;
|
|
`;
|
|
|
|
const StyledSectionContent = styled(TableBody)`
|
|
border-bottom: 1px solid ${({ theme }) => theme.border.color.light};
|
|
`;
|
|
|
|
export const TableSection = ({
|
|
children,
|
|
isInitiallyExpanded = true,
|
|
title,
|
|
}: TableSectionProps) => {
|
|
const [isExpanded, setIsExpanded] = useState(isInitiallyExpanded);
|
|
const theme = useTheme();
|
|
|
|
const handleToggleSection = () =>
|
|
setIsExpanded((previousIsExpanded) => !previousIsExpanded);
|
|
|
|
return (
|
|
<>
|
|
<StyledSectionHeader
|
|
isExpanded={isExpanded}
|
|
onClick={handleToggleSection}
|
|
>
|
|
<Label>{title}</Label>
|
|
{isExpanded ? (
|
|
<IconChevronUp
|
|
size={theme.icon.size.md}
|
|
stroke={theme.icon.stroke.sm}
|
|
/>
|
|
) : (
|
|
<IconChevronDown
|
|
size={theme.icon.size.md}
|
|
stroke={theme.icon.stroke.sm}
|
|
/>
|
|
)}
|
|
</StyledSectionHeader>
|
|
<StyledSection isExpanded={isExpanded}>
|
|
<StyledSectionContent>{children}</StyledSectionContent>
|
|
</StyledSection>
|
|
</>
|
|
);
|
|
};
|