Files
twenty/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridOverlay.tsx
T
Charles Bochet 3bfdc2c83f chore(twenty-front): migrate command-menu, workflow, page-layout and UI modules from Emotion to Linaria (PR 4-6/10) (#18342)
## Summary

Continues the Emotion → Linaria migration (PR 4-6 from the [migration
plan](docs/emotion-to-linaria-migration-plan.md)). Migrates **311
files** across four module groups:

| Module | Files |
|---|---|
| command-menu | 53 |
| workflow | 84 |
| page-layout | 84 |
| UI (partial - first ~80 files) | ~80 |
| twenty-ui (TEXT_INPUT_STYLE) | 1 |
| misc (hooks, keyboard-shortcut-menu, file-upload) | ~9 |

### Migration patterns applied

- `import styled from '@emotion/styled'` → `import { styled } from
'@linaria/react'`
- `import { useTheme } from '@emotion/react'` → `import { useContext }
from 'react'` + `import { ThemeContext } from 'twenty-ui/theme'`
- `${({ theme }) => theme.X.Y.Z}` → `${themeCssVariables.X.Y.Z}` (static
CSS variables)
- `theme.spacing(N)` → `themeCssVariables.spacing[N]`
- `styled(motion.div)` → `motion.create(StyledBase)` (11 components)
- `styled(Component)<TypeParams>` → wrapper div approach for non-HTML
elements
- Multi-declaration interpolations split into one CSS property per
interpolation
- Interpolation return types fixed (`&&` → ternary `? : ''`)
- `TEXT_INPUT_STYLE` converted from function to static string constant
(backward compatible)
- Emotion `<Global>` replaced with `useEffect` style injection
- Complex runtime-dependent styles use CSS custom properties via
`style={}` prop

### After this PR

- **Remaining files**: ~400 (object-record: ~160, settings: ~200, UI:
~44)
- **No breaking changes**: CSS variables resolve identically to the
previous Emotion theme values
2026-03-03 16:42:03 +01:00

111 lines
4.1 KiB
TypeScript

import { type PageLayoutBreakpoint } from '@/page-layout/constants/PageLayoutBreakpoints';
import { PAGE_LAYOUT_GRID_OVERLAY_Z_INDEX } from '@/page-layout/constants/PageLayoutGridOverlayZIndex';
import { useCreateWidgetFromClick } from '@/page-layout/hooks/useCreateWidgetFromClick';
import { pageLayoutCurrentBreakpointComponentState } from '@/page-layout/states/pageLayoutCurrentBreakpointComponentState';
import { pageLayoutCurrentLayoutsComponentState } from '@/page-layout/states/pageLayoutCurrentLayoutsComponentState';
import { pageLayoutSelectedCellsComponentState } from '@/page-layout/states/pageLayoutSelectedCellsComponentState';
import { calculateGridCellPosition } from '@/page-layout/utils/calculateGridCellPosition';
import { calculateTotalGridRows } from '@/page-layout/utils/calculateTotalGridRows';
import { generateCellId } from '@/page-layout/utils/generateCellId';
import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { styled } from '@linaria/react';
import { useMemo } from 'react';
import { themeCssVariables } from 'twenty-ui/theme-constants';
const StyledGridOverlay = styled.div<{
isDragSelecting?: boolean;
breakpoint: PageLayoutBreakpoint;
}>`
position: absolute;
top: ${themeCssVariables.spacing[2]};
left: ${themeCssVariables.spacing[2]};
right: ${themeCssVariables.spacing[2]};
bottom: ${themeCssVariables.spacing[2]};
display: grid;
grid-template-columns: ${({ breakpoint }) =>
breakpoint === 'mobile' ? '1fr' : 'repeat(12, 1fr)'};
grid-auto-rows: 55px;
gap: ${themeCssVariables.spacing[2]};
pointer-events: ${({ isDragSelecting }) =>
isDragSelecting ? 'auto' : 'none'};
z-index: ${PAGE_LAYOUT_GRID_OVERLAY_Z_INDEX};
`;
const StyledGridCell = styled.div<{ isSelected?: boolean }>`
background: ${({ isSelected }) =>
isSelected ? themeCssVariables.color.blue3 : 'transparent'};
border: 1px solid
${({ isSelected }) =>
isSelected
? themeCssVariables.color.blue7
: themeCssVariables.border.color.light};
border-radius: ${themeCssVariables.border.radius.md};
cursor: pointer;
transition: background-color 0.3s ease;
&:hover {
background: ${themeCssVariables.background.transparent.lighter};
border-color: ${themeCssVariables.border.color.medium};
}
`;
export const PageLayoutGridOverlay = () => {
const pageLayoutCurrentBreakpoint = useAtomComponentStateValue(
pageLayoutCurrentBreakpointComponentState,
);
const pageLayoutSelectedCells = useAtomComponentStateValue(
pageLayoutSelectedCellsComponentState,
);
const pageLayoutCurrentLayouts = useAtomComponentStateValue(
pageLayoutCurrentLayoutsComponentState,
);
const activeTabId = useAtomComponentStateValue(activeTabIdComponentState);
const { createWidgetFromClick } = useCreateWidgetFromClick();
const numberOfRows = useMemo(() => {
const currentTabLayouts = pageLayoutCurrentLayouts[activeTabId ?? ''] || {
desktop: [],
mobile: [],
};
return calculateTotalGridRows(currentTabLayouts);
}, [pageLayoutCurrentLayouts, activeTabId]);
const isPageLayoutCurrentBreakpointMobile =
pageLayoutCurrentBreakpoint === 'mobile';
const numberOfColumns = pageLayoutCurrentBreakpoint === 'mobile' ? 1 : 12;
return (
<StyledGridOverlay
isDragSelecting={!isPageLayoutCurrentBreakpointMobile}
breakpoint={pageLayoutCurrentBreakpoint}
>
{Array.from(
{
length: numberOfColumns * numberOfRows,
},
(_, i) => {
const { column, row } = calculateGridCellPosition({
index: i,
numberOfColumns,
});
const cellId = generateCellId(column, row);
return (
<StyledGridCell
key={i}
data-selectable-id={cellId}
isSelected={pageLayoutSelectedCells.has(cellId)}
onClick={() => createWidgetFromClick(cellId)}
/>
);
},
)}
</StyledGridOverlay>
);
};