Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
import styled from '@emotion/styled';
import { PropsWithChildren, useId } from 'react';

const StyledScrollWrapper = styled(ScrollWrapper)`
box-sizing: border-box;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: Not sure why this is required here but it is, not getting globally applied from the index.css

padding-inline: ${({ theme }) => theme.spacing(1)};
width: 100%;
`;

const StyledPaddingContainer = styled.div`
padding: ${({ theme }) => theme.spacing(1)};
`;

const StyledPaddingBlockContainer = styled.div`
overflow: auto;
padding-block: ${({ theme }) => theme.spacing(1)};
`;

type DropDownMenuItemsScrollContainerProps = PropsWithChildren<{
hasMaxHeight?: boolean;
scrollable?: boolean;
}>;
export const DropDownMenuItemsScrollContainer = ({
hasMaxHeight = false,
scrollable = true,
children,
}: DropDownMenuItemsScrollContainerProps) => {
const id = useId();

if (scrollable || hasMaxHeight) {
return (
<StyledPaddingBlockContainer>
<StyledScrollWrapper
componentInstanceId={`scroll-wrapper-dropdown-menu-${id}`}
>
{children}
</StyledScrollWrapper>
</StyledPaddingBlockContainer>
);
}

return <StyledPaddingContainer>{children}</StyledPaddingContainer>;
};
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
import { DropDownMenuItemsScrollContainer } from '@/ui/layout/dropdown/components/DropDownMenuItemsScrollContainer';
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { useId } from 'react';
import { PropsWithChildren } from 'react';
import { isDefined } from 'twenty-shared/utils';

const StyledDropdownMenuItemsExternalContainer = styled.div<{
hasMaxHeight?: boolean;
width: number | 'auto';
}>`
--padding: ${({ theme }) => theme.spacing(1)};

align-items: flex-start;
display: flex;

flex-direction: column;
max-height: ${({ hasMaxHeight }) => (hasMaxHeight ? '168px' : 'none')};

padding: var(--padding);

${({ width }) =>
isDefined(width) &&
css`
Expand All @@ -35,60 +31,34 @@ const StyledDropdownMenuItemsInternalContainer = styled.div`
width: 100%;
`;

const StyledScrollWrapper = styled(ScrollWrapper)`
width: 100%;
`;

type DropdownMenuItemsContainerProps = PropsWithChildren<{
hasMaxHeight?: boolean;
className?: string;
scrollable?: boolean;
width?: number | 'auto';
}>;
// TODO: refactor this, the dropdown should handle the max height behavior + scroll with the size middleware
// We should instead create a DropdownMenuItemsContainerScrollable or take for granted that it is the default behavior
export const DropdownMenuItemsContainer = ({
children,
hasMaxHeight,
className,
width = 200,
scrollable = true,
}: {
children: React.ReactNode;
hasMaxHeight?: boolean;
className?: string;
scrollable?: boolean;
width?: number | 'auto';
}) => {
const id = useId();

return scrollable !== true ? (
scrollable,
}: DropdownMenuItemsContainerProps) => (
<DropDownMenuItemsScrollContainer
hasMaxHeight={hasMaxHeight}
scrollable={scrollable}
>
<StyledDropdownMenuItemsExternalContainer
hasMaxHeight={hasMaxHeight}
className={className}
role="listbox"
width={width}
hasMaxHeight={hasMaxHeight}
>
{hasMaxHeight ? (
<StyledScrollWrapper
componentInstanceId={`scroll-wrapper-dropdown-menu-${id}`}
>
<StyledDropdownMenuItemsInternalContainer>
{children}
</StyledDropdownMenuItemsInternalContainer>
</StyledScrollWrapper>
) : (
<StyledDropdownMenuItemsInternalContainer>
{children}
</StyledDropdownMenuItemsInternalContainer>
)}
<StyledDropdownMenuItemsInternalContainer>
{children}
</StyledDropdownMenuItemsInternalContainer>
</StyledDropdownMenuItemsExternalContainer>
) : (
<ScrollWrapper componentInstanceId={`scroll-wrapper-dropdown-menu-${id}`}>
<StyledDropdownMenuItemsExternalContainer
hasMaxHeight={hasMaxHeight}
className={className}
role="listbox"
width={width}
>
<StyledDropdownMenuItemsInternalContainer>
{children}
</StyledDropdownMenuItemsInternalContainer>
</StyledDropdownMenuItemsExternalContainer>
</ScrollWrapper>
);
};
</DropDownMenuItemsScrollContainer>
);