7a2e397ad1
## Summary
Completes the migration of the frontend styling system from **Emotion**
(`@emotion/styled`, `@emotion/react`) to **Linaria** (`@linaria/react`,
`@linaria/core`), a zero-runtime CSS-in-JS library where styles are
extracted at build time.
This is the final step of the migration — all ~494 files across
`twenty-front`, `twenty-ui`, `twenty-website`, and `twenty-sdk` are now
fully converted.
## Changes
### Styling Migration (across ~480 component files)
- Replaced all `@emotion/styled` imports with `@linaria/react`
- Converted runtime theme access patterns (`({ theme }) => theme.x.y`)
to build-time `themeCssVariables` CSS custom properties
- Replaced `useTheme()` hook (from Emotion) with
`useContext(ThemeContext)` where runtime theme values are still needed
(e.g., passing colors to non-CSS props like icon components)
- Removed `@emotion/react` `css` helper usages in favor of Linaria
template literals
### Dependency & Configuration Changes
- **Removed**: `@emotion/react`, `@emotion/styled` from root
`package.json`
- **Added**: `@wyw-in-js/babel-preset`, `next-with-linaria` (for
twenty-website SSR support)
- Updated Nx generator defaults from `@emotion/styled` to
`@linaria/react` in `nx.json`
- Simplified `vite.config.ts` (removed Emotion-specific configuration)
- Updated `twenty-website/next.config.js` to use `next-with-linaria` for
SSR Linaria support
### Storybook & Testing
- Removed `ThemeProvider` from Emotion in Storybook previews
(`twenty-front`, `twenty-sdk`)
- Now relies solely on `ThemeContextProvider` for theme injection
### Documentation
- Removed the temporary `docs/emotion-to-linaria-migration-plan.md`
(migration complete)
- Updated `CLAUDE.md` and `README.md` to reflect Linaria as the styling
stack
- Updated frontend style guide docs across all locales
## How it works
Linaria extracts styles at build time via the `@wyw-in-js/vite` plugin.
All expressions in `styled` template literals must be **statically
evaluable** — no runtime theme objects or closures over component state.
- **Static styles** use `themeCssVariables` which map to CSS custom
properties (`var(--theme-color-x)`)
- **Runtime theme access** (for non-CSS use cases like icon `color`
props) uses `useContext(ThemeContext)` instead of Emotion's `useTheme()`
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import { useContext } from 'react';
|
|
import { styled } from '@linaria/react';
|
|
|
|
import {
|
|
formatExpiration,
|
|
isExpired,
|
|
} from '@/settings/developers/utils/formatExpiration';
|
|
import { TableCell } from '@/ui/layout/table/components/TableCell';
|
|
import { TableRow } from '@/ui/layout/table/components/TableRow';
|
|
import { IconChevronRight } from 'twenty-ui/display';
|
|
import { ThemeContext } from 'twenty-ui/theme';
|
|
import { MOBILE_VIEWPORT } from 'twenty-ui/theme-constants';
|
|
import { type ApiKey } from '~/generated-metadata/graphql';
|
|
|
|
export const StyledApisFieldTableRow = styled(TableRow)`
|
|
@media (max-width: ${MOBILE_VIEWPORT}px) {
|
|
width: 100%;
|
|
}
|
|
`;
|
|
|
|
const StyledTruncatedCell = styled(TableCell)`
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
cursor: pointer;
|
|
`;
|
|
|
|
const StyledEllipsisLabel = styled.div`
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
overflow: hidden;
|
|
`;
|
|
|
|
type ApiKeyType = Pick<ApiKey, 'id' | 'name' | 'expiresAt' | 'revokedAt'> & {
|
|
role?: { id: string; label: string; icon?: string | null } | null;
|
|
};
|
|
|
|
type SettingsApiKeysFieldItemTableRowProps = {
|
|
apiKey: ApiKeyType;
|
|
to: string;
|
|
};
|
|
|
|
export const SettingsApiKeysFieldItemTableRow = ({
|
|
apiKey,
|
|
to,
|
|
}: SettingsApiKeysFieldItemTableRowProps) => {
|
|
const { theme } = useContext(ThemeContext);
|
|
const formattedExpiration = formatExpiration(apiKey.expiresAt || null);
|
|
|
|
const gridColumns = '5fr 2fr 3fr 1fr';
|
|
|
|
return (
|
|
<StyledApisFieldTableRow gridAutoColumns={gridColumns} to={to}>
|
|
<StyledTruncatedCell color={theme.font.color.primary}>
|
|
<StyledEllipsisLabel>{apiKey.name}</StyledEllipsisLabel>
|
|
</StyledTruncatedCell>
|
|
|
|
<StyledTruncatedCell color={theme.font.color.tertiary}>
|
|
<StyledEllipsisLabel>{apiKey.role?.label || '-'}</StyledEllipsisLabel>
|
|
</StyledTruncatedCell>
|
|
|
|
<StyledTruncatedCell
|
|
color={
|
|
isExpired(apiKey.expiresAt || null)
|
|
? theme.font.color.danger
|
|
: theme.font.color.tertiary
|
|
}
|
|
>
|
|
<StyledEllipsisLabel>{formattedExpiration}</StyledEllipsisLabel>
|
|
</StyledTruncatedCell>
|
|
|
|
<TableCell align="right">
|
|
<IconChevronRight
|
|
size={theme.icon.size.md}
|
|
color={theme.font.color.tertiary}
|
|
/>
|
|
</TableCell>
|
|
</StyledApisFieldTableRow>
|
|
);
|
|
};
|