Deprecate runtime theme objects in favor of CSS variables (#18402)
## Summary
- **Eliminate `ICON_SIZES` / `ICON_STROKES` constants**: all icon
dimensions are now resolved at runtime via
`resolveThemeVariableAsNumber(themeCssVariables.icon.size.X)`, ensuring
values always come from computed CSS variables
- **No more consumer imports from `twenty-ui/theme`**: moved
`ColorSchemeContext`, `ColorSchemeProvider`, `ThemeColor`,
`MAIN_COLOR_NAMES`, `getNextThemeColor`, `AnimationDuration` to
`twenty-ui/theme-constants`
- **Remove `ThemeContext` / `ThemeContextProvider` / `ThemeProvider` /
`ThemeType`**: replaced across ~300 files with `themeCssVariables` (for
CSS contexts) or `resolveThemeVariable` / `resolveThemeVariableAsNumber`
(for JS runtime values)
- **Simplify provider chain**: only `ColorSchemeProvider` remains — it
toggles `light`/`dark` class on `document.documentElement` and provides
`colorScheme` via React context
- **Fix pre-existing test failures**: `useIcons.test.ts`
(non-configurable ES module spy) and
`turnRecordFilterGroupIntoGqlOperationFilter.test.ts`
(`Omit<RecordFilter, 'id'>` type mismatch)
### Theme access pattern (before → after)
| Context | Before | After |
|---------|--------|-------|
| CSS (Linaria) | `${({ theme }) => theme.font.color.primary}` |
`${themeCssVariables.font.color.primary}` |
| JS runtime (icon size, animation) | `theme.icon.size.md` /
`ICON_SIZES.md` |
`resolveThemeVariableAsNumber(themeCssVariables.icon.size.md)` |
| Color scheme check | `theme.name === 'dark'` |
`useContext(ColorSchemeContext).colorScheme === 'dark'` |
This commit is contained in:
+1
-2
@@ -7,7 +7,6 @@ import {
|
||||
H2Title,
|
||||
Status,
|
||||
Tag,
|
||||
THEME_LIGHT,
|
||||
ThemeProvider,
|
||||
} from 'twenty-sdk/ui';
|
||||
|
||||
@@ -34,7 +33,7 @@ const TwentyUiComponent = () => {
|
||||
const [count, setCount] = useState(0);
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={THEME_LIGHT}>
|
||||
<ThemeProvider colorScheme="light">
|
||||
<div data-testid="twenty-ui-component" style={CARD_STYLE}>
|
||||
<H2Title
|
||||
title="Twenty UI"
|
||||
|
||||
+5
-5
@@ -12,7 +12,7 @@ import {
|
||||
import { useMemo, useState } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { type ThemeType, ThemeContextProvider } from 'twenty-ui/theme';
|
||||
import { ThemeProvider } from 'twenty-ui/theme-constants';
|
||||
import { FrontComponentWorkerEffect } from '../../remote/components/FrontComponentWorkerEffect';
|
||||
import { componentRegistry } from '../generated/host-component-registry';
|
||||
|
||||
@@ -23,7 +23,7 @@ type FrontComponentContentProps = {
|
||||
executionContext: FrontComponentExecutionContext;
|
||||
frontComponentHostCommunicationApi: FrontComponentHostCommunicationApi;
|
||||
onError: (error?: Error) => void;
|
||||
theme: ThemeType;
|
||||
colorScheme: 'light' | 'dark';
|
||||
};
|
||||
|
||||
export const FrontComponentRenderer = ({
|
||||
@@ -33,7 +33,7 @@ export const FrontComponentRenderer = ({
|
||||
executionContext,
|
||||
frontComponentHostCommunicationApi,
|
||||
onError,
|
||||
theme,
|
||||
colorScheme,
|
||||
}: FrontComponentContentProps) => {
|
||||
const [receiver, setReceiver] = useState<RemoteReceiver | null>(null);
|
||||
const [thread, setThread] = useState<ThreadWebWorker<
|
||||
@@ -109,12 +109,12 @@ export const FrontComponentRenderer = ({
|
||||
)}
|
||||
|
||||
{isDefined(receiver) && isExecutionContextInitialized && (
|
||||
<ThemeContextProvider theme={theme}>
|
||||
<ThemeProvider colorScheme={colorScheme}>
|
||||
<RemoteRootRenderer
|
||||
receiver={receiver}
|
||||
components={componentRegistry}
|
||||
/>
|
||||
</ThemeContextProvider>
|
||||
</ThemeProvider>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user