chore(twenty-front): migrate small modules from Emotion to Linaria (PR 1/10) (#18314)

## Emotion → Linaria migration — PR 1 of 10

First batch of the `twenty-front` migration from Emotion (runtime
CSS-in-JS) to Linaria (zero-runtime, build-time extraction via
wyw-in-js). Covers **100 files** across 10 small standalone modules —
chosen as the lowest-risk starting point.

### Modules migrated

spreadsheet-import (28) · navigation-menu-item (17) · views (14) ·
billing (10) · blocknote-editor (7) · advanced-text-editor (7) ·
favorites (7) · navigation (4) · information-banner (3) ·
sign-in-background-mock (3)

### Migration pattern

Every file follows the same mechanical transformation:

| Emotion | Linaria |
|---|---|
| `import styled from '@emotion/styled'` | `import { styled } from
'@linaria/react'` |
| `${({ theme }) => theme.font.color.primary}` |
`${themeCssVariables.font.color.primary}` |
| `${({ theme }) => theme.spacing(4)}` |
`${themeCssVariables.spacing[4]}` |
| `const theme = useTheme()` | `const { theme } =
useContext(ThemeContext)` |
| `import { type Theme } from '@emotion/react'` | `import { type
ThemeType } from 'twenty-ui/theme'` |

`themeCssVariables` is a build-time object where every leaf is a
`var(--t-xxx)` CSS custom property reference, evaluated statically by
wyw-in-js. Runtime theme access (icon sizes, colors passed as props)
uses `useContext(ThemeContext)`.

### Gotchas encountered & fixed

- **Interpolation return types** — wyw-in-js requires `string | number`,
never `false`/`undefined`. Replaced `condition && 'css'` with `condition
? 'css' : ''`.
- **`css` tag inside `styled` templates** — Linaria `css` returns a
class name, not CSS text. Replaced with plain template strings.
- **`styled(Component)` needs `className`** — added `className` prop to
`NavigationDrawerSection`, `DropdownMenuItemsContainer`, and `Heading`.
- **`shouldForwardProp` not supported** — Linaria filters invalid DOM
props automatically for HTML elements. For custom components, used
wrapper divs where needed.
- **`FormFieldPlaceholderStyles`** — converted from Emotion `css`
function to a static string using `themeCssVariables`.
This commit is contained in:
Charles Bochet
2026-03-02 16:33:40 +01:00
committed by GitHub
parent 9c4b0f526c
commit c4140f85df
211 changed files with 4754 additions and 1114 deletions
@@ -1,9 +1,10 @@
import { filterSuggestionItems } from '@blocknote/core/extensions';
import { BlockNoteView } from '@blocknote/mantine';
import { SuggestionMenuController } from '@blocknote/react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { type ClipboardEvent } from 'react';
import { styled } from '@linaria/react';
import { type ClipboardEvent, useContext } from 'react';
import { ThemeContext } from 'twenty-ui/theme';
import { themeCssVariables } from 'twenty-ui/theme-constants';
import { type BLOCK_SCHEMA } from '@/blocknote-editor/blocks/Schema';
import { getSlashMenu } from '@/blocknote-editor/utils/getSlashMenu';
@@ -31,11 +32,11 @@ const StyledEditor = styled.div`
& .editor {
background: transparent;
font-size: 13px;
color: ${({ theme }) => theme.font.color.primary};
color: ${themeCssVariables.font.color.primary};
min-height: 400px;
}
& .editor [class^='_inlineContent']:before {
color: ${({ theme }) => theme.font.color.tertiary};
color: ${themeCssVariables.font.color.tertiary};
font-style: normal !important;
}
& .editor .bn-inline-content:has(> .ProseMirror-trailingBreak):before {
@@ -55,8 +56,8 @@ const StyledEditor = styled.div`
align-items: center;
}
& .bn-drag-handle-menu {
background: ${({ theme }) => theme.background.transparent.secondary};
backdrop-filter: ${({ theme }) => theme.blur.medium};
background: ${themeCssVariables.background.transparent.secondary};
backdrop-filter: ${themeCssVariables.blur.medium};
box-shadow:
0px 2px 4px rgba(0, 0, 0, 0.04),
2px 4px 16px rgba(0, 0, 0, 0.12);
@@ -64,7 +65,7 @@ const StyledEditor = styled.div`
min-height: 96px;
padding: 4px;
border-radius: 8px;
border: 1px solid ${({ theme }) => theme.border.color.medium};
border: 1px solid ${themeCssVariables.border.color.medium};
left: 26px;
}
@@ -83,9 +84,9 @@ const StyledEditor = styled.div`
& .bn-suggestion-menu {
padding: 4px;
border-radius: 8px;
border: 1px solid ${({ theme }) => theme.border.color.medium};
background: ${({ theme }) => theme.background.transparent.secondary};
backdrop-filter: ${({ theme }) => theme.blur.medium};
border: 1px solid ${themeCssVariables.border.color.medium};
background: ${themeCssVariables.background.transparent.secondary};
backdrop-filter: ${themeCssVariables.blur.medium};
}
& .mantine-Menu-item {
@@ -94,17 +95,17 @@ const StyledEditor = styled.div`
min-height: 32px;
font-style: normal;
font-family: ${({ theme }) => theme.font.family};
font-weight: ${({ theme }) => theme.font.weight.regular};
color: ${({ theme }) => theme.font.color.secondary};
font-family: ${themeCssVariables.font.family};
font-weight: ${themeCssVariables.font.weight.regular};
color: ${themeCssVariables.font.color.secondary};
}
& .mantine-ActionIcon-root:hover {
box-shadow:
0px 0px 4px rgba(0, 0, 0, 0.08),
0px 2px 4px rgba(0, 0, 0, 0.04);
background: ${({ theme }) => theme.background.transparent.primary};
background: ${themeCssVariables.background.transparent.primary};
backdrop-filter: blur(20px);
border: 1px solid ${({ theme }) => theme.border.color.light};
border: 1px solid ${themeCssVariables.border.color.light};
}
& .bn-side-menu .mantine-UnstyledButton-root:not(.mantine-Menu-item) svg {
height: 16px;
@@ -119,17 +120,17 @@ const StyledEditor = styled.div`
}
& .bn-inline-content a {
color: ${({ theme }) => theme.color.blue};
color: ${themeCssVariables.color.blue};
}
& .bn-inline-content code {
font-family: monospace;
color: ${({ theme }) => theme.font.color.danger};
color: ${themeCssVariables.font.color.danger};
padding: 2px 4px;
border-radius: 4px;
border: 1px solid ${({ theme }) => theme.font.color.extraLight};
border: 1px solid ${themeCssVariables.font.color.extraLight};
font-size: 0.9rem;
background-color: ${({ theme }) => theme.background.transparent.light};
background-color: ${themeCssVariables.background.transparent.light};
}
`;
@@ -141,7 +142,7 @@ export const BlockEditor = ({
onPaste,
readonly,
}: BlockEditorProps) => {
const theme = useTheme();
const { theme } = useContext(ThemeContext);
const blockNoteTheme = theme.name === 'light' ? 'light' : 'dark';
const getMentionItems = useMentionMenu(editor);