Skip to content

The open alternative to Salesforce, designed for AI.

fix: use white background for widgets on mobile and in side panel (#16870)

Abdullah.18473e5c94ef
diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx
index a85fb01ca77..b6afb1afa7b 100644
--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx
+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx
@@ -12,6 +12,7 @@ import { PAGE_LAYOUT_GRID_MARGIN } from '@/page-layout/constants/PageLayoutGridM
import { PAGE_LAYOUT_GRID_ROW_HEIGHT } from '@/page-layout/constants/PageLayoutGridRowHeight';
import { usePageLayoutHandleLayoutChange } from '@/page-layout/hooks/usePageLayoutHandleLayoutChange';
import { usePageLayoutTabWithVisibleWidgetsOrThrow } from '@/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow';
+import { useShouldUseWhiteBackground } from '@/page-layout/hooks/useShouldUseWhiteBackground';
import { isPageLayoutInEditModeComponentState } from '@/page-layout/states/isPageLayoutInEditModeComponentState';
import { pageLayoutCurrentBreakpointComponentState } from '@/page-layout/states/pageLayoutCurrentBreakpointComponentState';
import { pageLayoutCurrentLayoutsComponentState } from '@/page-layout/states/pageLayoutCurrentLayoutsComponentState';
@@ -36,7 +37,13 @@ import {
} from 'react-grid-layout';
import { isDefined } from 'twenty-shared/utils';
-const StyledGridContainer = styled.div`
+const StyledGridContainer = styled.div<{
+ shouldUseWhiteBackground: boolean;
+}>`
+ background: ${({ theme, shouldUseWhiteBackground }) =>
+ shouldUseWhiteBackground
+ ? theme.background.primary
+ : theme.background.secondary};
box-sizing: border-box;
flex: 1;
min-height: 100%;
@@ -104,6 +111,8 @@ export const PageLayoutGridLayout = ({ tabId }: PageLayoutGridLayoutProps) => {
const gridContainerRef = useRef<HTMLDivElement>(null);
+ const { shouldUseWhiteBackground } = useShouldUseWhiteBackground();
+
const isPageLayoutInEditMode = useRecoilComponentValue(
isPageLayoutInEditModeComponentState,
);
@@ -143,7 +152,10 @@ export const PageLayoutGridLayout = ({ tabId }: PageLayoutGridLayoutProps) => {
);
return (
- <StyledGridContainer ref={gridContainerRef}>
+ <StyledGridContainer
+ ref={gridContainerRef}
+ shouldUseWhiteBackground={shouldUseWhiteBackground}
+ >
{isPageLayoutInEditMode && (
<>
<PageLayoutGridOverlay />
diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListEditor.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListEditor.tsx
index f176b9cb806..0c36a07ced8 100644
--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListEditor.tsx
+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListEditor.tsx
@@ -1,3 +1,4 @@
+import { useShouldUseWhiteBackground } from '@/page-layout/hooks/useShouldUseWhiteBackground';
import { pageLayoutDraggingWidgetIdComponentState } from '@/page-layout/states/pageLayoutDraggingWidgetIdComponentState';
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
import { WidgetRenderer } from '@/page-layout/widgets/components/WidgetRenderer';
@@ -11,7 +12,13 @@ import {
} from '@hello-pangea/dnd';
import { useId } from 'react';
-const StyledVerticalListContainer = styled.div`
+const StyledVerticalListContainer = styled.div<{
+ shouldUseWhiteBackground: boolean;
+}>`
+ background: ${({ theme, shouldUseWhiteBackground }) =>
+ shouldUseWhiteBackground
+ ? theme.background.primary
+ : theme.background.secondary};
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing(2)};
@@ -35,6 +42,8 @@ export const PageLayoutVerticalListEditor = ({
}: PageLayoutVerticalListEditorProps) => {
const droppableId = `page-layout-vertical-list-${useId()}`;
+ const { shouldUseWhiteBackground } = useShouldUseWhiteBackground();
+
const setDraggingWidgetId = useSetRecoilComponentState(
pageLayoutDraggingWidgetIdComponentState,
);
@@ -53,6 +62,7 @@ export const PageLayoutVerticalListEditor = ({
{(provided) => (
<StyledVerticalListContainer
ref={provided.innerRef}
+ shouldUseWhiteBackground={shouldUseWhiteBackground}
// eslint-disable-next-line react/jsx-props-no-spreading
{...provided.droppableProps}
>
diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListViewer.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListViewer.tsx
index 3d12d0871d1..abd3ccc8bbe 100644
--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListViewer.tsx
+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListViewer.tsx
@@ -1,8 +1,15 @@
+import { useShouldUseWhiteBackground } from '@/page-layout/hooks/useShouldUseWhiteBackground';
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
import { WidgetRenderer } from '@/page-layout/widgets/components/WidgetRenderer';
import styled from '@emotion/styled';
-const StyledVerticalListContainer = styled.div`
+const StyledVerticalListContainer = styled.div<{
+ shouldUseWhiteBackground: boolean;
+}>`
+ background: ${({ theme, shouldUseWhiteBackground }) =>
+ shouldUseWhiteBackground
+ ? theme.background.primary
+ : theme.background.secondary};
display: flex;
flex-direction: column;
gap: ${({ theme }) => theme.spacing(2)};
@@ -15,8 +22,12 @@ type PageLayoutVerticalListViewerProps = {
export const PageLayoutVerticalListViewer = ({
widgets,
}: PageLayoutVerticalListViewerProps) => {
+ const { shouldUseWhiteBackground } = useShouldUseWhiteBackground();
+
return (
- <StyledVerticalListContainer>
+ <StyledVerticalListContainer
+ shouldUseWhiteBackground={shouldUseWhiteBackground}
+ >
{widgets.map((widget) => (
<div key={widget.id}>
<WidgetRenderer widget={widget} />
diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useShouldUseWhiteBackground.ts b/packages/twenty-front/src/modules/page-layout/hooks/useShouldUseWhiteBackground.ts
new file mode 100644
index 00000000000..b368c0e7a63
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/hooks/useShouldUseWhiteBackground.ts
@@ -0,0 +1,14 @@
+import { useIsInPinnedTab } from '@/page-layout/widgets/hooks/useIsInPinnedTab';
+import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';
+import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
+
+export const useShouldUseWhiteBackground = () => {
+ const isMobile = useIsMobile();
+ const { isInRightDrawer } = useLayoutRenderingContext();
+ const { isInPinnedTab } = useIsInPinnedTab();
+
+ const shouldUseWhiteBackground =
+ (isMobile || isInRightDrawer) && !isInPinnedTab;
+
+ return { shouldUseWhiteBackground };
+};
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/widget-card/components/WidgetCard.tsx b/packages/twenty-front/src/modules/page-layout/widgets/widget-card/components/WidgetCard.tsx
index 364c9800227..9fa919fa618 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/widget-card/components/WidgetCard.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/widget-card/components/WidgetCard.tsx
@@ -80,7 +80,6 @@ const StyledWidgetCard = styled.div<{
if (variant === 'side-column' && !isEditable) {
return css`
- background: ${theme.background.secondary};
padding: ${theme.spacing(2)};
${isLastWidget !== true &&
css`